Ejemplo n.º 1
0
 public Flowsheet UnpersistFlowsheet(NewSystemPreferences newSystemPrefs, string fileName)
 {
    Flowsheet flowsheet = null;
    Stream stream = null;
    try
    {
       stream = new FileStream(fileName, FileMode.Open);
       SoapFormatter serializer = new SoapFormatter();
       serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;
       ArrayList items = (ArrayList)serializer.Deserialize(stream);
       flowsheet = this.SetFlowsheetContent(newSystemPrefs, items);
       if (flowsheet != null)
          flowsheet.Text = fileName;
    }
    catch (Exception e) 
    {
       string message = e.ToString(); 
       MessageBox.Show(message, "Open Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    finally 
    {
       stream.Close();
    }
    return flowsheet;
 }
Ejemplo n.º 2
0
        public Flowsheet(NewSystemPreferences newSystemPrefs, EvaporationAndDryingSystem system)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.newSystemPrefs = newSystemPrefs;
            UnitSystemCatalog catalog = UnitSystemService.GetInstance().GetUnitSystemCatalog();
            UnitSystem        us      = catalog.Get("SI-2");

            UnitSystemService.GetInstance().CurrentUnitSystem = us;
            this.currentUnitSystemName = us.Name;

            this.MultipleSelection = false;
            this.Activity          = FlowsheetActivity.Default;

            if (system == null)
            {
                DryingGas dg = DryingGasCatalog.GetInstance().GetDryingGas(newSystemPrefs.DryingGasName);
                if (dg == null)
                {
                    dg = DryingGasCatalog.GetInstance().GetDryingGas("Air");
                }

                DryingMaterial dm = DryingMaterialCatalog.GetInstance().GetDryingMaterial(newSystemPrefs.DryingMaterialName);
                if (dm == null)
                {
                    dm = DryingMaterialCatalog.GetInstance().GetDryingMaterial("Generic Material");
                }

                this.evapAndDryingSystem = new EvaporationAndDryingSystem("New System", dm, dg);
            }
            else
            {
                this.evapAndDryingSystem = system;
            }

            this.evapAndDryingSystem.SystemChanged      += new SystemChangedEventHandler(evapAndDryingSystem_SystemChanged);
            this.evapAndDryingSystem.CalculationStarted += new CalculationStartedEventHandler(evapAndDryingSystem_CalculationStarted);
            this.evapAndDryingSystem.CalculationEnded   += new CalculationEndedEventHandler(evapAndDryingSystem_CalculationEnded);

            this.connectionManager = new ConnectionManager(this);
            this.customEditor      = new ProsimoUI.CustomEditor.CustomEditor(this);
            this.streamManager     = new StreamManager(this);
            this.unitOpManager     = new UnitOpManager(this);
            UI ui = new UI();

            this.BackColor     = ui.FLOWSHEET_COLOR;
            this.NumericFormat = NumericFormat.FixedPoint;
            this.DecimalPlaces = "3";
            this.Version       = new FlowsheetVersion();

            this.KeyDown += new KeyEventHandler(Flowsheet_KeyDown);
            this.KeyUp   += new KeyEventHandler(Flowsheet_KeyUp);
            UnitSystemService.GetInstance().CurrentUnitSystemChanged += new CurrentUnitSystemChangedEventHandler(Flowsheet_CurrentUnitSystemChanged);
            this.IsDirty = false;
        }
Ejemplo n.º 3
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.º 4
0
        public NewSystemPreferencesForm(NewSystemPreferences newSysPrefs)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.newSysPrefs = newSysPrefs;

            this.dryingGasesControl.ListViewGases.MultiSelect         = false;
            this.dryingMaterialsControl.ListViewMaterials.MultiSelect = false;

            this.dryingGasesControl.SelectDryingGas(this.newSysPrefs.DryingGasName);
            this.dryingMaterialsControl.SelectDryingMaterial(this.newSysPrefs.DryingMaterialName);

            this.textBoxDryingGas.Text      = this.newSysPrefs.DryingGasName;
            this.textBoxDryingMaterial.Text = this.newSysPrefs.DryingMaterialName;
        }
