Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public AppSelector()
        {
            List <ConfigServerWebsite> result = new List <ConfigServerWebsite>();
            string requestDomainName          = UtilServer.RequestDomainName();

            this.ConfigServer = ConfigServer.Load();
            foreach (var website in ConfigServer.WebsiteList)
            {
                foreach (var item in website.DomainNameList)
                {
                    if (item.DomainName == requestDomainName)
                    {
                        result.Add(website);
                    }
                }
            }

            // Make sure Website has been found
            if (result.Count == 0)
            {
                throw new Exception(string.Format("Website not found! See also: ConfigServer.json (Domain={0}; Environment={1};)", requestDomainName, this.ConfigServer.EnvironmentName));
            }
            if (result.Count > 1)
            {
                throw new Exception(string.Format("More than one website found! See also: ConfigServer.json ({0})", requestDomainName));
            }

            this.Website     = result.Single();
            this.AppTypeName = Website.DomainNameList.Where(item => item.DomainName == requestDomainName).Single().AppTypeName;
        }
Esempio n. 2
0
 public void LoadUtilServerProcesses()
 {
     foreach (var util in Env.UtilServers)
     {
         UtilServer    UtilCache = new UtilServer(util["name"]);
         List <String> ParentIds = new List <String>();
         ParentIds = this.IRData.GetParentIdsByServer(util["keyname"]);
         log.Debug($"Initializnig Cache Load: {util["name"]}");
         if (ParentIds.Count > 0)
         {
             foreach (var id in ParentIds)
             {
                 ImportProcess process = this.DeconstructImportProcess(id);
                 // if(Env.DEBUG) { log.Info($"ParentId: {id}"); }
                 if (process is ImportProcess)
                 {
                     UtilCache.Processes.Add(process);
                 }
                 else
                 {
                     log.Error($"Could not build Import Process DAO for Parent ID: {id}");
                 }
             }
         }
         else
         {
             log.Error($"No Parent IDs returned by query on{util["name"]}");
         }
         if (UtilCache.Processes.Count > 0)
         {
             this.Servers.Add(UtilCache);
         }
     }
 }
Esempio n. 3
0
        public void Initialize()
        {
            List <bool> RemoveServer    = new List <bool>();
            String      LocalServerName = Env.DEBUG ? "ap-imgutil2-dev" : System.Environment.MachineName;

            try
            {
                this.EnvServers = JsonConvert.DeserializeObject <List <UtilServer> >(File.ReadAllText(Env.CACHE_DIR + $"\\{Env.AppServer["name"]}.json"));
                log.Info("Deserialized Server configuration.");
            }
            catch (IOException e)
            {
                log.Error($"Cannot find JSON config file in: {Env.CACHE_DIR}");
                log.Error(e.Message);
            }
            foreach (UtilServer server in this.EnvServers)
            {
                if (server.ServerName != LocalServerName)
                {
                    RemoveServer.Add(true);
                }
                else
                {
                    RemoveServer.Add(false);
                }
            }
            for (int i = 0; i < RemoveServer.Count; i++)
            {
                if (RemoveServer[i])
                {
                    log.Info("Deleting remote server config: " + this.EnvServers[i].ServerName);
                    this.EnvServers.RemoveAt(i);
                }
            }
            if (this.EnvServers.Count == 1)
            {
                this.MyServer = this.EnvServers[0];
                log.Info("Match: " + this.MyServer.ServerName + "Instantiating Local Server Object.");
            }
            else
            {
                log.Error("Zero, or multiple servers found. \n" +
                          "Unable to instantiate local server object.");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Log stopwatch to console.
        /// </summary>
        internal static void TimeLog()
        {
            int pathCount  = RequestIdToStopwatchCollectionList.Where(item => item.Value.NavigatePath == UtilServer.Context.Request.Path.Value).Count();
            var collection = CollectionCurrent;

            StringBuilder result = new StringBuilder();

            result.AppendLine(string.Format("CollectionId={0}/{1}; Path={2}; RequestCount={3}; PathCount={4};", collection.Id, RequestIdToStopwatchCollectionList.Count, collection.NavigatePath, collection.RequestCount, pathCount));
            foreach (var item in collection.List.OrderBy(item => item.Key)) // Order by stopwatch name.
            {
                // Calculate average time per max 10 requests.
                double second = ((double)item.Value.Stopwatch.ElapsedTicks / (double)Stopwatch.Frequency) / collection.RequestCount;
                result.AppendLine(string.Format("Time={0:000.0}ms; Name={1}; StartCount={2};", second * 1000, item.Key, item.Value.StartCount));
            }

            result.AppendLine(collection.LogText.ToString());

            UtilServer.Logger(typeof(UtilStopwatch).Name).LogInformation(result.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
        }
Esempio n. 5
0
        /// <summary>
        /// Create AppJson with session data.
        /// </summary>
        internal async Task <AppJson> CreateAppJsonSession(HttpContext context)
        {
            // Deserialize RequestJson
            RequestJson requestJson;
            string      requestJsonText = await UtilServer.StreamToString(context.Request.Body);

            if (requestJsonText != null)
            {
                requestJson        = JsonSerializer.Deserialize <RequestJson>(requestJsonText);
                requestJson.Origin = RequestOrigin.Browser;
                foreach (var command in requestJson.CommandList)
                {
                    command.Origin       = RequestOrigin.Browser;
                    command.GridCellText = UtilFramework.StringNull(command.GridCellText); // Sanitize incomming request.
                }
            }
            else
            {
                requestJson = new RequestJson(null)
                {
                    RequestCount = 1
                };
            }

            // Deserialize AppJson (Session) or init
            var appJson = UtilSession.Deserialize();

            // IsExpired
            bool isSessionExpired   = appJson == null && requestJson.RequestCount > 1;
            bool isBrowserRefresh   = appJson != null && requestJson.RequestCount != appJson.RequestCount + 1; // Or BrowserTabSwitch.
            bool isBrowserTabSwitch = appJson != null && requestJson.ResponseCount != appJson.ResponseCount;

            // New session
            if (appJson == null || isBrowserRefresh || isBrowserTabSwitch)
            {
                // New AppJson (Session)
                bool isInit = false;
                if (appJson == null || UtilServer.Context.Request.Method == "GET")
                {
                    appJson = CreateAppJson();
                    isInit  = true;
                }
                appJson.RequestUrl       = UtilServer.RequestUrl();
                appJson.IsSessionExpired = isSessionExpired;

                // New RequestJson
                string browserPath = requestJson.BrowserPath;
                requestJson = new RequestJson(null)
                {
                    RequestCount = requestJson.RequestCount, BrowserUrl = requestJson.BrowserUrl
                };                                                                                                                    // Reset RequestJson.
                appJson.RequestJson = requestJson;

                // Add navigate command to queue
                if (UtilServer.Context.Request.Method == "POST" || browserPath == "/")
                {
                    appJson.Navigate(browserPath, false); // User clicked backward, forward navigation history.
                }

                // New session init
                if (isInit)
                {
                    await appJson.InitInternalAsync();
                }
            }
            else
            {
                appJson.IsSessionExpired = false;
            }

            // Set RequestJson
            appJson.RequestJson = requestJson;

            return(appJson);
        }