Exemplo n.º 1
0
        //根据条件填充实体,并显示
        private void InitionPortDevice()
        {
            DeviceModel dobj = DeviceObj.GetDeviceModel();
            TcpModel    TCPE = dobj.Port.TCP;
            SerialModel SE   = dobj.Port.Serial;

            if (dobj == null || TCPE == null || SE == null)
            {
                return;
            }
            //显示 端口值
            switch (dobj.Port.PortType)
            {
            case Protocol.Modbus_TCPIPPort: cb_Port.Text = "TCP/IP"; break;

            case Protocol.Modbus_SerialPort: cb_Port.Text = SE.PortName; break;

            case Protocol.Modbus_USBPort: cb_Port.Text = "USB"; break;

            default: break;
            }
            tb_IPadr.Text   = TCPE.IP;
            tb_TCPport.Text = TCPE.Port.ToString();

            cb_BaudRate.Text   = SE.BaudRate.ToString();
            cb_Word.Text       = SE.DataBit.ToString();
            cb_Parit.EditValue = ((int)SE.Parity).ToString();
            cb_stop.EditValue  = ((int)SE.StopBit).ToString();
            tb_WaitTime.Text   = SE.RecoveryWaitTime.ToString();
        }
        /// <summary>从指定流stream将反序列化成指定类型的数据</summary>
        /// <typeparam name="T">指定以何种类型反序列化</typeparam>
        /// <param name="destStream">指定待序列化的stream</param>
        /// <param name="serialModel">指定使用何种反序列化的方式</param>
        public static T DeSerialDataFromStream <T>(Stream destStream, SerialModel serialModel = SerialModel.XML)
        {
            if (null == destStream)
            {
                return(default(T));
            }

            switch (serialModel)
            {
            case SerialModel.XML:
                return(new SerialXMLHelper().DeSerialFromStream <T>(destStream));

            case SerialModel.Binary:
                return(new SerialBinaryHelper().DeSerialFromStream <T>(destStream));

            case SerialModel.Json:
                return(new SerialJsonHelper().DeSerialFromStream <T>(destStream));

            case SerialModel.ProtoBuf:
                break;

            default:
                break;
            }

            return(default(T));
        }
        /// <summary>将数据序列化到指定流stream</summary>
        /// <typeparam name="T">指定序列化数据的类型</typeparam>
        /// <param name="data">待序列化的数据</param>
        /// <param name="destStream">指定序列化到哪个stream</param>
        /// <param name="serialModel">指定序列化的方式</param>
        public static void SerialDataToStream <T>(T data, Stream destStream, SerialModel serialModel = SerialModel.XML)
        {
            if (null == destStream)
            {
                return;
            }

            switch (serialModel)
            {
            case SerialModel.XML:
                new SerialXMLHelper().SerialToStream <T>(data, destStream);
                break;

            case SerialModel.Binary:
                new SerialBinaryHelper().SerialToStream <T>(data, destStream);
                break;

            case SerialModel.Json:
                new SerialJsonHelper().SerialToStream <T>(data, destStream);
                break;

            case SerialModel.ProtoBuf:
                break;

            default:
                break;
            }
        }
        /// <summary>从指定文件将反序列化成指定类型的数据</summary>
        /// <typeparam name="T">指定以何种类型反序列化</typeparam>
        ///<param name="strPath">待反序列化的文件路径</param>
        /// <param name="serialModel">指定使用何种反序列化的方式</param>
        public static T DeSerialDataFromFile <T>(string strPath, SerialModel serialModel = SerialModel.XML)
        {
            //路径非法拦截
            if (!FileTool.FileExist(strPath))
            {
                return(default(T));
            }
            Stream destStream = FileTool.ReadyStream(strPath);

            return(DeSerialDataFromStream <T>(destStream, serialModel));
        }
Exemplo n.º 5
0
        public void RtuOverIsolatedTest()
        {
            var model   = new ModbusModel();
            var scanner = new ModbusRTUScanner();

            using (var server = new SerialModel(SlaveCOM, model, scanner))
                using (var master = ModbusMaster.IsolatedRTU(new SerialSettings(MasterCOM)))
                {
                    //race condition avoided by access order
                    H.SharedSlaveTest(model, master);
                }
        }
