假设我们有这个 Web 服务器来处理请求:
let webApp = scope {
get "/api/zoo/animals/" (getAllAnimals())
getf "/api/zoo/animals/%s" getAnimalInfo
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我想在 url 查询中有一个参数,例如过滤结果,该怎么办?
http://localhost:8080/api/zoo/animals?type=mammals
Run Code Online (Sandbox Code Playgroud)
这不会做任何事情:
getf "/api/zoo/animals?type=%s" getAnimalsByType
Run Code Online (Sandbox Code Playgroud) TL; DR:此示例不适用于VS2017。
我有一个蓝色的宇宙DB,想什么时候添加或更新有火一些逻辑。为此,CosmosDBTrigger应该很棒。
教程演示了如何在Azure Portal中创建触发器,它对我有用。然而,(现在15.5.4,最新的)做在Visual Studio一样的东西不。
我用的是默认的 Azure的功能模板,预定义的宇宙DB触发和近默认代码:
[FunctionName("TestTrigger")]
public static void Run(
[CosmosDBTrigger("Database", "Collection", ConnectionStringSetting = "myCosmosDB")]
IReadOnlyList<Document> input,
TraceWriter log)
{
log.Info("Documents modified " + input.Count);
log.Info("First document Id " + input[0].Id);
}
Run Code Online (Sandbox Code Playgroud)
应用程序运行没有错误,但是当我实际在数据库中进行操作时,什么也没有发生。因此,我无法调试事物并实际上实现一些必需的逻辑。
连接字符串在指定 local.settings.json和被认为是。如果我故意犯规,则触发运行时错误。
看起来连接字符串似乎连接到错误的数据库。但是,正是一个,copypasted,字符串我在通过Azure的门户网站所做的扳机。
我该怎么办?我还能检查什么?
对于 F# 应用程序,我传统上使用不同的功能友好的命令行解析器,例如Argu和CommandLineParser。
既然 Microsoft 已经推出了System.CommandLine(可能会带来更好的支持和文档),它可以在 F# 中使用吗?
想象一下以下代码:
let d = dict [1, "one"; 2, "two" ]
let CollectionHasValidItems keys =
try
let values = keys |> List.map (fun k -> d.Item k)
true
with
| :? KeyNotFoundException -> false
Run Code Online (Sandbox Code Playgroud)
现在让我们测试一下:
let keys1 = [ 1 ; 2 ]
let keys2 = [ 1 ; 2; 3 ]
let result1 = CollectionHasValidItems keys1 // true
let result2 = CollectionHasValidItems keys2 // false
Run Code Online (Sandbox Code Playgroud)
这可以像我期望的那样工作.但是如果我们在函数中将List更改为Seq,我们会得到不同的行为:
let keys1 = seq { 1 .. 2 }
let keys2 = seq { …Run Code Online (Sandbox Code Playgroud) 我在 Azure DevOps 中有一个管道。在构建和测试之后,我创建了 Azure 资源以便在那里部署应用程序。
我为此使用了Azure 资源组部署任务。它有效,但在日志中我只看到这个(对于我创建的所有资源):
******************************************************************************
Starting: Create Azure Resources
******************************************************************************
==============================================================================
Task : Azure Resource Group Deployment
Description : Deploy an Azure resource manager (ARM) template to a resource group. You can also start, stop, delete, deallocate all Virtual Machines (VM) in a resource group
Version : 2.147.2
Author : Microsoft Corporation
Help : [More Information](https://aka.ms/argtaskreadme)
==============================================================================
Checking if the following resource group exists: awesomeApp42.
Resource group exists: true.
Creating deployment parameters.
The detected …Run Code Online (Sandbox Code Playgroud) azure azure-devops azure-rm-template azure-pipelines azure-template
我正在用 F#开发一个SAFE应用程序,其中一部分是将一些日志发送到 Azure 中的 Application Insights。服务器端日志记录有点简单:
open Microsoft.ApplicationInsights
open Microsoft.ApplicationInsights.Extensibility
let getTelemetryClient() =
let key = <key>
TelemetryConfiguration.Active.InstrumentationKey <- key
TelemetryClient()
let log (message : string) =
let logger = (lazy getTelemetryClient()).Value
logger.TrackTrace message
logger.Flush()
Run Code Online (Sandbox Code Playgroud)
现在我想在客户端做一些类似的事情,在寓言中。我有一个 AI 密钥,我需要将数据发送到 Azure。相同的代码不会转换为 JS。
当我运行 Saturn 应用程序时,我看到一些日志被写入控制台。
看起来他们以LogLevel.Info. 我如何进行更详细的日志记录,即如何正确设置例如LogLevel.Trace?
我想在 Azure Batch 中执行一个简单的任务,等待它完成并获取结果:
using (var client = _CreateBatchClient())
{
var monitor = client.Utilities.CreateTaskStateMonitor();
var task = new CloudTask(Guid.NewGuid().ToString(), "echo hello world");
await client.JobOperations.AddTaskAsync("Test", task);
await monitor.WhenAll(new List<CloudTask> { task }, TaskState.Completed, _timeout);
var result = task.ExecutionInformation.Result;
}
Run Code Online (Sandbox Code Playgroud)
还有WhenAsync线抛出System.InvalidOperationException: 'This operation is forbidden on unbound objects.'
该消息相当晦涩,而我距离教程并不远。怎么了?
我已经拥有所有 webpack 加载器,所以我需要做的就是这样,但在 F# 中:
import loading from "../images/loading.gif";
Run Code Online (Sandbox Code Playgroud)
这应该是一件容易的事情,我只是迷失在文档中,我主要找到有关[<Import>]属性的信息,这些信息似乎用于其他东西......
我正在将其添加Stryker.net到我的 C# 项目中。我发现它在所有日志条目上都发生了变化。有什么办法可以在配置中忽略这些吗?
类似于这个问题 -在 F# 中编写 LINQ 的SingleOrDefault的最惯用的方法是什么?
我正在尝试检查密码是否至少包含一个字母和数字.以下似乎没有用.
密码可以是"tester1"或"11111111t"等.
不能是所有字母或所有数字.
有任何想法吗?
const string pattern = @"/[a-z].*\d|\d.*[a-z]/";
var match = Regex.Match(password, pattern);
Run Code Online (Sandbox Code Playgroud)
解决了:
var rule1 = password.Any(char.IsLetter);
var rule2 = password.Any(char.IsNumber);
Run Code Online (Sandbox Code Playgroud)
这也有效:
const string pattern = @"[a-z].*\d|\d.*[a-z]";
Run Code Online (Sandbox Code Playgroud) 我希望在寓言中有一个简单的显示/隐藏内容行为.像这样的东西.
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}Run Code Online (Sandbox Code Playgroud)
<button onclick="myFunction()">Click Me</button>
<div id="myDIV">
This is my DIV element.
</div>Run Code Online (Sandbox Code Playgroud)
最合适的方法是什么?
f# ×8
c# ×3
fable-f# ×3
azure ×2
logging ×2
.net ×1
asp.net-core ×1
azure-batch ×1
azure-devops ×1
c#-to-f# ×1
collections ×1
exception ×1
f#-giraffe ×1
html ×1
linq ×1
mapping ×1
regex ×1
safe-stack ×1
sequences ×1
stryker ×1
stryker-net ×1
togglebutton ×1