예제 #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();
        }
예제 #2
0
        public LeaderboardManager()
        {
            var filepath = @"leaderboard.xml";

            // Handle the xml stuff pls ty
            _xmlHandler = new XML_Handler <Leaderboard>(filepath);

            // Check if the file exists or not
            if (!File.Exists(filepath))
            {
                // If not, create one and put the leaderboard in it
                _leaderboard = new Leaderboard();
                _xmlHandler.Serialise(_leaderboard);
            }
            else
            {
                // if there is, get the leaderboard
                _leaderboard = _xmlHandler.Deserialise();
            }
        }
        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);
        }
        //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();
        }