Exemplo n.º 1
0
        public ZeroResponse<string[]> GetExistingPacks(string ID)
        {
            ZeroResponse<string[]> ret = new ZeroResponse<string[]>
            {
                IsValid = true,
            };

            using (ZeroServerConfiguration Config = new ZeroServerConfiguration())
            {
                int TCode = 0;
                string msg = "";
                bool stat = Config.ValidateConnection(ID, out TCode, out msg);
                if (stat)
                {
                    ret.Result = Config.GetPackNamesToSend(TCode);
                }
                else
                {
                    if (TCode > 0)
                        Config.UpdateConnectionStatus(ID, ZeroServerConfiguration.ConnectionState.Error);
                }
                ret.Status = msg;
            }

            return ret;
        }
Exemplo n.º 2
0
        public ZeroResponse<string> GetTerminals(string ID)
        {
            var ret = new ZeroResponse<string>();
            ret.IsValid = false;
            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, ID))
            {
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            int tCode = -1;
                            if (Config.ValidateConnection(ID, out hlp.TerminalCode, out hlp.StatusMessage))
                            {
                                IEnumerable<Terminal> list = Config.GetTerminals(tCode);
                                ret.Result = ContextExtentions.GetEntitiesAsXMLObjectList(list);
                            }

                        }
                    });

                ret.IsValid = hlp.IsValid;
                ret.Message = hlp.StatusMessage;
            }

            return ret;
        }
Exemplo n.º 3
0
        public ZeroResponse<Dictionary<int, int>> GetExistingPacks(string ID)
        {
            var ret = new ZeroResponse<Dictionary<int, int>>();
            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, ID))
            {
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            if (Config.ValidateConnection(ID, out hlp.TerminalCode, out hlp.StatusMessage))
                            {
                                ret.Result = Config.GetPacksToSend(hlp.TerminalCode);
                            }
                            else
                            {
                                if (hlp.TerminalCode >= 0)
                                    Config.UpdateConnectionStatus(ID, ZeroServerConfiguration.ConnectionState.Error);
                            }
                        }
                    });

                ret.IsValid = hlp.IsValid;
                ret.Message = hlp.StatusMessage;
            }

            return ret;
        }
        public ZeroResponse<List<TerminalStatus>> GetTerminalsStatus()
        {
            var ret = new ZeroResponse<List<TerminalStatus>>();
            try
            {
                var conf = new ZeroServerConfiguration();

                using (var ent = new ConfigurationModelManager())
                {
                    ent.ContextOptions.LazyLoadingEnabled = false;
                    ret.Result = new List<TerminalStatus>();
                    foreach (var terminal in ent.Terminals)
                    {
                        var tst = new TerminalStatus();
                        tst.Terminal = terminal;
                        tst.Info += string.Format("IP: {0}\n", terminal.LastKnownIP);
                        var tt = conf.GetPacksToSend(tst.Terminal.Code);
                        if (tt.Count > 0)
                        {
                            tst.Info += string.Format("Packs pendientes: {0}\n", tt.Count);
                            foreach (var i in tt)
                            {
                                tst.Info += string.Format("Módulo: {0}(Pack: {1})\n", i.Value, i.Key);
                            }
                        }

                        ret.Result.Add(tst);
                    }

                    foreach (var item in ret.Result)
                    {
                        TerminalProperty prop =
                            ent.TerminalProperties.FirstOrDefault(
                                tp => tp.TerminalCode == item.Terminal.Code && tp.Code == "SYNC_EVERY");
                        if (prop != null)
                        {
                            if (item.Terminal.LastSync.HasValue)
                            {
                                item.Terminal.IsSyncronized = item.Terminal.LastSync.Value.AddMinutes(int.Parse(prop.Value)) >
                                                     DateTime.Now;
                            }
                        }

                    }

                }

                ret.IsValid = true;
            }
            catch (Exception ex)
            {
                ret.IsValid = false;
                ret.Message = ex.ToString();
            }

            return ret;
        }
