Пример #1
0
        public void ReconnectTest()
        {
            SickScanner ss = new SickScanner("CLV650", LogLevel.Debug);

            ss.Address = "192.168.0.104";
            ss.Read();

            Assert.Fail();
        }
Пример #2
0
        public void SendDisconnectMailTest()
        {
            SickScanner ss = new SickScanner("CLV650", LogLevel.Debug);

            ss.Address             = "192.168.0.104";
            ss.MailOnConnectionTry = 1;
            ss.ReconnectTime       = 0;
            ss.Read();
            Assert.Fail();
        }
Пример #3
0
        public void SubstringLastTest()
        {
            string a = "CLV650 SUBSTRING(0,3,123456) SUBSTRING(2, 3, 654321) 333333";

            string[] substring = Regex.Matches(a, @"SUBSTRING\(\d+,\d+,\w+\)").Cast <Match>().Select(m => m.Value).Distinct().ToArray();

            SickScanner ss = new SickScanner("CLV650", LogLevel.Debug);

            string[] codes = new string[3] {
                "123456", "654321", "333333"
            };
            string template = "@NAME SUBSTRING(0,3,@CODE0) LAST(3,@CODE1) @CODE2";
        }
Пример #4
0
        public void StartWorkTest()
        {
            SickScanner ss = new SickScanner("CLV650", LogLevel.Debug);

            ss.Address = "192.168.0.104";
            ss.MailRecipients.Add(new System.Net.Mail.MailAddress("*****@*****.**"));
            ss.ReconnectTime = 1;
            ss.StartWork();
            string raw = ss.DataRAW;


            Assert.Fail();
        }
Пример #5
0
        public void ParameterTest()
        {
            SickScanner ss = new SickScanner("CLV650", LogLevel.Debug);

            #region Port
            bool exception = false;
            try
            {
                ss.Port = -1;
            }
            catch (Exception ex)
            {
                exception = true;
            }

            if (!exception)
            {
                Assert.Fail();
            }

            exception = false;

            try
            {
                ss.Port = 70_000;
            }
            catch (Exception ex)
            {
                exception = true;
            }

            if (!exception)
            {
                Assert.Fail();
            }
            #endregion Port

            #region Name

            ss.Name = null;
            Assert.AreEqual("Scanner", ss.Name);
            ss.Name = "";
            Assert.AreEqual("Scanner", ss.Name);

            #endregion
        }
Пример #6
0
        private void LoadConfig()
        {
            DataSet config = new DataSet();

            config.ReadXml(string.Format("{0}\\ScannersConfig.xml", AppDomain.CurrentDomain.BaseDirectory));

            int licence = 0;

            foreach (DataRow drScanner in config.Tables["Scanner"].Rows)
            {
#pragma warning disable
                SickScanner ss = new SickScanner((string)drScanner["Name"], LogLevel.Debug);
                ss.Address       = (string)drScanner["Address"];
                ss.Port          = int.Parse((string)drScanner["Port"]);
                ss.ReconnectTime = int.Parse((string)drScanner["ReconnectTime"]);
                ss.Log.Path      = (string)drScanner["LogFilePath"];
                ss.Log.FileName  = ((string)drScanner["LogFileName"]).Replace("@NAME", ss.Name);
#pragma warning restore
                switch ((string)drScanner["LogLevel"])
                {
                case "Debug":
                    ss.Log.Level = LogLevel.Debug;
                    break;

                case "Normal":
                    ss.Log.Level = LogLevel.Normal;
                    break;
                }

                if (bool.TryParse((string)drScanner["EnableHistoricalRead"], out bool enableHistoricalRead))
                {
                    ss.EnableHistoricalRead = enableHistoricalRead;
                }
                if (uint.TryParse((string)drScanner["MailOnConnectionTry"], out uint mailOnConnectionTry))
                {
                    ss.MailOnConnectionTry = mailOnConnectionTry;
                }
                string[] recipients = ((string)drScanner["MailRecipients"]).Split(';');
                foreach (string recipient in recipients)
                {
                    ss.MailRecipients.Add(new MailAddress(recipient));
                }

#pragma warning disable
                DataParser dp = new DataParser(ss.Log);
                dp.HistoricalCodePattern = (string)drScanner["HistoricalCodePattern"];
                ss.HistoricalReaded     += dp.ParseHistorical;
#pragma warning restore
                ss.Readed += dp.Parse;
                foreach (DataRow dr in drScanner.GetChildRows(config.Relations["Scanner_CodeTemplate"]))
                {
                    dp.DataParserConfigs.Add(new DataParserConfig((string)dr["Name"], (string)dr["Pattern"]));
                }

                DataWriter dw = new DataWriter(ss.Log);
                dp.Parsed += dw.Write;
                foreach (DataRow dr in drScanner.GetChildRows(config.Relations["Scanner_FileTemplate"]))
                {
                    dw.DataWriterConfigs.Add(new DataWriterConfig((string)dr["Name"], (string)dr["SavePath"], (string)dr["Content"]));
                }

                if (licence < 2)
                {
                    Scanners.Add(ss);
                }
                licence++;
            }
        }