Пример #1
0
        public static void UpdateTerminalDetails(LogableTaskWithoutEnd task)
        {
            task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "Called");
            task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "going to synch terminal info");

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "TerminalDetails.json"))
            {
                var terminalDetailsStr = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "TerminalDetails.json", System.Text.Encoding.UTF8);
                DataSynchronizer.TerminalDetails = JsonConvert.DeserializeObject <TerminalDetailsResponse>(terminalDetailsStr);
            }

            var reply = ServerHelper.GetResponse <TerminalDetailsResponse>("Terminal/GetTerminalDetails", new BaseTerminalRequest
            {
                CommonParams = new CommonParameters {
                    MachineID = SessionController.MachineID
                }
            }, task);

            if (reply.Success)
            {
                DataSynchronizer.TerminalDetails = reply.Data;
                File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "TerminalDetails.json",
                                  JsonConvert.SerializeObject(DataSynchronizer.TerminalDetails), System.Text.Encoding.UTF8);
            }
            else
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, reply.ErrorDesc);
                throw new Exception(reply.ErrorDesc);
            }
        }
Пример #2
0
        public static void UpdateSadadaData(LogableTaskWithoutEnd task)
        {
            task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, "going to synch sadad data");
            if (DataSynchronizer.SADADBillersData == null)
            {
                try
                {
                    DataSynchronizer.LocalSADADDataVersion = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "SadadData", "*.json", System.IO.SearchOption.TopDirectoryOnly)
                                                             .Select(f => int.Parse(Path.GetFileNameWithoutExtension(f))).Max();

                    var sadadDataStr = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "SadadData/" + LocalSADADDataVersion.ToString() + ".json", System.Text.Encoding.UTF8);
                    DataSynchronizer.SADADBillersData = Newtonsoft.Json.JsonConvert.DeserializeObject <DTOs.Sadad.BillersData>(sadadDataStr);
                }
                catch { LocalSADADDataVersion = -1; }
            }

            var versionReply = ServerHelper.GetResponse <int>("/sadad/GetSadadDataVersion", new BaseTerminalRequest
            {
                CommonParams = new CommonParameters {
                    MachineID = SessionController.MachineID
                }
            }, task);

            if (versionReply.Success == false)
            {
                throw new Exception(versionReply.ErrorDesc);
            }

            var sadadDataVersionAtServer = versionReply.Data;

            if (sadadDataVersionAtServer > LocalSADADDataVersion)
            {
                var SadadDataReply = ServerHelper.GetResponse <byte[]>("/sadad/GetSadadData",
                                                                       new BaseTerminalRequest {
                    CommonParams = new CommonParameters {
                        MachineID = SessionController.MachineID
                    }
                }, task);

                if (SadadDataReply.Success == false)
                {
                    throw new Exception(SadadDataReply.ErrorDesc);
                }

                var sadadDataStr = Lib.GZipper.Unzip(SadadDataReply.Data);

                if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "SadadData") == false)
                {
                    Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "SadadData");
                }

                File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "SadadData\\" + sadadDataVersionAtServer.ToString() + ".json", sadadDataStr, System.Text.Encoding.UTF8);

                SADADBillersData      = Newtonsoft.Json.JsonConvert.DeserializeObject <DTOs.Sadad.BillersData>(sadadDataStr);
                LocalSADADDataVersion = sadadDataVersionAtServer;
                SADADDataSynchedAt    = DateTime.Now;
            }

            DataSynchronizer.SADADDataCheckedAt = DateTime.Now;
        }
Пример #3
0
        public static Response <T> GetResponse <T>(string subUrl, BaseTerminalRequest request, LogableTaskWithoutEnd task)
        {
            try
            {
                var    url = Program.appSettings.ServerUrl + subUrl;
                string req = JsonConvert.SerializeObject(request);
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, Lib.MaskingUtil.MasKPANInString(req));

                string str = Lib.HttpUtil.PostToServerStr(url, req, Program.appSettings.RequestTimeOut);
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Info, Lib.MaskingUtil.MasKPANInString(str));
                var reply = JsonConvert.DeserializeObject <Response <T> >(str);
                if (reply.Success == false)
                {
                    task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Error, reply.ErrorDesc);
                }
                else if (UserSession.CurrentSession != null)
                {
                    UserSession.CurrentSession.SessionID = reply.SessionID;
                }
                return(reply);
            }
            catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout)
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Warning, ex.Message);
                return(new Response <T> {
                    ErrorDesc = UserSession.getServerTimeoutDesc(), Success = false
                });
            }
            catch (Exception ex)
            {
                task.Log(MethodBase.GetCurrentMethod(), System.Diagnostics.TraceLevel.Warning, ex.Message);
                return(new Response <T> {
                    ErrorDesc = ex.Message, Success = false
                });
            }
        }