我可能在这里错过了这条船,但是如果你给XMLProvider的XML没有所有可能的元素,你如何构建一个使用XML Type Provider的可重用工具呢?换句话说,有没有办法使用XSD?我知道我可以尝试从XSD生成示例XML,但我想知道我是否正在接近这个错误.
有点像F#初学者.我试图在交互式窗口中测试我的一些XmlTypeProvider代码,首先在脚本(fsx)文件中输入它.脚本文件将无法识别以下内容
open FSharp.Data // gives "The namespace or module 'FSharp' is not defined"
Run Code Online (Sandbox Code Playgroud)
所有内容都已添加到引用中,.fs文件似乎没有找到XmlTypeProvider引用的任何问题但由于某种原因,同一项目中的脚本没有.我甚至让代码在.fs文件中工作.
我用nuget添加了FSharp.Data,一切似乎都正确添加.我在这里错过了什么?
我们正处于f#项目的开端,该项目涉及流数据的实时和历史分析.数据包含在ac#对象中(见下文),并作为标准.net事件的一部分发送.实时地,我们通常接收的事件的数量可以从每个仪器每秒大约800个事件的不到1 /秒到更高的变化很大,因此可以是非常突发的.典型的一天可能会累积500万行/每个元素
C#事件的数据结构的通用版本如下所示:
public enum MyType { type0 = 0, type1 = 1}
public class dataObj
{
public int myInt= 0;
public double myDouble;
public string myString;
public DateTime myDataTime;
public MyType type;
public object myObj = null;
}
Run Code Online (Sandbox Code Playgroud)
我们计划以两种方式在f#中使用这个数据结构:
随着我们添加更多事件,数据结构需要能够增长.这排除了array<t>因为它不允许调整大小,尽管它可以用于历史分析.数据结构还需要能够快速访问最近的数据,理想情况下需要能够跳回到数据x点.这排除了Lists<T>因为线性查找时间,并且因为没有随机访问元素,只是"仅向前"遍历.
根据这篇文章,Set<T>可能是个不错的选择......
编辑:尹祝的回应让我更清楚地知道我在问什么.我已经编辑了帖子的其余部分以反映这一点.此外,通过引入历史分析的要求,这个问题的先前版本变得混乱.我省略了它们.
以下是实时流程步骤的细分:
Set<T>还是其他结构?所以问题是什么是用于存储我们将用于生成功能的实时流事件的最佳数据结构.
鉴于代码:
#if INTERACTIVE
#r "bin\Debug\FSharp.Data.dll"
#endif
open System
open FSharp.Data
open FSharp.Data.Json
let testJson = """{ "workingDir":"hello", "exportDir":"hi there", "items":[{ "source":"", "dest":"", "args": {"name":"that"} }] }"""
//here is where i get the error
let Schema = JsonProvider<testJson>
Run Code Online (Sandbox Code Playgroud)
最后一行不断给出错误"这不是一个常量表达式或有效的自定义属性值" - 这是什么意思?我怎样才能读到这个JSON?
我认为这个标题是错误的,但不能创建一个标题,从抽象的角度来反映我想要实现的目标.
我正在编写一个调用服务并将数据作为JSON字符串检索的函数.该函数使用JSON类型提供程序解析字符串.在某些条件下,我想修改该JSON对象的属性,然后返回修改对象的字符串.因此,如果来自呼叫的响应是
{"property1" : "value1","property2" : "value2", "property3": "value3" }
Run Code Online (Sandbox Code Playgroud)
我想将property3更改为新值,然后返回JSON字符串.
如果JsonProvider是可变的,这将是一个练习,如:
type JsonResponse =
JsonProvider<""" {"property1" : "value1",
"property2" : "value2",
"property3": "value3" } """>
let jsonResponse = JsonResponse.Parse(response)
jsonResponse.Property3 <- "new value"
jsonResponse.ToString()
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为无法设置属性.我想确定解决这个问题的最佳方法.我很乐意根据原始响应初始化一个新对象,但修改了参数,但我不确定是否有一种简单的方法可以实现这一点.
作为参考,JSON对象比给定的平面示例更复杂,并且包含深层次结构.
我一直在使用FSharp.Data中的XmlProvider来生成与XML片段相对应的类型,我将其存储在正在构建的F#项目的源目录中的文件中.
我用文件的路径参数化XmlProvider.然后将此代码编译为DLL.
如果我然后从另一个无法从源目录读取的F#项目引用此程序集的已编译DLL,那么在该项目的编译时我得到错误FS3033'无法从'config_schema.xml'读取示例XML:不能找到(路径)'.
为什么是这样?我的理解是,在编译之后,与XML样本对应的类型是标准的完全成熟类型,这应该是编译后的DLL中的结果.为什么类型的消费者(第二个项目中的代码)仍然需要引用样本进行编译?
我正在尝试在FSharp项目的脚本文件中使用FSharp.Data,而我收到的错误是:
警告'..\packages\FSharp.Data.2.2.5\lib \net40\FSharp.Data.dll'不是有效的程序集名称.
FSharp.Data来自https://www.nuget.org/packages/FSharp.Data/
如果我尝试使用.NET 4.0,.NET 4.5或.NET 4.6的F#项目,那就是同样的问题.
编辑:它适用于'..\packages\FSharp.Data.2.2.5\lib\portable-net40 + sl5 + wp8 + win8\FSharp.Data.dll'但在此便携版本中仅支持Web位置.
Visual Studio module MyFile不时在第一行显示错误.但是,我没有使用WorldBankProvider,重建项目后错误总是消失.为什么?
类型提供者'ProviderImplementation.WorldBankProvider报告错误:类型提供商构造方法已抛出异常:类型"FSharp.Data.Runtime.WorldBank.Indicators"由一个类型提供用在参考组件组未找到"[| ctxt程序集FSharp.Data,Version = 2.3.0.0,Culture = neutral;
完整的错误消息:
Severity Code Description Project File Line Suppression State
Error The type provider 'ProviderImplementation.WorldBankProvider' reported an error: The type provider constructor has thrown an exception: The type 'FSharp.Data.Runtime.WorldBank.Indicators' utilized by a type provider was not found in reference assembly set '[|ctxt assembly FSharp.Data, Version=2.3.0.0, Culture=neutral;
ctxt assembly HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a;
ctxt assembly NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c;
ctxt assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;
ctxt assembly FSharp.Core, Version=4.3.1.0, …Run Code Online (Sandbox Code Playgroud) 我正在使用FSharp.Data.SqlClient并尝试将我的connectionString从a移动[<Literal>]到app.config.
我的app.config看起来像这样
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Test;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我的SqlCommandProvider外观如下所示,根据http://fsprojects.github.io/FSharp.Data.SqlClient/configuration%20and%20input.html,这应该是正确的
new SqlCommandProvider<"SELECT ...",
ConnectionStringOrName = "name=DefaultConnection",
SingleRow = true,
AllParametersOptional = true>(??????)
Run Code Online (Sandbox Code Playgroud)
现在的问题是.最后一部分是什么,??????部分.
我试过"name=DefaultConnection"但它给了我一个运行时错误,名称不受支持.
我似乎找不到任何文件来解释那里发生了什么.
Instaed of fixnig我发现了这个问题的解决方法. https://fsprojects.github.io/FSharp.Configuration/
ConnectionStringOrName如果必须提供连接字符串,我无法达到目的.另外你为什么要指定它两次.对我来说没什么意义:(
我有一个NUnit单元测试,它是用普通的F#库编写的,但它是针对可移植类库中的F#代码.
当我运行此测试(在Visual Studio 2013中)时,我得到以下异常:
Result Message: System.MissingMethodException : Method not found:
'Microsoft.FSharp.Control.FSharpAsync`1<System.IO.TextReader> FSharp.Data.Runtime.IO.asyncReadTextAtRuntime(System.Boolean, System.String, System.String, System.String, System.String)'.
Run Code Online (Sandbox Code Playgroud)
这就是我在Portable Class Library中的app.config中所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这就是我在普通F#库的app.config中所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.3.13283" newVersion="2.6.3.13283" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)