Пример #1
0
        //Overides
        #region overides
        protected override void OnInitialize()
        {
            _eventAggregator.Subscribe(this);
            Items.Add(I_ReadWriteTab_ViewModel);
            Items.Add(I_FormatParameterTransfer_ViewModel);

            CheckConnection_Worker.DoWork             += DoWork_CheckConnection;
            CheckConnection_Worker.RunWorkerCompleted += WorkCompleted_CheckConnection;
            CheckConnection_Worker.ProgressChanged    += ProgressChanged_CheckConnections;

            XML_Handler XML_FileHandler = new XML_Handler();

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

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

            base.OnInitialize();
        }
        //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();
        }