Ejemplo n.º 1
0
 public void RestorePreferences(MainForm mainForm)
 {
     SetObjectData();
     mainForm.Location           = mainFormLocation;
     mainForm.Size               = mainFormSize;
     mainForm.WindowState        = mainFormWindowState;
     mainForm.ToolboxVisible     = toolboxVisible;
     mainForm.NewProcessSettings = newProcessSettings;
     mainForm.ApplicationPrefs   = appPrefs;
     appPrefs.InitializeCurrentUnitSystem();
     mainForm.FlowsheetPrefs = flowsheetPrefs;
 }
Ejemplo n.º 2
0
        public void UnpersistAppPreferences(MainForm mainForm)
        {
            string fileName = mainForm.ExePathName + MainForm.APP_PREFS;
            Stream stream   = null;

            try
            {
                stream = new FileStream(fileName, FileMode.Open);
                SoapFormatter serializer = new SoapFormatter();
                serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;
                ArrayList items = (ArrayList)serializer.Deserialize(stream);

                IEnumerator e = items.GetEnumerator();
                while (e.MoveNext())
                {
                    object obj = e.Current;

                    if (obj is UIPreferences)
                    {
                        UIPreferences uiPrefs = (UIPreferences)obj;
                        uiPrefs.SetObjectData(uiPrefs.SerializationInfo, uiPrefs.StreamingContext);
                        mainForm.Location        = uiPrefs.MainFormLocation;
                        mainForm.Size            = uiPrefs.MainFormSize;
                        mainForm.WindowState     = uiPrefs.MainFormWindowState;
                        mainForm.ToolboxVisible  = uiPrefs.ToolboxVisible;
                        mainForm.ToolboxLocation = uiPrefs.ToolboxLocation;
                    }
                    else if (obj is NewProcessSettings)
                    {
                        NewProcessSettings newProcessSettings = (NewProcessSettings)obj;
                        newProcessSettings.SetObjectData(newProcessSettings.SerializationInfo, newProcessSettings.StreamingContext);
                        if (!DryingGasCatalog.GetInstance().IsInCatalog(newProcessSettings.DryingGasName))
                        {
                            newProcessSettings.DryingGasName = DryingGasCatalog.GetInstance().GetDefaultDryingGas().Name;
                        }
                        if (!DryingMaterialCatalog.GetInstance().IsInCatalog(newProcessSettings.DryingMaterialName))
                        {
                            newProcessSettings.DryingMaterialName = DryingMaterialCatalog.GetInstance().GetDefaultDryingMaterial().Name;
                        }

                        //
                        if (newProcessSettings.DryingGasName == null || newProcessSettings.DryingGasName.Trim().Equals(""))
                        {
                            newProcessSettings.DryingGasName = "Air";
                        }
                        mainForm.NewProcessSettings = newProcessSettings;
                    }
                    else if (obj is ApplicationPreferences)
                    {
                        ApplicationPreferences appPrefs = (ApplicationPreferences)obj;
                        appPrefs.SetObjectData(appPrefs.SerializationInfo, appPrefs.StreamingContext);
                        appPrefs.InitializeCurrentUnitSystem();
                        mainForm.ApplicationPrefs = appPrefs;
                    }
                }
            }
            catch (Exception)
            {
                NewProcessSettings newProcessSettings = new NewProcessSettings();
                mainForm.NewProcessSettings = newProcessSettings;
                ApplicationPreferences appPrefs = new ApplicationPreferences();
                mainForm.ApplicationPrefs = appPrefs;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }