Exemplo n.º 1
0
        internal void Reload(string Instance = "Default")
        {
            string sID = "";

            try
            {
                AzureLog.PostAsync(new { Computer = Environment.MachineName, EventID = 1001, Description = $"Reloading {Instance}" });

                _hubContext.Clients.All.SendAsync("init", "init");
                _hubContext.Clients.Group("web").SendAsync("newData", "Hub", ""); //Enforce PageUpdate

                Type xType = Type.GetType("DevCDRServer." + Instance);

                MethodInfo methodInfo = xType.GetMethod(
                    "Clear",
                    BindingFlags.Public | BindingFlags.Static
                    );
                sID = methodInfo.Invoke(new object(), new object[] { Instance }) as string;
            }
            catch { }
        }
Exemplo n.º 2
0
        public async void Status(string name, string Status)
        {
            name = name.ToLower();

            if (string.IsNullOrEmpty(AzureLog.WorkspaceId))
            {
                if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Log-WorkspaceID")) && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Log-SharedKey")))
                {
                    AzureLog = new DevCDR.Extensions.AzureLogAnalytics(Environment.GetEnvironmentVariable("Log-WorkspaceID"), Environment.GetEnvironmentVariable("Log-SharedKey"), "DevCDR_" + (Environment.GetEnvironmentVariable("INSTANCENAME") ?? "Default"));
                }
            }

            var J1 = JObject.Parse(Status);

            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("fnDevCDR")))
            {
                J1["Groups"] = "unknown";
            }

            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("IP2LocationURL")))
            {
                string ClientIP = Context.GetHttpContext().Connection.RemoteIpAddress.ToString();
                J1["Internal IP"] = ClientIP;
                try
                {
                    J1["Internal IP"] = GetLocAsync(ClientIP).Result;
                }
                catch { }
            }

            if (J1["Customer"] == null)
            {
                J1.Add("Customer", "");
            }

            bool bChange = false;

            try
            {
                if (string.IsNullOrEmpty(J1.GetValue("Hostname").Value <string>()))
                {
                    return;
                }

                if (jData.SelectTokens("[?(@.Hostname == '" + J1.GetValue("Hostname") + "')]").Count() == 0) //Prevent Duplicates
                {
                    J1.Add("ConnectionId", Context.ConnectionId);

                    lock (jData)
                    {
                        jData.Add(J1);
                    }
                    bChange = true;
                    _connections.Add(name, Context.ConnectionId);

                    await Clients.Group("web").SendAsync("newData", "add", ""); //Enforce PageUpdate

                    if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("fnDevCDR")))
                    {
                        try
                        {
                            await setStatusAsync(Environment.GetEnvironmentVariable("INSTANCENAME") ?? "Default", J1.GetValue("id").ToString(), J1.ToString());
                        }
                        catch { }
                    }

                    AzureLog.PostAsync(new { Computer = J1.GetValue("Hostname"), EventID = 3000, Description = J1.GetValue("ScriptResult").ToString() });
                }
                else
                {
                    lock (jData)
                    {
                        //Changes ?
                        if (jData.SelectTokens("[?(@.Hostname == '" + J1.GetValue("Hostname") + "')]").First().ToString(Formatting.None) != J1.ToString(Formatting.None))
                        {
                            jData.SelectTokens("[?(@.Hostname == '" + J1.GetValue("Hostname") + "')]").First().Replace(J1);
                            bChange = true;
                            AzureLog.PostAsync(new { Computer = J1.GetValue("Hostname"), EventID = 3000, Description = J1.GetValue("ScriptResult").ToString() });

                            //if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("fnDevCDR")))
                            //{
                            //    J1.Add("ConnectionId", Context.ConnectionId);
                            //    setStatusAsync(Environment.GetEnvironmentVariable("INSTANCENAME") ?? "Default", J1.GetValue("id").ToString(), J1.ToString());
                            //}
                        }
                        else
                        {
                            //if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("fnDevCDR")))
                            //{
                            //    string sJSON = "{\"ConnectionID\":\"" + Context.ConnectionId + "\"}";
                            //    setStatusAsync(Environment.GetEnvironmentVariable("INSTANCENAME") ?? "Default", J1.GetValue("Hostname").ToString(), sJSON);
                            //}
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bChange = true;
                ex.Message.ToString();
            }

            if (bChange)
            {
                try
                {
                    await Clients.Group("web").SendAsync("newData", name, ""); //Enforce PageUpdate
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }
        }