Пример #1
0
        /// <summary>
        /// Initialize this client environment from the specified configuration file and version
        /// using the configuration parser.
        /// </summary>
        /// <param name="parser">Configuration parser to use.</param>
        /// <param name="configfile">Configuration file path.</param>
        /// <param name="version">Configuration version (expected)</param>
        /// <param name="password">Password, if configuration has encrypted nodes.</param>
        protected void Init(AbstractConfigParser parser, string configfile,
                            Version version, string password = null)
        {
            try
            {
                LogUtils.Info(String.Format(
                                  "Initializing Client Environment : With Configuration file [{0}]...",
                                  configfile));
                Uri            path   = new Uri(NetUtils.FilePathToFileUrl(configfile));
                AbstractReader reader = ConfigProviderFactory.GetReader(path);
                if (reader == null)
                {
                    throw new ConfigurationException(String.Format("Failed to get reader. [URI={0}]", path.ToString()));
                }
                parser.Parse(ConfigName, reader,
                             version,
                             null, password);
                __configuration = parser.GetConfiguration();
                if (__configuration == null)
                {
                    throw new ConfigurationException(String.Format(
                                                         "Error parsing configuration : NULL configuration read. [file={0}]",
                                                         configfile));
                }

                PostInit();

                UpdateState(EEnvState.Initialized);
            }
            catch (Exception e)
            {
                throw new ConfigurationException(e);
            }
        }
Пример #2
0
        /// <summary>
        /// 獲得Reader名稱為RegawareM1的實例
        /// </summary>
        /// <returns></returns>
        public static AbstractReader GetReaderInstance()
        {
            //AbstractReader reader = GetReader("TH24G");
            AbstractReader reader = GetReaderInstance <AbstractReader>(ReaderEquipment_24GReader);

            return(reader);
        }
Пример #3
0
        public static void logAndTriggerApiErr(string senderName, string errCode, string exceptionMsg, LogType logType)
        {
            string str = senderName + ":";

            str = ((!ErrInfoList.ErrDictionary.ContainsKey(errCode)) ? (str + " ErrCode(" + errCode + ") ") : (str + ErrInfoList.ErrDictionary[errCode]));
            if (!string.IsNullOrEmpty(exceptionMsg))
            {
                str = str + "|Exception:" + exceptionMsg;
            }
            AbstractReader.TrigerApiException(senderName, new ErrInfo(errCode, str));
            switch (logType)
            {
            case LogType.Fatal:
                Log.Fatal(str);
                break;

            case LogType.Error:
                Log.Error(str);
                break;

            case LogType.Warn:
                Log.Warn(str);
                break;

            case LogType.Info:
                Log.Info(str);
                break;

            case LogType.Debug:
                Log.Debug(str);
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// 獲得Reader實例
        /// </summary>
        /// <param name="readerName">RegawareM1、RegawareM5</param>
        /// <returns></returns>
        public static AbstractReader GetReaderInstance(string readerName)
        {
            //AbstractReader reader = GetReader(readerName);
            AbstractReader reader = GetReaderInstance <AbstractReader>(readerName);

            return(reader);
        }
Пример #5
0
        private Token GetNextToken(string input, int inputIndex)
        {
            var currSymbol = input[inputIndex];

            return(TokenReaders.ContainsKey(currSymbol)
                ? TokenReaders[currSymbol].Read(input, inputIndex)
                : AbstractReader.Read(input, inputIndex, CurrMdSymbols));
        }
Пример #6
0
        public Token Read(string input, int inputIndex)
        {
            var headerLevel = GetHeaderLevel(input, inputIndex);
            var headerToken = AbstractReader.Read(input, inputIndex + headerLevel, '\n');

            headerToken.Tag      = TokenType.Header;
            headerToken.TagLevel = headerLevel;
            return(headerToken);
        }
Пример #7
0
        /// <summary>
        /// Parse a included configuration reference.
        /// </summary>
        /// <param name="parent">Parent Config Node</param>
        /// <param name="elem">XML Element</param>
        private void AddIncludeNode(ConfigPathNode parent, XmlElement elem)
        {
            string configName = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_NAME);

            if (String.IsNullOrWhiteSpace(configName))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_NAME);
            }
            string path = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_PATH);

            if (String.IsNullOrWhiteSpace(path))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_PATH);
            }
            string st = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);

            if (String.IsNullOrWhiteSpace(st))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);
            }
            EUriScheme type = EUriScheme.none.ParseScheme(st);

            if (type == EUriScheme.none)
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_TYPE);
            }
            string vs = elem.GetAttribute(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_VERSION);

            if (String.IsNullOrWhiteSpace(vs))
            {
                throw ConfigurationException.PropertyMissingException(ConstXmlConfigIncludeNode.XML_CONFIG_INCLUDE_VERSION);
            }
            Version version = Version.Parse(vs);

            ConfigIncludeNode node = new ConfigIncludeNode(configuration, parent);

            node.Name       = elem.Name;
            node.ConfigName = configName;
            node.Path       = ReaderTypeHelper.ParseUri(path);
            node.ReaderType = type;
            node.Version    = version;

            using (AbstractReader reader = ReaderTypeHelper.GetReader(type, node.Path))
            {
                reader.Open();
                XmlConfigParser parser = new XmlConfigParser();
                parser.Parse(node.ConfigName, reader, node.Version, settings);
                Configuration config = parser.GetConfiguration();
                node.Reference = config;
                node.Node      = config.RootConfigNode;
                node.UpdateConfiguration(configuration);
            }
            parent.AddChildNode(node);
        }
