コード例 #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());
        }
コード例 #2
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());
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: sandalkuilang/texto
        private void InitSerialPort(BasicInformation connection)
        {
            //// let the connection remains open until the server is closed/disposed
            connection.Connector.Open();

            connection.OnBeginExecuting();
 
            BaseResult<GenericTypeResult<string>> manufacturer = connection.GetManufacturer();
            if (!string.IsNullOrEmpty(manufacturer.Response.Result))
            {
                connection.GetServiceCenter();
                connection.SetErrorMessageFormat(1);
                connection.GetOperator();

                PhoneBook pb = new PhoneBook(connection);
                pb.SetPhoneBookMemory(MemoryStorage.SIMOwnNumber);
                pb.GetInfo();

                SMS sms = new SMS(connection);
                sms.SetMessageStorage(MemoryStorage.MobilePhonebook, MemoryStorage.MobilePhonebook, MemoryStorage.MobilePhonebook);
                sms.SetMessageFormat(connection.PDUMode);

                string prefixOwnNumber = string.Empty;
                if (string.IsNullOrEmpty(prefixOwnNumber))
                {
                    GSMServer.Configuration.IConfiguration configuration = ObjectPool.Instance.Resolve<GSMServer.Configuration.IConfiguration>();
                    prefixOwnNumber = ((ApplicationSettings)configuration).General.PrefixOwnNumber;
                }

                BaseResult<GenericTypeResult<List<PhoneNumberInfo>>> list = pb.ReadPhoneBook(MemoryStorage.SIMOwnNumber, 1, -1);
                if (list.Response.Result.Count > 0)
                {
                    foreach (PhoneNumberInfo info in list.Response.Result)
                    {
                        if (info.Name.Equals(prefixOwnNumber))
                        {
                            connection.OwnNumber = info.PhoneNumber;
                            break;
                        }
                    }
                }
                portColletion.Add(connection);
            }
            connection.OnEndExecuting();
        }