Esempio n. 1
0
        public static void OnSynchTimerTick(object state)
        {
            LogableTask task = LogableTask.NewTask("Update terminal Details");

            try
            {
                UpdateTerminalDetails(task);
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, ex);
            }
            finally { task.EndTask(); }

            task = LogableTask.NewTask("Synch data");
            try
            {
                UpdateSadadaData(task);
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, ex);
            }
            finally { task.EndTask(); }
        }
        public void SetStartUpData(StartUpData req)
        {
            LogableTask task = LogableTask.NewTask("SetStartupData");

            try
            {
                task.Log(MethodBase.GetCurrentMethod(), TraceLevel.Info, "Session started, TSN = " + req.TSN);

                if (req.ReuseSession == false)
                {
                    UserSession.CurrentSession = new UserSession();

                    UserSession.CurrentSession.Language = req.Lang == "eng" ? Language.Eng : Language.Ara;
                    task.Log(MethodBase.GetCurrentMethod(), TraceLevel.Info, "language set as " + UserSession.CurrentSession.Language);
                    SessionController.MachineID    = UserSession.CurrentSession.MachineID = req.MachineID;
                    UserSession.CurrentSession.PAN = req.PAN;
                    var token = GetRequesterAuthorizer(req.PAN);
                    UserSession.CurrentSession.Requester   = token.Data.requester;
                    UserSession.CurrentSession.Authorizer  = token.Data.authorizer;
                    UserSession.CurrentSession.SessionData = new List <KeyValuePair <string, string> >();
                }
                else
                {
                    task.Log(MethodBase.GetCurrentMethod(), TraceLevel.Info, "Reusing session");
                }

                UserSession.CurrentSession.TSN = req.TSN;
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), TraceLevel.Error, ex);
            }
            finally { task.EndTask(); }
        }
Esempio n. 3
0
        /// <summary>
        /// throws (WebException e) when (e.Status == WebExceptionStatus.Timeout)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="subUrl"></param>
        /// <param name="request"></param>
        /// <param name="task"></param>
        /// <returns></returns>
        public static Response <T> GetResponse <T>(string subUrl, BaseTerminalRequest request, bool waitForCustomerDetails = true)
        {
            LogableTask task = LogableTask.NewTask("Posting to " + subUrl);

            try
            {
                if (waitForCustomerDetails)
                {
                    if (UserSession.CurrentSession.CustomerDetailsStatus.WaitOne(1000 * 150) == false)
                    {
                        task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, "wait of 150 sec expired for customer details ");
                    }

                    if (UserSession.CurrentSession.CustomerDetailsResponse == null)
                    {
                        task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, "CustomerDetailsResponse is null");
                        return(new Response <T>
                        {
                            Success = false,
                            ErrorCode = "Exception",
                            ErrorDesc = "UserSession.CurrentSession.CustomerDetailsResponse is null"
                        });
                    }

                    if (UserSession.CurrentSession.CustomerDetailsResponse.Success == false)
                    {
                        task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error,
                                 "customer details was failed. " + UserSession.CurrentSession.CustomerDetailsResponse.ErrorDesc);
                        return(new Response <T>
                        {
                            Success = false,
                            ErrorCode = UserSession.CurrentSession.CustomerDetailsResponse.ErrorCode,
                            ErrorDesc = UserSession.CurrentSession.CustomerDetailsResponse.ErrorDesc
                        });
                    }
                }
                request.CommonParams = ServerHelper.GetCommonParameters();
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "sending req to " + subUrl);

                return(GetResponse <T>(subUrl, request, task));
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, ex);
                throw ex;
            }
            finally { task.EndTask(); }
        }
        public void SetCommonParams(SetCommonParamsReq req)
        {
            LogableTask task = LogableTask.NewTask("SetCommonParams");

            try
            {
                task.Log(MethodBase.GetCurrentMethod(), TraceLevel.Info, "called");
                if (req.SetCustNum)
                {
                    UserSession.CurrentSession.CustNum = req.CustNum;
                }

                if (req.SetPAN)
                {
                    UserSession.CurrentSession.PAN = req.PAN;
                }
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), TraceLevel.Error, ex);
            }
            finally { task.EndTask(); }
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            DebugLog("Starting");
            if (Debugger.IsAttached == false)
            {
                var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
                var pathToContentRoot = Path.GetDirectoryName(pathToExe);
                Directory.SetCurrentDirectory(pathToContentRoot);
                DebugLog("Set Current Dir as " + pathToContentRoot);
            }

            Program.textLogWriter = new TextLogWriter();
            DebugLog("Creating logs at " + Environment.CurrentDirectory + "\\Logs");

            Program.textLogWriter.InitializeLogWriter(System.Environment.CurrentDirectory + "\\Logs", "ConceptsClient", false, true, true, true);
            LogableTask task = LogableTask.NewTask("Main");

            try
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "Starting app");
                appSettings = JsonConvert.DeserializeObject <appSettingsDTO>(System.IO.File.ReadAllText(System.Environment.CurrentDirectory + "\\ConceptsClient.json"));

                appSettings.ServerUrl = string.Format(appSettings.ServerUrl, appSettings.Server);
                if (Program.appSettings.ServerUrl.EndsWith('/') == false && Program.appSettings.ServerUrl.EndsWith('\\') == false)
                {
                    appSettings.ServerUrl += "/";
                }

                //if (appSettings.LogsFolderPath == null || appSettings.LogsFolderPath == "")
                //    appSettings.LogsFolderPath = Startup.hostingEnvironment.ContentRootPath + "\\Logs";

                //textLogWriter.InitializeLogWriter(appSettings.LogsFolderPath, "ConceptsClient", false, true, true, true);


                var builder = CreateWebHostBuilder(args);
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "web host builder created");

                builder.UseKestrel().UseIISIntegration();
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "going to use URL " + appSettings.LocalUrl);

                //    builder.UseUrls("http://0.0.0.0:82");


                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "useUrls set");

                //   if (Debugger.IsAttached == false)// that is running as windows service
                //   builder.UseContentRoot(System.Environment.CurrentDirectory);


                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "Content root set as " + Environment.CurrentDirectory);

                var host = builder.Build();
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "Host built now. Run as Service =" + appSettings.RunAsService);

                if (appSettings.RunAsService)
                {
                    task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "Host starting as windows service");
                    task.EndTask();
                    // host.RunAsCustomService();// host.RunAsService();
                }
                else
                {
                    task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "Host starting now as process");
                    task.EndTask();
                    host.Run();
                }
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, ex);
            }
            finally
            {
                if (task.ended == false)
                {
                    task.EndTask();
                }
            }
        }