Пример #8
0
        public Token Read(string input, int inputIndex)
        {
            if (CheckFullSymbol(input, inputIndex))
            {
                var token = AbstractReader.Read(input, inputIndex + 3, '\n');
                token.Tag = TokenType.Horizontal;
                return(token);
            }

            return(AbstractReader.Read(input, inputIndex, MarkdownSymbols.AllSymbols));
        }
Пример #9
0
        public Token GetTokenWithoutTags(string input, int inputIndex, char stopSymbol, int stopSymbolQuant)
        {
            var refund = "";

            for (var quantApended = 0; quantApended < stopSymbolQuant; quantApended++)
            {
                refund += stopSymbol;
            }
            var startToken = AbstractReader.Read(input, inputIndex + stopSymbolQuant, MarkdownSymbols.Emphasis);

            return(new Token(refund + startToken.Text, inputIndex));
        }
Пример #10
0
        public Token Read(string input, int inputIndex)
        {
            var startIndex = inputIndex;

            if (inputIndex + 1 <= input.Length - 1 &&
                input[inputIndex + 1] == MarkdownSymbols.Quote)
            {
                inputIndex = GetTagIndexWithTrueEnviron(input, inputIndex + 2, CheckQuotesEnviron);
                if (inputIndex != -1)
                {
                    var token = new Token(input.Substring(startIndex + 2, inputIndex - startIndex - 2), startIndex + 2);
                    token.Tag = TokenType.Quotes;
                    return(token);
                }
            }
            return(AbstractReader.Read(input, startIndex + 1, MarkdownSymbols.AllSymbols));
        }
Пример #11
0
        /// <summary>
        /// Download a resource file specified in the configuration node passed.
        /// </summary>
        /// <param name="fnode">File Resource Node</param>
        /// <returns>Downloaded File path</returns>
        public static string DownloadResource(ConfigResourceFile fnode)
        {
            using (AbstractReader reader = ReaderTypeHelper.GetReader(fnode.Location))
            {
                Conditions.NotNull(reader);
                reader.Open();
                string   f  = FileUtils.WriteLocalFile(reader.GetStream(), fnode.ResourceName, fnode.Configuration.Settings.GetTempDirectory());
                FileInfo fi = new FileInfo(f);
                if (!fi.Exists)
                {
                    throw new ConfigurationException(String.Format("Erorr downloading file: File not created. [file={0}]", fi.FullName));
                }
                fnode.File       = fi;
                fnode.Downloaded = true;

                return(fi.FullName);
            }
        }
Пример #12
0
        public List <AbstractReader> GetAvailableInnerReadersFor(AbstractReader reader)
        {
            var res = new List <AbstractReader>();

            if (!AllowedInnerReadersByDefault.TryGetValue(reader, out var allowedInnerReaders) || allowedInnerReaders.Count == 0)
            {
                return(res);
            }

            foreach (var innerReader in AllowedReaders)
            {
                if (allowedInnerReaders.Contains(innerReader))
                {
                    res.Add(innerReader);
                }
            }

            return(res);
        }
Пример #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            IEncryption    encryption   = null;
            ISecurityRole  securityRole = null;
            AbstractReader reader       = null;

            if (checkBox1.Checked)
            {
                encryption = new ReverseEncryption();
            }

            if (checkBox2.Checked)
            {
                securityRole = new ClassicSecurityRole();
            }

            reader = GetReaderByIndex(comboBox1.SelectedIndex, encryption, securityRole, textBox3.Text, textBox4.Text);

            textBox2.Text = reader.Read(textBox1.Text);
        }
Пример #14
0
 public override void Parse(string name, AbstractReader reader, Version version, ConfigurationSettings settings, string passwrod = null)
 {
     if (settings == null)
     {
         settings = new ConfigurationSettings();
     }
     configuration = new Configuration(settings);
     LogUtils.Info(String.Format("Loading Configuration: [name={0}]", name));
     try
     {
         configuration.Validate();
         configuration.PostLoad();
         LogUtils.Debug(String.Format("Configuration Loaded: [name={0}]", configuration.Header.Name), configuration);
     }
     catch (Exception ex)
     {
         LogUtils.Error(ex);
         configuration.SetError(ex);
         throw ex;
     }
 }
Пример #15
0
        /// <summary>
        /// Load a configuration from local/remote location.
        /// </summary>
        /// <param name="configName">Configuration name</param>
        /// <param name="configUri">Configuration File URI</param>
        /// <param name="configType">Configuration Type</param>
        /// <param name="version">Configuration Version (expected)</param>
        /// <param name="settings">Configuration Settings</param>
        /// <param name="password">Password (if required)</param>
        /// <returns>Loaded Configruation</returns>
        public Configuration Load(string configName, string configUri,
                                  EConfigType configType, Version version,
                                  ConfigurationSettings settings, string password = null)
        {
            Preconditions.CheckArgument(configName);
            Preconditions.CheckArgument(configUri);
            Preconditions.CheckArgument(configType);
            Preconditions.CheckArgument(version);

            LogUtils.Info(String.Format("Loading Configuration. [name={0}][version={1}][uri={2}]", configName, version.ToString(), configUri));

            Uri uri = new Uri(configUri);

            using (AbstractReader reader = ConfigProviderFactory.GetReader(uri))
            {
                AbstractConfigParser parser = ConfigProviderFactory.GetParser(configType);
                Postconditions.CheckCondition(parser);

                parser.Parse(configName, reader, version, settings, password);

                return(parser.GetConfiguration());
            }
        }
Пример #16
0
        /// <summary>
        /// Parse a new configuration instance.
        /// </summary>
        /// <param name="name">Configuration name.</param>
        /// <param name="reader">Configuration Data reader</param>
        /// <param name="version">Expected configuration version</param>
        /// <param name="settings">Configuration Settings</param>
        /// <param name="password">Decryption Password (if required)</param>
        public override void Parse(string name, AbstractReader reader, Version version, ConfigurationSettings settings, string password = null)
        {
            Preconditions.CheckArgument(name);
            Preconditions.CheckArgument(reader);
            Preconditions.CheckArgument(version);

            if (settings == null)
            {
                settings = new ConfigurationSettings();
            }
            configuration = new Configuration(settings);
            this.settings = settings;
            LogUtils.Info(String.Format("Loading Configuration: [name={0}]", name));
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(reader.GetStream());

                XmlElement root = doc.DocumentElement;
                ParseRootNode(name, version, root, password);

                PostLoad(settings.ReplaceProperties);

                if (!String.IsNullOrWhiteSpace(password))
                {
                    ZConfigEnv.Vault.AddPasscode(configuration, password);
                    LogUtils.Info(String.Format("Added passcode to vault. [configuration={0}]", configuration.Header.Name));
                }
                LogUtils.Debug(String.Format("Configuration Loaded: [name={0}]", configuration.Header.Name), configuration);
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                configuration.SetError(ex);
                throw ex;
            }
        }
Пример #17
0
        /// <summary>
        /// 初始化读写器
        /// </summary>
        protected void InitReader()
        {
            if (this._IsConnected)
            {
                return;
            }
            this._Reader = PaymentReaderFactory.CreateWriter(PaymentReaderFactory.EastRiverReader906);

            ReturnValueInfo rvInfo = this._Reader.Conn();
            if (rvInfo.boolValue && !rvInfo.isError)
            {
                this._IsConnected = true;
            }
        }