Exemplo n.º 6
0
        public void TcpOverIsolatedTest()
        {
            var model   = new ModbusModel();
            var scanner = new ModbusTCPScanner();

            using (var server = new SerialModel(SlaveCOM, model, scanner))
                using (var stream = new ModbusIsolatedStream(new SerialSettings(MasterCOM), 400))
                {
                    var master = new ModbusMaster(stream, new ModbusTCPProtocol());
                    //race condition avoided by access order
                    H.SharedSlaveTest(model, master);
                }
        }
Exemplo n.º 7
0
        private void RunTest(ISerialModelTest t)
        {
            var parameters = new WindowsStoreSerialModelParameters(new SwapChainPanelAdapter(RenderTarget));

            SetAssetPath(t, parameters.AssetLocations);

            t.ModifyModelParameters(parameters);

            var smodel = new SerialModel(parameters);

            model = smodel;
            smodel.Run(new Action(t.EntryPoint));
        }
Exemplo n.º 8
0
        public void RtuExceptionOverIsolatedTest()
        {
            var model   = new ModbusModel();
            var scanner = new ModbusRTUScanner();

            using (var server = new SerialModel(SlaveCOM, model, scanner))
                using (var master = ModbusMaster.IsolatedRTU(new SerialSettings(MasterCOM)))
                {
                    var ex = Assert.Throws <ModbusException>(() => H.SharedExceptionTest(master));
                    Assert.AreEqual("Modbus exception 2", ex.Message);
                    Assert.AreEqual(2, ex.Code);
                }
        }
Exemplo n.º 9
0
        public static int InsertSerialNumber(string serialNumber, string workOrderNumber, string builderName)
        {
            SerialModel data = new SerialModel
            {
                SerialNumber    = serialNumber,
                WorkOrderNumber = workOrderNumber,
                BuilderName     = builderName
            };

            string sql = @"INSERT INTO _ud_serialnumbers (serial_num, wo_num, build_date, invoice_num, invoice_date, builder_name) 
                            VALUES (@SerialNumber, @WorkOrderNumber, CURRENT_TIMESTAMP, CONVERT(VARCHAR(25),NULL), CONVERT(DATETIME,NULL), @BuilderName); ";

            return(SQLDataAccess.InsertDataSCMDB(sql, data));
        }
Exemplo n.º 10
0
        public void TcpExceptionOverIsolatedTest()
        {
            var model   = new ModbusModel();
            var scanner = new ModbusTCPScanner();

            using (var server = new SerialModel(SlaveCOM, model, scanner))
                using (var stream = new ModbusIsolatedStream(new SerialSettings(MasterCOM), 400))
                {
                    var master = new ModbusMaster(stream, new ModbusTCPProtocol());
                    var ex     = Assert.Throws <ModbusException>(() => H.SharedExceptionTest(master));
                    Assert.AreEqual("Modbus exception 2", ex.Message);
                    Assert.AreEqual(2, ex.Code);
                }
        }
Exemplo n.º 11
0
        /// <summary>将数据序列化到指定文件</summary>
        /// <typeparam name="T">指定序列化数据的类型</typeparam>
        /// <param name="data">待序列化的数据</param>
        /// <param name="strPath">指定序列化到哪个文件</param>
        /// <param name="serialModel">指定序列化的方式</param>
        public static void SerialDataToFile <T>(T data, string strPath, SerialModel serialModel = SerialModel.XML)
        {
            //路径非法拦截
            if (FileTool.IsErrorPath(strPath))
            {
                return;
            }

            //确保路径可用
            FileTool.EnsureDirectoryExist(strPath);

            Stream destStream = FileTool.ReadyStream(strPath, FileMode.OpenOrCreate, FileAccess.Write);

            SerialDataToStream(data, destStream, serialModel);
        }
Exemplo n.º 12
0
 public void AddOrDelSerial(SerialModel serialModel, bool add)
 {
     if (add)
     {
         SerialModelsCollection.Add(serialModel);
     }
     else
     {
         SerialModel toDel = SerialModelsCollection.AsParallel().FirstOrDefault(x => x == serialModel);
         if (toDel != null)
         {
             SerialModelsCollection.Remove(toDel);
         }
     }
 }
