Ejemplo n.º 1
0
               fs.Close();
            }
         }
      }

      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 NewSystemPreferences)
               {
                  NewSystemPreferences newSysPrefs = (NewSystemPreferences)obj;
                  newSysPrefs.SetObjectData(newSysPrefs.SerializationInfo, newSysPrefs.StreamingContext);
                  if (!DryingGasCatalog.GetInstance().IsInCatalog(newSysPrefs.DryingGasName))
                  {
                     newSysPrefs.DryingGasName = DryingGasCatalog.GetInstance().GetDefaultDryingGas().Name;
                  }
                  if (!DryingMaterialCatalog.GetInstance().IsInCatalog(newSysPrefs.DryingMaterialName))
                  {
                     newSysPrefs.DryingMaterialName = DryingMaterialCatalog.GetInstance().GetDefaultDryingMaterial().Name;
                  }
                  mainForm.NewSystemPrefs = newSysPrefs;
               }
            }
         }
         catch (Exception)
         {
            NewSystemPreferences newSysPrefs = new NewSystemPreferences();
            mainForm.NewSystemPrefs = newSysPrefs;
         }
         finally 
Ejemplo n.º 2
0
        public void PersistAppPreferences(MainForm mainForm)
        {
            string fileName = ApplicationInformation.ApplicationStartupPath + MainForm.APP_PREFS_XML;

            try {
                //UIPreferences uiPrefs = new UIPreferences(mainForm.Location, mainForm.Size, mainForm.WindowState, mainForm.ToolboxVisible, mainForm.ToolboxLocation);
                UIPreferences uiPrefs = new UIPreferences(mainForm);
                PersistFile(fileName, uiPrefs);
            }
            catch (Exception e) {
                string message = e.ToString();
                MessageBox.Show(message, "Error Saving Application Preferences", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 3
0
        public void PersistAppPreferences(MainForm mainForm)
        {
            //string fileName = mainForm.ExePathName + MainForm.APP_PREFS_XML;
            string fileName = ApplicationInformation.ApplicationStartupPath + MainForm.APP_PREFS_XML;
            //string fileName = mainForm.ExePathName + MainForm.APP_PREFS_DAT;
            FileStream fs = null;

            try {
                if (File.Exists(fileName))
                {
                    fs = new FileStream(fileName, FileMode.Open);
                }
                else
                {
                    fs = new FileStream(fileName, FileMode.Create);
                }

                //ArrayList toSerializeItems = new ArrayList();

                //UIPreferences uiPrefs = new UIPreferences(mainForm.Location, mainForm.Size, mainForm.WindowState, mainForm.ToolboxVisible, mainForm.ToolboxLocation);
                UIPreferences uiPrefs = new UIPreferences(mainForm);

                //toSerializeItems.Add(uiPrefs);
                //toSerializeItems.Add(mainForm.NewProcessSettings);
                //toSerializeItems.Add(mainForm.ApplicationPrefs);

                SoapFormatter serializer = new SoapFormatter();

                //BinaryFormatter serializer = new BinaryFormatter();
                serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;

                //serializer.Serialize(fs, toSerializeItems);
                serializer.Serialize(fs, uiPrefs);
            }
            catch (Exception e) {
                string message = e.ToString();
                MessageBox.Show(message, "Error Saving Application Preferences", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally {
                if (fs != null)
                {
                    fs.Flush();
                    fs.Close();
                }
            }
        }