Exemplo n.º 5
0
        public ZeroResponse<string> GetTerminals(string ID)
        {
            ZeroResponse<string> ret = new ZeroResponse<string>();
            ret.IsValid = true;
            using (ZeroServerConfiguration Config = new ZeroServerConfiguration())
            {
                string msg;
                int tCode = -1;
                if (Config.ValidateConnection(ID, out tCode, out msg))
                {
                    IEnumerable<Terminal> list = Config.GetTerminals(tCode);
                    ret.Result = ZeroCommonClasses.Helpers.IEnumerableExtentions.GetEntitiesAsXMLObjectList<Terminal>(list);
                }

                ret.Status = msg;
            }
            return ret;
        }
Exemplo n.º 6
0
        public ZeroResponse<bool> SendClientTerminals(string ID, string terminals)
        {
            var ret = new ZeroResponse<bool>();

            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, ID, terminals))
            {
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            if (Config.ValidateConnection(ID, out hlp.TerminalCode, out hlp.StatusMessage))
                            {
                                ret.Result = true;
                                Config.MergeTerminal(hlp.TerminalCode, ContextExtentions.GetEntitiesFromXMLObjectList<Terminal>(terminals));
                            }
                        }
                    });

                ret.IsValid = hlp.IsValid;
                ret.Message = hlp.StatusMessage;
            }

            return ret;
        }
Exemplo n.º 7
0
        public ZeroResponse<bool> SendClientModules(string ID, string modules)
        {
            var ret = new ZeroResponse<bool>();
            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, ID, modules))
            {
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            if (Config.ValidateConnection(ID, out hlp.TerminalCode, out hlp.StatusMessage))
                            {
                                IEnumerable<Module> mods = ContextExtentions.GetEntitiesFromXMLObjectList<Module>(modules);
                                Config.MergeModules(mods, hlp.TerminalCode);
                                ret.Result = true;
                            }
                        }

                    });

                ret.IsValid = hlp.IsValid;
                ret.Message = hlp.StatusMessage;
            };

            return ret;
        }
Exemplo n.º 8
0
        public ZeroResponse<string> SayHello(string name, int terminal)
        {
            var ret = new ZeroResponse<string>();
            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, "", name, terminal))
            {
                hlp.TerminalCode = terminal;
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            if (Config.ValidateTerminal(terminal, name, out hlp.StatusMessage))
                            {
                                string ip = GetWCFMethodCallerIp();
                                ret.Result = Config.CreateConnection(terminal, ip);
                                Trace.WriteLine(string.Format("Iniciando Conexión con terminal {0} - ID {1} - ConnID {2} - IP: {3}", name, terminal, ret.Result, ip));
                            }
                        }
                    });

                ret.IsValid = hlp.IsValid;
                ret.Message = hlp.StatusMessage;
            }

            return ret;
        }
Exemplo n.º 9
0
        public ZeroResponse<DateTime> SayBye(string ID)
        {
            var ret = new ZeroResponse<DateTime>();
            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, ID))
            {
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            if (Config.ValidateConnection(ID, out hlp.TerminalCode, out hlp.StatusMessage))
                            {
                                Config.UpdateConnectionStatus(ID, ZeroServerConfiguration.ConnectionState.Ended);
                                ret.Result = DateTime.Now;
                                Trace.WriteLine(string.Format("Finalizando Conexión con terminal ID {0} - ConnID {1}", hlp.TerminalCode, ID));
                            }
                            else
                            {
                                if (hlp.TerminalCode >= 0)
                                    Config.UpdateConnectionStatus(ID, ZeroServerConfiguration.ConnectionState.Error);

                                ret.Result = DateTime.MinValue;
                            }
                        }
                    });

                ret.Message = hlp.StatusMessage;
                ret.IsValid = hlp.IsValid;
            }

            return ret;
        }
Exemplo n.º 10
0
        public ZeroResponse<bool> MarkPackReceived(string ID, int packCode)
        {
            var ret = new ZeroResponse<bool>();
            using (var hlp = new ServiceLogHelper(System.Reflection.MethodBase.GetCurrentMethod().Name, ID, packCode))
            {
                hlp.Handle(() =>
                    {
                        using (var Config = new ZeroServerConfiguration())
                        {
                            if (Config.ValidateConnection(ID, out hlp.TerminalCode, out hlp.StatusMessage))
                            {
                                Config.MarkPackReceived(hlp.TerminalCode, packCode);
                                ret.Result = true;
                            }
                            else
                            {
                                ret.Result = false;
                            }
                        }
                    });

                ret.Message = hlp.StatusMessage;
                ret.IsValid = hlp.IsValid;

            }

            return ret;
        }
