コード例 #1
0
    public TcpIpHostDataJsonSafe(EnsureSpecial getThisHostInfo, bool once)
    {
        TcpIpSystemHostInfo info = LocalNet.GetHostInfo(once);

        this.HostName        = info.HostName;
        this.DomainName      = info.DomainName;
        this.FqdnHostName    = info.FqdnHostName;
        this.IsIPv4Supported = info.IsIPv4Supported;
        this.IsIPv6Supported = info.IsIPv6Supported;
        this.IPAddressList   = info.IPAddressList.Select(x => x.ToString()).ToArray();
    }
コード例 #2
0
    static int Net(ConsoleService c, string cmdName, string str)
    {
        ConsoleParam[]        args = { };
        ConsoleParamValueList vl   = c.ParseCommandList(cmdName, str, args);

        TcpIpSystemHostInfo hostInfo = LocalNet.GetHostInfo(true);

        Net_Test1_PlainTcp_Client();
        return(0);

        //Net_Test2_Ssl_Client();
        //return 0;

        //Net_Test3_PlainTcp_Server();
        //return 0;

        //Net_Test3_2_PlainTcp_Server_AcceptQueue();
        //return 0;


        //while (true)
        //{
        //    try
        //    {
        //        Net_Test4_SpeedTest_Client();
        //    }
        //    catch (Exception ex)
        //    {
        //        ex.ToString()._Print();
        //    }
        //}

        //Net_Test5_SpeedTest_Server();

        //Net_Test6_DualStack_Client();

        //Net_Test7_Http_Download_Async()._GetResult();

        //Net_Test8_Http_Upload_Async()._GetResult();

        //Net_Test9_WebServer();

        //Net_Test10_SslServer();

        //Net_Test11_AcceptLoop();

        //Net_Test12_AcceptLoop2();

        //Net_Test13_WebSocketClientAsync()._GetResult();

        //Net_Test14_WebSocketClient2Async()._GetResult();

        return(0);
    }
コード例 #3
0
    async Task PostHttpMainAsync(CancellationToken cancel = default)
    {
        if (this.Config.PostUrl._IsEmpty())
        {
            return;
        }

        StatManDatabase copy;

        lock (this.DataLock)
        {
            copy = this.Database._CloneWithJson();
        }

        KeyValueList <string, string> vers = new KeyValueList <string, string>();

        vers.Add("APPNAME", CoresLib.AppNameFnSafe);
        vers.Add("OS", Env.OsInfoString);
        vers.Add("CPU", Env.CpuInfo.ToString());
        vers.Add("NUMCPU", Env.NumCpus.ToString());
        vers.Add("DOTNET", Env.FrameworkInfoString);
        vers.Add("EXE", Env.AppExecutableExeOrDllFileName._GetFileName() ?? "");

        List <string> versStrs = new List <string>();

        vers.ForEach(x => versStrs.Add($"{x.Key}={x.Value}"));

        var data = Json.NewJsonObject();

        foreach (var item in copy.StrValues)
        {
            data.TryAdd(item.Key, new JValue(item.Value));
        }

        foreach (var item in copy.LongValues)
        {
            data.TryAdd(item.Key, new JValue(item.Value));
        }

        DataVaultData postData = new DataVaultData
        {
            TimeStamp       = DtOffsetNow,
            StatUid         = copy.Uid,
            StatAppVer      = versStrs._Combine("|"),
            StatGitCommitId = Dbg.GetCurrentGitCommitId(),
            StatLocalIp     = this.CurrentLocalIp.ToString(),
            StatLocalFqdn   = LocalNet.GetHostInfo(true).HostName,
            SystemName      = Config.SystemName,
            LogName         = Config.LogName,
            Data            = data,
        };

        string postStr = postData._ObjectToJson();

        using var http = new WebApi(new WebApiOptions(new WebApiSettings { SslAcceptAnyCerts = true }));

        var ret = await http.SimplePostJsonAsync(WebMethods.POST, Config.PostUrl, postStr, cancel);

        if (ret.ToString()._InStr("ok") == false)
        {
            throw new CoresException($"Http error: {ret.ToString()._TruncStrEx(1000)}");
        }
    }