Esempio n. 1
0
        protected override void btnNext_Click(object sender, EventArgs e)
        {
            // Choose next form and do the job
            if (radioCreate.Checked)
            {
                nextForm = new OptimizationParametersForm(this);
            }
            else if (radioLoad.Checked)
            {
                // TODO: Should we check input and provide detailed localized info on the error
                // or just let corresponding exception be thrown and show its message to the user?
                try
                {
                    ModelStorage.Instance.Model = XmlIdentificationModelProvider.Open(textModelFile.Text);
                    nextForm = new OptimizationParametersForm(this);
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.ShowError(ex.Message);
                    return;
                }
            }
            else
            {
                return;
            }

            // Let's have this for now - later will decide based on the type and contents of the model file
            //nextForm = new OptimizationParametersForm(this);

            // Now call base implementation - it is responsible for forms rotation
            base.btnNext_Click(sender, e);
        }
Esempio n. 2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (dialogSaveModel.ShowDialog() == DialogResult.OK)
            {
                int filterIndex = dialogSaveModel.FilterIndex;
                try
                {
                    switch (filterIndex)
                    {
                    // OPT model
                    case 2:
                        Model optModel = ModelsConverter.ConvertToOptimization(ModelStorage.Instance.Model);
                        XmlModelProvider.Save(optModel, dialogSaveModel.FileName);
                        break;

                    // OPT.ID model
                    case 1:
                    default:
                        XmlIdentificationModelProvider.Save(ModelStorage.Instance.Model, dialogSaveModel.FileName);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.ShowError(ex.Message);
                }

                dialogSaveModel.FileName = string.Empty;
            }
        }
Esempio n. 3
0
        private void WriteExchangeFile(string exchangeFilePath)
        {
            XmlIdentificationModelProvider.Save(ModelStorage.Instance.Model, exchangeFilePath);

            while (!File.Exists(exchangeFilePath))
            {
                Thread.Sleep(500);
            }
        }
Esempio n. 4
0
        public void Save()
        {
            if (model == null)
            {
                throw new InvalidOperationException("Model is null");
            }

            XmlIdentificationModelProvider.Save(model, modelFile);
        }
Esempio n. 5
0
        public ModelCalculator(string modelFilePath)
        {
            if (string.IsNullOrEmpty(modelFilePath))
            {
                throw new ArgumentNullException("modelFilePath");
            }

            model     = XmlIdentificationModelProvider.Open(modelFilePath);
            modelFile = modelFilePath;
        }
Esempio n. 6
0
        public void ProcessModel(object data)
        {
            CancellationToken cancellationToken;

            if (data == null)
            {
                cancellationToken = new CancellationToken(false);
            }
            else
            {
                cancellationToken = (CancellationToken)data;
            }

            if (cancellationToken.IsCancellationRequested)
            {
                OnProcessingComplete(new EventArgs());
                return;
            }

            model = XmlIdentificationModelProvider.Open(optFile);
            if (cancellationToken.IsCancellationRequested)
            {
                OnProcessingComplete(new EventArgs());
                return;
            }

            int maxProgress = model.IdentificationExperiments.Count;

            OnProgressChanged(new ProgressChangedEventArgs(0, maxProgress, 0, "Initialized"));

            int exp = 0;

            foreach (IdentificationExperiment experiment in model.IdentificationExperiments.Values)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                ProcessExperiment(experiment);
                OnProgressChanged(new ProgressChangedEventArgs(0, maxProgress, ++exp, "Processed experiment #" + experiment.Number.ToString()));
            }

            if (cancellationToken.IsCancellationRequested)
            {
                OnProcessingComplete(new EventArgs());
                return;
            }

            XmlIdentificationModelProvider.Save(model, optFile);

            OnProcessingComplete(new EventArgs());
        }
Esempio n. 7
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (dialogSaveModel.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    XmlIdentificationModelProvider.Save(ModelStorage.Instance.Model, dialogSaveModel.FileName);
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.ShowError(ex.Message);
                }

                dialogSaveModel.FileName = string.Empty;
            }
        }
Esempio n. 8
0
        private void ExternalApp_Exited(object sender, EventArgs e)
        {
            try
            {
                string exchangeFilePath = textExchangeFilePath.Text.Trim();

                // Update model
                if (File.Exists(exchangeFilePath))
                {
                    ModelStorage.Instance.Model = XmlIdentificationModelProvider.Open(exchangeFilePath);
                    ResidualFinder.CalculateAdequacyCriteriaValues(ModelStorage.Instance.Model);
                }

                // Invoke form's method to handle external app exit
                // This is needed because ExternalApp_Exited is invoked in another
                // thread (not in UI thread)
                Invoke(new Action(ExternalAppFinished));
            }
            catch (Exception ex)
            {
                MessageBoxHelper.ShowError(ex.Message);
            }
        }