Exemplo n.º 11
0
        public ZeroResponse<bool> MarkPackReceived(string ID, string packName)
        {
            ZeroResponse<bool> ret = new ZeroResponse<bool>();
            ret.IsValid = true;
            using (ZeroServerConfiguration Config = new ZeroServerConfiguration())
            {
                string msg;
                int tCode = -1;
                if (Config.ValidateConnection(ID, out tCode, out msg))
                {
                    Config.MarkPackReceived(tCode, packName);
                    ret.Result = true;
                }

                ret.Result = false;
                ret.Status = msg;
            }

            return ret;
        }
Exemplo n.º 12
0
        public ZeroResponse<bool> SendClientTerminals(string ID, string terminals)
        {
            ZeroResponse<bool> ret = new ZeroResponse<bool>();
            ret.IsValid = true;
            using (ZeroServerConfiguration Config = new ZeroServerConfiguration())
            {
                string msg;
                int tCode = -1;
                if (Config.ValidateConnection(ID, out tCode, out msg))
                {
                    ret.Result = true;
                    Config.MergeTerminal(tCode, IEnumerableExtentions.GetEntitiesFromXMLObjectList<Terminal>(terminals));
                }

                ret.Result = false;
                ret.Status = msg;
            }

            return ret;
        }
Exemplo n.º 13
0
        public ZeroResponse<bool> SendClientModules(string ID, string modules)
        {
            int TCode = 0;
            string msg = "";
            bool stat = true;
            using (ZeroServerConfiguration Config = new ZeroServerConfiguration())
            {
                stat = Config.ValidateConnection(ID, out TCode, out msg);
                if (stat)
                {
                    IEnumerable<Module> mods = IEnumerableExtentions.GetEntitiesFromXMLObjectList<Module>(modules);
                    Config.MergeModules(mods, TCode);
                }
            }
            ZeroResponse<bool> ret = new ZeroResponse<bool>
            {
                IsValid = stat,
                Result = stat,
                Status = (stat) ? "OK" : msg
            };

            return ret;
        }
Exemplo n.º 14
0
 public ZeroResponse<string> SayHello(string name, int terminal)
 {
     System.Diagnostics.Trace.WriteLine(string.Format("Name: {0}, Code: {1}",name,terminal), "SayHello");
     System.Diagnostics.Trace.Indent();
     ZeroResponse<string> ret = new ZeroResponse<string>();
     ZeroServerConfiguration Config = new ZeroServerConfiguration();
     string msg = "";
     ret.IsValid = Config.ValidateTerminal(terminal, name, out msg);
     if (ret.IsValid)
     {
         ret.Result = Config.CreateConnection(terminal);
         msg += " OK";
     }
     System.Diagnostics.Trace.Unindent();
     System.Diagnostics.Trace.WriteLine(string.Format("Name: {0}, Code: {1}, Message: {2}", name, terminal, ret), "SayHello");
     ret.Status = msg;
     return ret;
 }
Exemplo n.º 15
0
        public ZeroResponse<DateTime> SayBye(string ID)
        {
            ZeroResponse<DateTime> ret = new ZeroResponse<DateTime>();
            ret.IsValid = true;
            using (ZeroServerConfiguration Config = new ZeroServerConfiguration())
            {
                string msg;
                int tCode = -1;
                if (Config.ValidateConnection(ID, out tCode, out msg))
                {
                    Config.UpdateConnectionStatus(ID, ZeroServerConfiguration.ConnectionState.Ended);
                    ret.Result = DateTime.Now;
                }
                else
                {
                    if (tCode >= 0)
                        Config.UpdateConnectionStatus(ID, ZeroServerConfiguration.ConnectionState.Error);

                    ret.Result = DateTime.MinValue;
                    ret.Status = msg;
                }
            }

            return ret;
        }