Ejemplo n.º 1
0
        public override string OnPull(ParameterizedMap map)
        {
            StringBuilder responseJson  = new StringBuilder();
            bool          deviceRemoved = false;

            GSMCommunication.Feature.BasicInformation basic = map.TryGet <BasicInformation>("base");
            if (basic != null)
            {
                try
                {
                    basic.OnBeginExecuting();
                    List <BaseResult <SMSReadResult> > list = actions.Get <ISMS>().ReadAll(map);
                    actions.Get <ISMS>().DeleteAll(map);
                    responseJson = new StringBuilder(Newtonsoft.Json.JsonConvert.SerializeObject(list));
                }
                catch (System.IO.IOException ex)
                {
                    /// port closed
                    IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();
                    log.Write(ex.Message + " - pull command (I/O)");
                    log.Write("plug the device...");
                    deviceRemoved = true;
                }
                catch (System.InvalidOperationException ioe)
                {
                    // port closed
                    IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();
                    log.Write(ioe.Message + " - pull command (invalid operation)");
                    log.Write("plug the device...");
                    deviceRemoved = true;
                }
                finally
                {
                    basic.OnEndExecuting();
                }
            }
            if (deviceRemoved)
            {
                Thread.Sleep(1000);
                IServer server = ObjectPool.Instance.Resolve <IServer>();
                server.OnDeviceRemoved();
            }
            return(responseJson.ToString());
        }
Ejemplo n.º 2
0
        private void RaiseError(BasicInformation connection, Exception ex, string location)
        {
            portColletion.Add(connection);
            if (portColletion.Count > 0)
            {
                Console.WriteLine("connection has been restored.");
            }
            IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();

            log.Write(string.Format("{0} - {1}", ex, location));
        }
        public bool OnRequesting(PacketEventArgs requestFilter)
        {
            //// filtering header
            //// 1. get string using encoding ibm850
            //// 2. decrypt using rijndael
            //// 3. split with "</>"
            if (configuration == null)
            {
                configuration = ObjectPool.Instance.Resolve <GSMServer.Configuration.IConfiguration>();
            }
            if (string.IsNullOrEmpty(signature) || (string.IsNullOrEmpty(encodingName) || (encoding == null)))
            {
                signature    = ((ApplicationSettings)configuration).General.SMSGWSignature;
                encodingName = ((ApplicationSettings)configuration).General.DefaultEncoding;
                encoding     = Encoding.GetEncoding(encodingName);
            }

            lock (s_InternalSyncObject)
            {
                string dataFilter = "";
                if (requestFilter.Data.Length > 0)
                {
                    try
                    {
                        dataFilter = c.Decrypt(encoding.GetString(requestFilter.Data));
                    }
                    catch (FormatException fe)
                    {
                        IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();
                        log.Write(fe.Message + " - on requesting");
                        return(false);
                    }
                    requestFilter.Data = encoding.GetBytes(dataFilter);
                }
                if (!string.IsNullOrEmpty(dataFilter))
                {
                    Request request = JsonConvert.DeserializeObject <Request>(dataFilter, new JsonSerializerSettings
                    {
                        TypeNameHandling = TypeNameHandling.Objects
                    });
                    request.RemoteEndPoint = (IPEndPoint)requestFilter.Client.RemoteEndPoint;

                    if (request.Header != null)
                    {
                        if (request.Header.Signature != null)
                        {
                            if (!request.Header.Signature.Equals(signature))
                            {
                                request.Cancel = true;
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        public override string OnPush(ParameterizedMap map)
        {
            dynamic       response      = null;
            bool          deviceRemoved = false;
            StringBuilder responseJson  = new StringBuilder();

            GSMCommunication.Feature.BasicInformation basic = map.TryGet <BasicInformation>("base");
            if (basic != null)
            {
                try
                {
                    basic.OnBeginExecuting();
                    List <string> command = map.TryGet <List <string> >("command");

                    if (command.Where(s => s.ToLower() == "help").Any())
                    { // if command contains 'help' word
                        ActionInvoker invoker = actions.ToList().Where(d => d.InterfaceType.Name.ToLower() == command[1].ToLower()).SingleOrDefault();
                        if (invoker != null)
                        {
                            responseJson = new StringBuilder(Newtonsoft.Json.JsonConvert.SerializeObject(invoker.Commands,
                                                                                                         Newtonsoft.Json.Formatting.None,
                                                                                                         new Newtonsoft.Json.JsonSerializerSettings()
                            {
                                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                            }));
                        }
                    }
                    else
                    {
                        ActionInvoker invoker = actions.ToList().Where(d => d.InterfaceType.Name.ToLower() == command[0].ToLower()).SingleOrDefault();
                        if (invoker != null)
                        {
                            response = invoker.TryInvoke(command[1], new object[] { map });
                            if (response != null)
                            {
                                responseJson = new StringBuilder(Newtonsoft.Json.JsonConvert.SerializeObject(response,
                                                                                                             Newtonsoft.Json.Formatting.None,
                                                                                                             new Newtonsoft.Json.JsonSerializerSettings()
                                {
                                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                                }));
                            }
                        }
                    }
                }
                catch (UnauthorizedAccessException uae)
                {
                    IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();
                    log.Write(uae.Message + " - push command (unauthorized access)");
                    log.Write("plug the device...");
                    deviceRemoved = true;
                }
                catch (System.IO.IOException ioe)
                {
                    IErrorLogging log = ObjectPool.Instance.Resolve <IErrorLogging>();
                    log.Write(ioe.Message + " - push command (I/O)");
                    log.Write("plug the device...");
                    deviceRemoved = true;
                }
                finally
                {
                    basic.OnEndExecuting();
                }
            }
            if (deviceRemoved)
            {
                Thread.Sleep(1000);
                IServer server = ObjectPool.Instance.Resolve <IServer>();
                server.OnDeviceRemoved();
            }
            return(responseJson.ToString());
        }