コード例 #1
0
        protected override void OnDeactivate(bool close)
        {
            if (FormatVariables_ObservableCollection != null)
            {
                //Read textboxes variables and values and write save them to the Settings.xml file

                XML_Handler XML_FileHandler = new XML_Handler();

                String[] Pointer_StringArray         = new String[Pointer_ObservableCollection.Count];
                String[] TransferReq_StringArray     = new String[TransferReq_ObservableCollection.Count];
                String[] ParValid_StringArray        = new String[ParValid_ObservableCollection.Count];
                String[] ParameterToSend_StringArray = new String[ParameterToSend_ObservableCollection.Count];

                String[] FormatVariables_StringArray = new String[FormatVariables_ObservableCollection.Count];
                String[] FormatValues_StringArray    = new String[FormatValues_ObservableCollection.Count];

                int i = 0;
                foreach (Parameters par in FormatVariables_ObservableCollection)
                {
                    FormatVariables_StringArray[i] = par.Name;
                    i++;
                }

                i = 0;
                foreach (Parameters par in FormatValues_ObservableCollection)
                {
                    FormatValues_StringArray[i] = par.Name;
                    i++;
                }

                i = 0;
                foreach (Parameters par in Pointer_ObservableCollection)
                {
                    Pointer_StringArray[i] = par.Name;
                    i++;
                }

                i = 0;
                foreach (Parameters par in TransferReq_ObservableCollection)
                {
                    TransferReq_StringArray[i] = par.Name;
                    i++;
                }

                i = 0;
                foreach (Parameters par in ParValid_ObservableCollection)
                {
                    ParValid_StringArray[i] = par.Name;
                    i++;
                }

                i = 0;
                foreach (Parameters par in ParameterToSend_ObservableCollection)
                {
                    ParameterToSend_StringArray[i] = par.Name;
                    i++;
                }

                // Save Changes to the Settings.xml

                //XML_FileHandler.SaveParameters(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, FormatPar_Struc_ToFormatParViewModel.path, FormatPar_Struc_ToFormatParViewModel.PointerStringElementName, "", FormatPar_Struc_ToFormatParViewModel.PointerStringAttributeName, Pointer_StringArray);
                //XML_FileHandler.SaveParameters(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, FormatPar_Struc_ToFormatParViewModel.path, FormatPar_Struc_ToFormatParViewModel.TransferReqElementName, "", FormatPar_Struc_ToFormatParViewModel.TransferReqAttributeName, TransferReq_StringArray);
                //XML_FileHandler.SaveParameters(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, FormatPar_Struc_ToFormatParViewModel.path, FormatPar_Struc_ToFormatParViewModel.ParValidElementName, "", FormatPar_Struc_ToFormatParViewModel.ParValidAttributeName, ParValid_StringArray);
                //XML_FileHandler.SaveParameters(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, FormatPar_Struc_ToFormatParViewModel.path, FormatPar_Struc_ToFormatParViewModel.ParameterToSendElementName, "", FormatPar_Struc_ToFormatParViewModel.ParValidAttributeName, ParameterToSend_StringArray);
                XML_FileHandler.SaveParameters(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, FormatPar_Struc_ToFormatParViewModel.path, FormatPar_Struc_ToFormatParViewModel.FormatElementName, FormatPar_Struc_ToFormatParViewModel.FormatParElementName, FormatPar_Struc_ToFormatParViewModel.FormatParAttributeName, FormatVariables_StringArray);
                XML_FileHandler.SaveParameters(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, FormatPar_Struc_ToFormatParViewModel.path, FormatPar_Struc_ToFormatParViewModel.FormatElementName, FormatPar_Struc_ToFormatParViewModel.FormatParElementName, FormatPar_Struc_ToFormatParViewModel.FormatParAttributeValue, FormatValues_StringArray);

                //clear lists and collections
                _list_FormatVariables.Clear();
                _list_FormatValues.Clear();
                _list_PointerVariable.Clear();
                _list_TransferReq.Clear();
                _list_ParValid.Clear();
                _list_ParameterToSend.Clear();

                FormatVariables_ObservableCollection.Clear();
                FormatValues_ObservableCollection.Clear();
                Pointer_ObservableCollection.Clear();
                TransferReq_ObservableCollection.Clear();
                ParValid_ObservableCollection.Clear();
                ParameterToSend_ObservableCollection.Clear();

                //Background worker detach events
                _transferParameters_Worker.DoWork             -= DoWork_Transfer;
                _transferParameters_Worker.RunWorkerCompleted -= WorkCompleted_Transfer;
                _transferParameters_Worker.ProgressChanged    -= ProgressChanged_Transfer;
            }

            _eventAggregator.Unsubscribe(this);
            base.OnDeactivate(close);
        }