Ejemplo n.º 5
0
      private Flowsheet SetFlowsheetContent(NewSystemPreferences newSystemPrefs, ArrayList items)
      {
         Flowsheet flowsheet = null;
         IEnumerator e = items.GetEnumerator();
         while (e.MoveNext())
         {
            object obj = e.Current;
            
            if (obj is EvaporationAndDryingSystem)
            {
               EvaporationAndDryingSystem persisted = (EvaporationAndDryingSystem)obj;
               persisted.SetObjectData();
               flowsheet = new Flowsheet(newSystemPrefs, persisted);
            }  

            else if (obj is GasStreamControl)
            {
               GasStreamControl persistedCtrl = (GasStreamControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               DryingGasStream stream = flowsheet.EvaporationAndDryingSystem.GetGasStream(solvableName);
               GasStreamControl newCtrl = new GasStreamControl(flowsheet, new Point(0,0), stream); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is MaterialStreamControl)
            {
               MaterialStreamControl persistedCtrl = (MaterialStreamControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               DryingMaterialStream stream = flowsheet.EvaporationAndDryingSystem.GetMaterialStream(solvableName);
               MaterialStreamControl newCtrl = new MaterialStreamControl(flowsheet, new Point(0,0), stream); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is DryerControl)
            {
               DryerControl persistedCtrl = (DryerControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Dryer uo = flowsheet.EvaporationAndDryingSystem.GetDryer(solvableName);
               DryerControl newCtrl = new DryerControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is HeatExchangerControl)
            {
               HeatExchangerControl persistedCtrl = (HeatExchangerControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               HeatExchanger uo = flowsheet.EvaporationAndDryingSystem.GetHeatExchanger(solvableName);
               HeatExchangerControl newCtrl = new HeatExchangerControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is CycloneControl)
            {
               CycloneControl persistedCtrl = (CycloneControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Cyclone uo = flowsheet.EvaporationAndDryingSystem.GetCyclone(solvableName);
               CycloneControl newCtrl = new CycloneControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is EjectorControl)
            {
               EjectorControl persistedCtrl = (EjectorControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Ejector uo = flowsheet.EvaporationAndDryingSystem.GetEjector(solvableName);
               EjectorControl newCtrl = new EjectorControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is WetScrubberControl)
            {
               WetScrubberControl persistedCtrl = (WetScrubberControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               WetScrubber uo = flowsheet.EvaporationAndDryingSystem.GetWetScrubber(solvableName);
               WetScrubberControl newCtrl = new WetScrubberControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is MixerControl)
            {
               MixerControl persistedCtrl = (MixerControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Mixer uo = flowsheet.EvaporationAndDryingSystem.GetMixer(solvableName);
               MixerControl newCtrl = new MixerControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is TeeControl)
            {
               TeeControl persistedCtrl = (TeeControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Tee uo = flowsheet.EvaporationAndDryingSystem.GetTee(solvableName);
               TeeControl newCtrl = new TeeControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is FlashTankControl)
            {
               FlashTankControl persistedCtrl = (FlashTankControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               FlashTank uo = flowsheet.EvaporationAndDryingSystem.GetFlashTank(solvableName);
               FlashTankControl newCtrl = new FlashTankControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is FanControl)
            {
               FanControl persistedCtrl = (FanControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Fan uo = flowsheet.EvaporationAndDryingSystem.GetFan(solvableName);
               FanControl newCtrl = new FanControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is ValveControl)
            {
               ValveControl persistedCtrl = (ValveControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Valve uo = flowsheet.EvaporationAndDryingSystem.GetValve(solvableName);
               ValveControl newCtrl = new ValveControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is BagFilterControl)
            {
               BagFilterControl persistedCtrl = (BagFilterControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               BagFilter uo = flowsheet.EvaporationAndDryingSystem.GetBagFilter(solvableName);
               BagFilterControl newCtrl = new BagFilterControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is AirFilterControl)
            {
               AirFilterControl persistedCtrl = (AirFilterControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               AirFilter uo = flowsheet.EvaporationAndDryingSystem.GetAirFilter(solvableName);
               AirFilterControl newCtrl = new AirFilterControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is CompressorControl)
            {
               CompressorControl persistedCtrl = (CompressorControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Compressor uo = flowsheet.EvaporationAndDryingSystem.GetCompressor(solvableName);
               CompressorControl newCtrl = new CompressorControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is HeaterControl)
            {
               HeaterControl persistedCtrl = (HeaterControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Heater uo = flowsheet.EvaporationAndDryingSystem.GetHeater(solvableName);
               HeaterControl newCtrl = new HeaterControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is CoolerControl)
            {
               CoolerControl persistedCtrl = (CoolerControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Cooler uo = flowsheet.EvaporationAndDryingSystem.GetCooler(solvableName);
               CoolerControl newCtrl = new CoolerControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is ElectrostaticPrecipitatorControl)
            {
               ElectrostaticPrecipitatorControl persistedCtrl = (ElectrostaticPrecipitatorControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               ElectrostaticPrecipitator uo = flowsheet.EvaporationAndDryingSystem.GetElectrostaticPrecipitator(solvableName);
               ElectrostaticPrecipitatorControl newCtrl = new ElectrostaticPrecipitatorControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is PumpControl)
            {
               PumpControl persistedCtrl = (PumpControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Pump uo = flowsheet.EvaporationAndDryingSystem.GetPump(solvableName);
               PumpControl newCtrl = new PumpControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is RecycleControl)
            {
               RecycleControl persistedCtrl = (RecycleControl)obj;
               string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
               Recycle uo = flowsheet.EvaporationAndDryingSystem.GetRecycle(solvableName);
               RecycleControl newCtrl = new RecycleControl(flowsheet, new Point(0,0), uo); 
               newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
               flowsheet.Controls.Add(newCtrl);
            }
            else if (obj is SolvableConnection)
            {
               SolvableConnection persistedDc = (SolvableConnection)obj;
               SolvableConnection dc = new SolvableConnection(flowsheet);
               dc.SetObjectData(persistedDc.SerializationInfo, persistedDc.StreamingContext);
               flowsheet.ConnectionManager.Connections.Add(dc);
            }
            else if (obj is FlowsheetPreferences)
            {
               FlowsheetPreferences flowsheetPrefs = obj as FlowsheetPreferences;
               flowsheetPrefs.SetObjectData(flowsheetPrefs.SerializationInfo, flowsheetPrefs.StreamingContext);
               flowsheet.InitializeCurrentUnitSystem(flowsheetPrefs.CurrentUnitSystemName);
               flowsheet.NumericFormat = flowsheetPrefs.NumericFormat;
               flowsheet.DecimalPlaces = flowsheetPrefs.DecimalPlaces;
            }
            else if (obj is ProsimoUI.CustomEditor.CustomEditor)
            {
               ProsimoUI.CustomEditor.CustomEditor persistedEditor = (ProsimoUI.CustomEditor.CustomEditor)obj;
               flowsheet.CustomEditor.SetObjectData(persistedEditor.SerializationInfo, persistedEditor.StreamingContext);
            }
         }

         if (this.CheckFlowsheetVersion(items, flowsheet))
            flowsheet.IsDirty = false;
         else
            flowsheet = null;

         return flowsheet;
      }