小编shu*_*qui的帖子

Graphql Hotchocolate 中的多种查询类型

我正在使用热巧克力 graphql。我有一个场景,我有两个单独的查询类型类。

  1. PostQuery -> 包含与帖子相关的查询
  2. UserQuery -> 包含用户相关查询

我的文件夹结构

在此输入图像描述

这是我的配置方式

 .AddAuthorization()
    //for inmemory subscription
    .AddInMemorySubscriptions()
    .AddQueryType<PostQuery>()
    .AddQueryType<UserQuery>()
    .AddMutationType<Mutation>()
    .AddSubscriptionType<Subscription>()
    .AddGlobalObjectIdentification()
    // Registers the filter convention of MongoDB
    .AddMongoDbFiltering()
    // Registers the sorting convention of MongoDB
    .AddMongoDbSorting()
    // Registers the projection convention of MongoDB
    .AddMongoDbProjections()
    // Registers the paging providers of MongoDB
    .AddMongoDbPagingProviders();
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误

System.ArgumentException: The root type `Query` has already been registered
Run Code Online (Sandbox Code Playgroud)

无论如何,它可以配置吗?否则我必须将所有内容放在一个类中?

c# graphql hotchocolate .net-6.0

8
推荐指数
2
解决办法
4738
查看次数

读取文件的最后30,000行

如果有一个csv文件,其数据会不时增加.现在我需要做的是阅读最后30,000行.

代码:

string[] lines = File.ReadAllLines(Filename).Where(r => r.ToString() != "").ToArray();

 int count = lines.Count();

 int loopCount = count > 30000 ? count - 30000 : 0;

  for (int i = loopCount; i < lines.Count(); i++)
  {
      string[] columns = lines[i].Split(',');
      orderList.Add(columns[2]);
  }
Run Code Online (Sandbox Code Playgroud)

它工作正常,但问题是

File.ReadAllLines(Filename)
Run Code Online (Sandbox Code Playgroud)

阅读导致性能不足的完整文件.我想要它只读取最后30,000行迭代整个文件.

PS:我正在使用.Net 3.5..Net 3.5中不存在Files.ReadLines()

c# csv file-io

5
推荐指数
1
解决办法
1337
查看次数

将多个监听器绑定到同一个端口

我正在使用UdpClient类,.net 3.5 我需要将多个应用程序绑定到同一个端口。

因此,如果UDP服务器广播任何请求 - 在端口上侦听的所有应用程序都可以接收消息,但问题是,当我尝试将应用程序绑定到同一端口时,只有一个应用程序收到消息,而另一个应用程序没有。

下面是这两个应用程序的一些示例代码:

    UdpClient udpClient = new UdpClient();
    Thread thread;
    IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, 11000);
    public Form1()
    {
        //CheckForIllegalCrossThreadCalls = false;

        InitializeComponent();
        udpClient.ExclusiveAddressUse = false;
        udpClient.Client.SetSocketOption(
        SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        udpClient.Client.Bind(endPoint);
    }

    private void MainForm_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Escape)
        {
            thread.Abort();
            udpClient.Close();
            Close();
        }
    }

    private void ReceiveMessage()
    {
        //while (true)
        //{
        // IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, 11000);
        //  byte[] content = udpClient.Receive(ref endPoint);
        udpClient.BeginReceive(new AsyncCallback(Read_Callback), …
Run Code Online (Sandbox Code Playgroud)

c# udpclient

5
推荐指数
1
解决办法
8337
查看次数

C#背后的代码中的必填字段验证器

我正在尝试在文件后面的代码中使用必填字段验证器,但它显示以下错误。

错误:

Unable to find control id 'TextBox1' referenced by the 'ControlToValidate' property of 'abcd854'
Run Code Online (Sandbox Code Playgroud)

注意:TextBox1存在于页面中。我已经测试过了。

在此处输入图片说明

Aspx页面

  <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication3._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <p>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="save" />       
    </p>
    <p>
        &nbsp;<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</asp:Content>
Run Code Online (Sandbox Code Playgroud)

CS文件

   public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //RequiredFieldValidator validator = ControlsValidation.AssignRequiredFieldValidatorToControl(TextBox1, "Field is required", "*", "save");
            //validator.ControlToValidate = ((TextBox)this.Form.FindControl("MainContent").FindControl("TextBox1")).ID; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net requiredfieldvalidator

3
推荐指数
1
解决办法
2万
查看次数

进程间通信和BroadCasting

我正在进行一个进程间通信.我遇到了命名管道通信.

我已经有了一些基本的想法,但需要确保以下几点?

  1. 名称管道是否可以同时拥有多个客户端?

  2. 它是否支持通过不同语言构建的不同流程进行通信.

请告诉我,命名管道通信和进程间通信广播有什么区别?

c# named-pipes broadcasting interprocess

2
推荐指数
1
解决办法
995
查看次数

Elastic Search 7.5 中的父子关系

我是“弹性搜索”的新手,目前正在尝试了解 ES 如何维持“父子”关系。我从以下文章开始:

https://www.elastic.co/blog/managing-relations-inside-elasticsearch

但是这篇文章基于旧版本的 ES,我目前使用的是 ES 7.5,其中指出:

_parent 字段已被移除,取而代之的是 join 字段。

现在我正在关注这篇文章:

https://www.elastic.co/guide/en/elasticsearch/reference/7.5/parent-join.html

但是,我无法获得所需的结果。

我有一个场景,其中我有两个索引“人”和“家”。每个“人”可以有多个“家”,这基本上是一对多的关系。问题是当我查询获取所有父母为“XYZ”人的房屋时,答案为空。

以下是我的索引结构和搜索查询:

人物指数:

请求网址:http://hostname/person

{
    "mappings": {
        "properties": {
            "name": {
                "type": "text"
            },
            "person_home": {
                "type": "join",
                "relations": {
                    "person": "home"
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

主页索引:

请求地址:http://hostname/home

{
    "mappings": {
        "properties": {
            "state": {
                "type": "text"
            },
            "person_home": {
                "type": "join",
                "relations": {
                    "person": "home"
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

亲自添加数据索引

请求网址:http://hostname/person/_doc/1

{
    "name": "shujaat",
    "person_home": …
Run Code Online (Sandbox Code Playgroud)

parent-child elasticsearch elasticsearch-7

2
推荐指数
1
解决办法
4093
查看次数