コード例 #2
0
        //Overides
        #region Overides
        protected override void OnActivate()
        {
            // Read parent values on activation, after it will be handled by messaging
            MainViewModel ParentViewModel = (MainViewModel)this.Parent;

            _IP_Address_ParTranViewModel = ParentViewModel.IP_Address;
            _Port_ParTransViewModel      = ParentViewModel.Port;

            //Background worker attach events
            _transferParameters_Worker.DoWork             += DoWork_Transfer;
            _transferParameters_Worker.RunWorkerCompleted += WorkCompleted_Transfer;
            _transferParameters_Worker.ProgressChanged    += ProgressChanged_Transfer;

            //subscribe to the event messages
            _eventAggregator.Subscribe(this);

            XML_Handler XML_FileHandler = new XML_Handler();

            FormatPar_Struc_ToFormatParViewModel.path = System.IO.Directory.GetCurrentDirectory();
            FormatPar_Struc_ToFormatParViewModel.NumberOfFormatVar             = _conHandler.ReadCommSetting("NumberOfFormatVar");
            FormatPar_Struc_ToFormatParViewModel.SettingsFileName              = _conHandler.ReadCommSetting("SettingsFileName");
            FormatPar_Struc_ToFormatParViewModel.RootElementName               = _conHandler.ReadCommSetting("RootElementName");
            FormatPar_Struc_ToFormatParViewModel.NumFormatVarElementName       = _conHandler.ReadCommSetting("NumFormatVarElementName");
            FormatPar_Struc_ToFormatParViewModel.NumForVarAttributeName        = _conHandler.ReadCommSetting("NumForVarAttributeName");
            FormatPar_Struc_ToFormatParViewModel.FormatElementName             = _conHandler.ReadCommSetting("FormatElementName");
            FormatPar_Struc_ToFormatParViewModel.FormatParElementName          = _conHandler.ReadCommSetting("FormatParElementName");
            FormatPar_Struc_ToFormatParViewModel.FormatParAttributeName        = _conHandler.ReadCommSetting("FormatParAttributeName");
            FormatPar_Struc_ToFormatParViewModel.FormatParAttributeValue       = _conHandler.ReadCommSetting("FormatParAttributeValue");
            FormatPar_Struc_ToFormatParViewModel.PointerStringElementName      = _conHandler.ReadCommSetting("PointerStringElementName");
            FormatPar_Struc_ToFormatParViewModel.PointerStringAttributeName    = _conHandler.ReadCommSetting("PointerStringAttributeName");
            FormatPar_Struc_ToFormatParViewModel.PointerStringAttributeValue   = _conHandler.ReadCommSetting("PointerStringAttributeValue");
            FormatPar_Struc_ToFormatParViewModel.TransferReqElementName        = _conHandler.ReadCommSetting("TransferReqElementName");
            FormatPar_Struc_ToFormatParViewModel.TransferReqAttributeName      = _conHandler.ReadCommSetting("TransferReqAttributeName");
            FormatPar_Struc_ToFormatParViewModel.TransferReqAttributeValue     = _conHandler.ReadCommSetting("TransferReqAttributeValue");
            FormatPar_Struc_ToFormatParViewModel.ParValidElementName           = _conHandler.ReadCommSetting("ParValidElementName");
            FormatPar_Struc_ToFormatParViewModel.ParValidAttributeName         = _conHandler.ReadCommSetting("ParValidAttributeName");
            FormatPar_Struc_ToFormatParViewModel.ParValidAttributeValue        = _conHandler.ReadCommSetting("ParValidAttributeValue");
            FormatPar_Struc_ToFormatParViewModel.ParameterToSendElementName    = _conHandler.ReadCommSetting("ParameterToSendElementName");
            FormatPar_Struc_ToFormatParViewModel.ParameterToSendAttributeName  = _conHandler.ReadCommSetting("ParameterToSendAttributeName");
            FormatPar_Struc_ToFormatParViewModel.ParameterToSendAttributeValue = _conHandler.ReadCommSetting("ParameterToSendAttributeValue");

            //create Settings file if it doesn't exists
            if (!File.Exists(FormatPar_Struc_ToFormatParViewModel.SettingsFileName))
            {
                XML_FileHandler.Create_XMLfileStruc(FormatPar_Struc_ToFormatParViewModel);
            }

            _percentage       = 0;
            _percentageString = _percentage.ToString() + "%";

            //read settings.xml file
            _list_FormatVariables = XML_FileHandler.ReturnListOfXMLAttributes(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, _path, FormatPar_Struc_ToFormatParViewModel.FormatElementName, FormatPar_Struc_ToFormatParViewModel.FormatParElementName, FormatPar_Struc_ToFormatParViewModel.FormatParAttributeName);
            _list_FormatValues    = XML_FileHandler.ReturnListOfXMLAttributes(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, _path, FormatPar_Struc_ToFormatParViewModel.FormatElementName, FormatPar_Struc_ToFormatParViewModel.FormatParElementName, FormatPar_Struc_ToFormatParViewModel.FormatParAttributeValue);
            _list_PointerVariable = XML_FileHandler.ReturnListOfXMLAttributes(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, _path, FormatPar_Struc_ToFormatParViewModel.PointerStringElementName, "", FormatPar_Struc_ToFormatParViewModel.PointerStringAttributeName);
            _list_TransferReq     = XML_FileHandler.ReturnListOfXMLAttributes(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, _path, FormatPar_Struc_ToFormatParViewModel.TransferReqElementName, "", FormatPar_Struc_ToFormatParViewModel.TransferReqAttributeName);
            _list_ParValid        = XML_FileHandler.ReturnListOfXMLAttributes(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, _path, FormatPar_Struc_ToFormatParViewModel.ParValidElementName, "", FormatPar_Struc_ToFormatParViewModel.ParValidAttributeName);
            _list_ParameterToSend = XML_FileHandler.ReturnListOfXMLAttributes(FormatPar_Struc_ToFormatParViewModel.SettingsFileName, _path, FormatPar_Struc_ToFormatParViewModel.ParameterToSendElementName, "", FormatPar_Struc_ToFormatParViewModel.ParameterToSendAttributeName);

            //add strings from the lists in the collections
            foreach (String listItem in _list_FormatVariables)
            {
                Parameters par = new Parameters {
                    Name = listItem
                };
                FormatVariables_ObservableCollection.Add(par);
            }
            foreach (String listItem in _list_FormatValues)
            {
                Parameters par = new Parameters {
                    Name = listItem
                };
                FormatValues_ObservableCollection.Add(par);
            }
            foreach (String listItem in _list_PointerVariable)
            {
                Parameters par = new Parameters {
                    Name = listItem
                };
                Pointer_ObservableCollection.Add(par);
            }
            foreach (String listItem in _list_TransferReq)
            {
                Parameters par = new Parameters {
                    Name = listItem
                };
                TransferReq_ObservableCollection.Add(par);
            }
            foreach (String listItem in _list_ParValid)
            {
                Parameters par = new Parameters {
                    Name = listItem
                };
                ParValid_ObservableCollection.Add(par);
            }
            foreach (String listItem in _list_ParameterToSend)
            {
                Parameters par = new Parameters {
                    Name = listItem
                };
                ParameterToSend_ObservableCollection.Add(par);
            }

            base.OnActivate();
        }