Пример #18
0
        public ExcelReader(string filename)
        {
            var stream = AbstractReader.Copy(filename);

            _doc = SpreadsheetDocument.Open(stream, false);
        }
Пример #19
0
 /// <summary>
 /// Parse the configuration loaded by the reader handle.
 /// </summary>
 /// <param name="name">Configuration name</param>
 /// <param name="reader">Reader handle to read the configuration</param>
 /// <param name="version">Expected Version of the configuration</param>
 /// <param name="settings">Configuration Settings to use</param>
 /// <param name="password">Decryption Password (if required)</param>
 public abstract void Parse(string name, AbstractReader reader, Version version, ConfigurationSettings settings, string password = null);
Пример #20
0
        public void Parse_CorrectToken(string input, string tokenText, char stopSymbol)
        {
            var resToken = AbstractReader.Read(input, 0, stopSymbol);

            resToken.Text.Should().Be(tokenText);
        }
Пример #21
0
 private void Reader_OnMessageNotificationReceived(AbstractReader reader, IReaderMessage msg)
 {
     if (msg.Status == MsgStatus.Success || msg is MsgActiveTagActive || msg is MsgActiveTagSleep)
     {
         if (msg is MsgTagInventory)
         {
             if (isStart_AutoPowerConfig && !isPause_AutoPowerConfig)
             {
                 if (this.OnAutoPowerConfigInventoryReceived != null)
                 {
                     MsgTagInventory msgTagInventory = msg as MsgTagInventory;
                     if (IsEnableAntenna || IsEnableRSSI)
                     {
                         msgTagInventory.ReceivedMessage.setAntennaAndRSSI(IsEnableAntenna, IsEnableRSSI);
                     }
                     this.OnAutoPowerConfigInventoryReceived(reader.ReaderName, msgTagInventory.ReceivedMessage.TagData);
                 }
             }
             else if (this.OnInventoryReceived != null)
             {
                 MsgTagInventory msgTagInventory2 = msg as MsgTagInventory;
                 if (msgTagInventory2.isRS485)
                 {
                     RS485Item[] rS485Items = RS485Items;
                     foreach (RS485Item rS485Item in rS485Items)
                     {
                         if (rS485Item.Address == msgTagInventory2.address)
                         {
                             if (rS485Item.IsEnableAntenna || rS485Item.IsEnableRSSI)
                             {
                                 msgTagInventory2.ReceivedMessage.setAntennaAndRSSI(IsEnableAntenna, IsEnableRSSI);
                             }
                             break;
                         }
                     }
                 }
                 else if (IsEnableAntenna || IsEnableRSSI)
                 {
                     msgTagInventory2.ReceivedMessage.setAntennaAndRSSI(IsEnableAntenna, IsEnableRSSI);
                 }
                 this.OnInventoryReceived(reader.ReaderName, msgTagInventory2.ReceivedMessage.TagData);
             }
         }
         if (msg is MsgTagRead && this.OnInventoryReceived != null)
         {
             MsgTagRead msgTagRead = msg as MsgTagRead;
             if (msgTagRead.isRS485)
             {
                 RS485Item[] rS485Items2 = RS485Items;
                 foreach (RS485Item rS485Item2 in rS485Items2)
                 {
                     if (rS485Item2.Address == msgTagRead.address)
                     {
                         if (rS485Item2.IsEnableAntenna || rS485Item2.IsEnableRSSI)
                         {
                             msgTagRead.ReceivedMessage.setAntennaAndRSSI(IsEnableAntenna, IsEnableRSSI);
                         }
                         break;
                     }
                 }
             }
             else if (IsEnableAntenna || IsEnableRSSI)
             {
                 msgTagRead.ReceivedMessage.setAntennaAndRSSI(IsEnableAntenna, IsEnableRSSI);
             }
             this.OnInventoryReceived(reader.ReaderName, msgTagRead.ReceivedMessage.TagData);
         }
         if (msg is MsgAlarmInfo_AccessControl && this.OnMsgAlarmInfo_AccessControl != null)
         {
             MsgAlarmInfo_AccessControl msgAlarmInfo_AccessControl = msg as MsgAlarmInfo_AccessControl;
             this.OnMsgAlarmInfo_AccessControl(reader.ReaderName, msgAlarmInfo_AccessControl.ReceivedMessage.TagData);
         }
         if (msg is MsgActiveTagInventory && this.OnActiveTagInventoryReceived != null)
         {
             MsgActiveTagInventory msgActiveTagInventory = msg as MsgActiveTagInventory;
             this.OnActiveTagInventoryReceived(reader.ReaderName, msgActiveTagInventory.ReceivedMessage.ActiveTagList);
         }
         if (msg is MsgActiveTagInventory2 && this.OnActiveTagInventoryReceived != null)
         {
             MsgActiveTagInventory2 msgActiveTagInventory2 = msg as MsgActiveTagInventory2;
             this.OnActiveTagInventoryReceived(reader.ReaderName, msgActiveTagInventory2.ReceivedMessage.ActiveTagList);
         }
         if (msg is MsgActiveTagActive && this.OnMsgActiveTagActiveReceivedHandle != null)
         {
             MsgActiveTagActive msg2 = msg as MsgActiveTagActive;
             this.OnMsgActiveTagActiveReceivedHandle(reader.ReaderName, msg2);
         }
         if (msg is MsgActiveTagSleep && this.OnMsgActiveTagSleepReceivedHandle != null)
         {
             MsgActiveTagSleep msg3 = msg as MsgActiveTagSleep;
             this.OnMsgActiveTagSleepReceivedHandle(reader.ReaderName, msg3);
         }
         if (msg is MsgFirmwareOnlineUpgrade && this.OnFirmwareOnlineUpgradeReceived != null)
         {
             MsgFirmwareOnlineUpgrade msgFirmwareOnlineUpgrade = msg as MsgFirmwareOnlineUpgrade;
             uint   frameAddress = msgFirmwareOnlineUpgrade.ReceivedMessage.FrameAddress;
             ushort total        = (ushort)(frameAddress >> 16);
             ushort rate         = (ushort)frameAddress;
             this.OnFirmwareOnlineUpgradeReceived(total, rate);
         }
         if (msg is MsgAppFirmwareOnlineUpgrade && this.OnFirmwareOnlineUpgradeReceived != null)
         {
             MsgAppFirmwareOnlineUpgrade msgAppFirmwareOnlineUpgrade = msg as MsgAppFirmwareOnlineUpgrade;
             uint   frameAddress2 = msgAppFirmwareOnlineUpgrade.ReceivedMessage.FrameAddress;
             ushort total2        = (ushort)(frameAddress2 >> 16);
             ushort rate2         = (ushort)frameAddress2;
             this.OnAppFirmwareOnlineUpgradeReceived(total2, rate2);
         }
         if (msg is MsgCtrlUpdata_YC001 && this.OnCtrlUpdata_YC001 != null)
         {
             MsgCtrlUpdata_YC001 msgCtrlUpdata_YC = msg as MsgCtrlUpdata_YC001;
             byte             ctrlBoardNO         = msgCtrlUpdata_YC.ReceivedMessage.CtrlBoardNO;
             IrTrigger[]      irStates            = msgCtrlUpdata_YC.ReceivedMessage.IrStates;
             SenssorTrigger[] senssorStates       = msgCtrlUpdata_YC.ReceivedMessage.SenssorStates;
             this.OnCtrlUpdata_YC001(ctrlBoardNO, irStates, senssorStates);
         }
         if (msg is MsgKeepAlive_YC001 && this.OnKeepAlive_YC001 != null)
         {
             this.OnKeepAlive_YC001();
         }
         if (msg is MsgKeepAlive)
         {
             if (keepAliveInterval == 0)
             {
                 MsgKeepAliveConfig msgKeepAliveConfig = new MsgKeepAliveConfig();
                 if (Send(msgKeepAliveConfig, 2000))
                 {
                     isEnableKeepAlive = msgKeepAliveConfig.ReceivedMessage.IsEnable;
                     keepAliveInterval = msgKeepAliveConfig.ReceivedMessage.Interval;
                 }
             }
             if (threadKeepAlive == null || !threadKeepAlive.IsAlive)
             {
                 threadKeepAlive = new Thread(threadKeepAliveMethod);
                 threadKeepAlive.Start();
             }
             dtKeepAlive = DateTime.Now;
         }
         if (msg is MsgSearchIp)
         {
             MsgSearchIp info = msg as MsgSearchIp;
             if (this.OnUdpSearchIpReceived != null)
             {
                 this.OnUdpSearchIpReceived(ReaderName, info);
             }
         }
     }
 }