Exemplo n.º 13
0
        public ObservableCollection<SerialModel> Load(IListFileParser listFileParser)
        {
            var temp = new ObservableCollection<SerialModel>();
            if (File.Exists(cashFileName))
            {
                try
                {
                    using (var fs = new FileStream(cashFileName, FileMode.Open, FileAccess.Read))
                    {
                        using (var bw = new BinaryReader(fs))
                        {
                            while (bw.BaseStream.Position != bw.BaseStream.Length)
                            {
                                var filename = bw.ReadString();
                                var info = bw.ReadString();
                                var referenseTofile = bw.ReadString();
                                var size = bw.ReadString();
                                var title = createImage(bw.ReadBytes(bw.ReadInt32()));
                                var countofseries = bw.ReadInt32();
                                List<FileModel> listofModels = new List<FileModel>();
                                for (int i = 0; i < countofseries; i++)
                                {
                                    var sfName = bw.ReadString();
                                    var sfPathToDownload = bw.ReadString();
                                    var sfSerialName = bw.ReadString();
                                    var sfSerialSize = bw.ReadString();
                                    var sfDownloadStatus = (DownloadStatus)bw.ReadInt32();
                                    listofModels.Add(new FileModel(sfName, sfPathToDownload, sfSerialSize, sfSerialName, subscribeManager.DownLoadManagerModel, sfDownloadStatus));
                                }
                                var sm =
                                    new SerialModel(new SeriaInfo(referenseTofile, filename, size, title, info, true),
                                        subscribeManager, listFileParser);
                                sm.SetSerialListFromCach(listofModels);
                                temp.Add(sm);
                            }
                        }
                    }
                }
                catch (Exception)
                {

                    //TODO
                }

            }
            return temp;
        }
Exemplo n.º 14
0
        public async Task<List<SerialModel>> ParseSerials(MatchCollection serialsMatchCollection)
        {

            var models = new List<SerialModel>();
            foreach (Match match in serialsMatchCollection)
            {
                try
                {
                    Match parsedSeries = Regex.Match(match.Groups["SerialEntity"].Value, patern);
                    if (parsedSeries.Groups["folder"].Value.Contains("Статей"))
                    {
                        //string page = await DownLoader.DownloadPageAsync(parsedSeries.Groups["ReferensToFiles"].Value);
                        //var mod = await ParseSerials(Regex.Matches(page, serialEntityPattern));
                        //if (mod!=null)
                        //{
                        //    models.AddRange(mod);
                        //}
                    }
                    else
                    {
                        byte[] img = await downloadImage(parsedSeries.Groups["TitleImage"].Value);
                        var image = createImage(img);
                        string info = Regex.Replace(parsedSeries.Groups["Info"].Value.Replace("<br>", "\n"), "<.*?>", "");
                        var referenseTofile = parsedSeries.Groups["ReferensToFiles"].Value;
                        var modelTemp = new SerialModel(new SeriaInfo( "http://www.ex.ua" + referenseTofile.Remove(referenseTofile.Length - 1), parsedSeries.Groups["Name"].Value,
                            parsedSeries.Groups["Size"].Value, image, info), subscribeManager, listFileParser);
                        models.Add(modelTemp);
                    }

                }
                catch (Exception e)
                {
                    // ignored
                }
            }

            return models;
        }
