コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: saladjay/iAMPUpdate
        private MainViewModel()
        {
            Data = new DataModel();
            //Data.PropertyChanged += Data_PropertyChanged;
            CoreData                   = TCoreData.GetInstance();
            RadioBtnCommand            = new RelayCommand <object>(RadioPGType2Click);
            OpenFileCommand            = new RelayCommand(OpenFile);
            TestSerialCommand          = new RelayCommand(TestSerialPort, CanSendCMD);
            ConnectSerialCommand       = new RelayCommand(ConnectSerialPort);
            GetSerialPortNameCommand   = new RelayCommand(GetSerialPortNameExcute);
            ChangePasswordCommand      = new RelayCommand(ChangePassword, CanSendCMD);
            StartUpdateFirmwareCommand = new RelayCommand(StartUpdateFirmwareExcute, CanSendupdateFirmware);
            SavePresetCommand          = new RelayCommand(SavePresetExcute, CanSendCMD);
            SerialPortNames            = new ObservableCollection <string>();
            MySerialPort.DataReceived += MySerialPort_DataReceived;


            //MyIoSocketPort = IoSocketProces.shareIoSocket();
            //IoSocketProces.ioProc.ReceiveByteEvent += new IoSocketProces.socketReceive(OnReceiveByte);
            //IoSocketProces.ioProc.SockConnectEvent += new IoSocketProces.socketConnected(socketConnected);
            //IoSocketProces.ioProc.showSockLog = true;
            IPScanCommand = new RelayCommand(IPScan);

            ConnectionTypeSwitchCommand = new RelayCommand <object>(ConnectionTypeSwitch);

            MyNetPort = NetCilent.shareCilent();
            MyNetPort.initSocket();
            MyNetPort.onConnectedEvent  += MyNetPort_onConnectedEvent;
            MyNetPort.onDisconnectEvent += MyNetPort_onDisconnectEvent;
            MyNetPort.ReceiveByteEvent  += MyNetPort_ReceiveByteEvent;
            Thread Converter = new Thread(new ThreadStart(ConverterLoop));

            Converter.IsBackground = true;
            Converter.Start();
            ConnectionTimer.AutoReset = false;
            ConnectionTimer.Elapsed  += ConnectionTimer_Elapsed;
            nTimer.Elapsed           += NTimer_Elapsed;
            Password = "******";
            for (int i = 0; i < 16; i++)
            {
                Data.PresetCollection.Add(i.ToString());
            }
            //manage
            CreateSinglePresetFileCommand   = new iAMPUpdate.RelayCommand(CreateSinglePreserFile, CanCreateSinglePresetFile);
            UploadSelectedPresetFileCommand = new RelayCommand(UploadSelectedPresetFile);
            ResetPresetsCommand             = new RelayCommand(ResetPresets, CanCreateSinglePresetFile);
            SavePresetsFileCommand          = new RelayCommand(SavePresetsFile);
            UploadPresetsToDeviceCommand    = new RelayCommand(UploadPresetsToDevice);
            //Additional function
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "initialfile.xml"))
            {
                XmlDocument initialXml = new XmlDocument();
                initialXml.Load(AppDomain.CurrentDomain.BaseDirectory + "initialfile.xml");
                XmlElement root = (XmlElement)initialXml.SelectSingleNode("Software");
                if (root != null && root.HasChildNodes)
                {
                    foreach (XmlNode item in root.ChildNodes)
                    {
                        XmlElement First = (XmlElement)item.FirstChild;
                        if (First.InnerText == "true")
                        {
                            Data.AdditionalFunction = true;
                        }
                        else
                        {
                            Data.AdditionalFunction = false;
                        }
                    }
                }
            }
            else
            {
                XmlDocument InitialXml  = new XmlDocument();
                XmlNode     Declaration = InitialXml.CreateXmlDeclaration("1.0", "utf-8", "yes");
                InitialXml.AppendChild(Declaration);
                XmlNode Software = InitialXml.CreateElement("Software");
                InitialXml.AppendChild(Software);

                XmlElement AdditionalFunction = InitialXml.CreateElement("student");

                XmlElement studentName = InitialXml.CreateElement("AdditionalFunction");
                studentName.AppendChild(InitialXml.CreateTextNode("true"));
                AdditionalFunction.AppendChild(studentName);

                Software.AppendChild(AdditionalFunction);

                InitialXml.Save(AppDomain.CurrentDomain.BaseDirectory + "initialfile.xml");
            }
        }
コード例 #2
0
 public ManagePresetViewModel()
 {
     CreateSinglePresetFileCommand = new iAMPUpdate.RelayCommand(CreateSinglePreserFile, CanCreateSinglePresetFile);
 }