Exemplo n.º 15
0
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="RecieveData">接收到的流</param>
        /// <returns></returns>
        public bool DeserialOperate(byte[] RecieveData, bool bFlag)
        {
            int       ComandTime = 0;
            ArrayList Arraylist  = null;
            string    strContent = string.Empty;;

            byte[]        fs1     = null;
            int           intRows = 0;
            SqlConnection conn    = new SqlConnection();
            string        strErr  = string.Empty;

            SqlParameter[] parameters = null;
            string         strsql     = string.Empty;

            if (bFlag)
            {
                // strsql = "server=.;database=KJ128N;uid=sa;pwd=sa;Timeout=5";
                strsql = GetConfigValue("ConnectionString").Trim();
            }
            else
            {
                // strsql = "server=.;database=KJ128NBackUp;uid=sa;pwd=sa;Timeout=5";
                strsql = GetConfigValue("ConnectionString").Trim();
            }
            File.WriteAllText(Application.StartupPath + "\\Conn.dw", strsql, Encoding.Default);

            string err = string.Empty;

            err = "";
            int        intFlag         = 0;
            bool       Flag            = false;
            string     strDeserialPath = Application.StartupPath.ToString() + "\\DesialsData.dat";
            FileStream fs = File.Create(strDeserialPath);

            fs.Write(RecieveData, 2, RecieveData.Length - 2);
            fs.Close();
            fs.Dispose();

            Stream          stream = new FileStream(strDeserialPath, FileMode.Open);
            BinaryFormatter bf     = new BinaryFormatter();


            SerialModel sbc = (SerialModel)bf.Deserialize(stream);

            stream.Close();
            if (sbc.parameter != null)
            {
                parameters = new SqlParameter[sbc.parameter.Length];
                for (int i = 0; i < sbc.parameter.Length; i++)
                {
                    parameters[i] = new SqlParameter();
                    parameters[i].ParameterName = sbc.parameter[i].ParameterName;
                    parameters[i].SqlDbType     = sbc.parameter[i].ParameterType;
                    parameters[i].Size          = sbc.parameter[i].intLongth;
                    parameters[i].Value         = sbc.parameter[i].objValue;
                }
            }
            if (sbc.ComandTime != 0)
            {
                ComandTime = sbc.ComandTime;
            }
            if (sbc.Arraylist != null)
            {
                Arraylist = sbc.Arraylist;
            }
            if (sbc.fs != null)
            {
                fs1 = sbc.fs;
            }
            if (sbc.strContent != null)
            {
                strContent = sbc.strContent;
            }

            New_DBAcess     NDBA;
            New_DbHelperSQL NDH;

            switch (sbc.FuntionName)
            {
            case "ACCESS_ExecuteSql1":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters);
                break;

            case "ACCESS_ExecuteSql2":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "ACCESS_ExecuteSql3":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters, conn);
                break;

            case "ACCESS_ExecuteSql4":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.strSql, conn);
                break;

            case "ACCESS_ExecuteSql5":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.strSql);
                break;

            case "ACCESS_ExecuteSql6":
                NDBA = new New_DBAcess();
                NDBA.ExistsSql(sbc.strSql);
                break;

            case "Helper_ExecuteSql1":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureByInt64(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "Helper_ExecuteSql2":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureByInt(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "Helper_ExecuteSql3":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureByInt(sbc.RestoryProcedureName, out strErr);
                break;

            case "Helper_ExecuteSql4":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureReturnInt(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "Helper_ExecuteSql5":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSql(sbc.strSql);
                break;

            case "Helper_ExecuteSql6":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlByTime(sbc.strSql, ComandTime);
                break;

            case "Helper_ExecuteSql7":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlTran(Arraylist);
                break;

            case "Helper_ExecuteSql8":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSql(sbc.strSql, sbc.strContent);
                break;

            case "Helper_ExecuteSql9":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlGet(sbc.strSql, sbc.strContent);
                break;

            case "Helper_ExecuteSql10":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlInsertImg(sbc.strSql, fs1);
                break;

            case "Helper_ExecuteSql11":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSql(sbc.strSql, parameters);
                break;

            case "Helper_ExecuteSql12":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedure(sbc.RestoryProcedureName, parameters, out intRows);
                break;

            case "Helper_ExecuteSql13":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedure(sbc.RestoryProcedureName);
                break;

            default:
                break;
            }

            if (intFlag != -1)
            {
                Flag = true;
            }
            else
            {
                Flag = false;
            }

            if (File.Exists(Application.StartupPath + "\\Conn.dw"))
            {
                File.Delete(Application.StartupPath + "\\Conn.dw");
            }
            return(Flag);
        }
Exemplo n.º 16
0
#pragma warning restore 649

        public SerialViewModel(SerialModel serialModel)
        {
            this.serialModel = serialModel;
        }
Exemplo n.º 17
0
 public static Boolean SetSerial(PortModel PE, SerialModel SE)
 {
     return(true);
 }