public override Type BindToType(string assemblyName, string typeName) { Type type; Assembly unitCoreAsm = Assembly.GetExecutingAssembly(); type = unitCoreAsm.GetType(typeName); if (type != null) { return(type); } var asms = AppDomain.CurrentDomain.GetAssemblies(); foreach (var asm in asms) { if (asm.FullName == assemblyName) { type = asm.GetType(typeName); if (type != null) { return(type); } } } CasterLogger.Error($"Type {typeName} in Assemly {assemblyName} is not found."); return(typeof(object)); }
public override void ClearAllProperties() { CasterLogger.Debug("Material 11 ClearAllProperties"); Debug.Assert(IsValid()); _capeThermoMaterial.ClearAllProps(); //_alreadyFlashed = false; }
/// <summary> /// This constructor assign SpecCalculator, create Ports, Parameters and Results and call their initialize method /// </summary> /// <paramCollection name="specCalculator">the specification calculate class</paramCollection> /// <paramCollection name="className">name of this unit operation</paramCollection> /// <paramCollection name="description">description of this unit operation</paramCollection> public CasterUnitOperationBase(Calculator specCalculator, string className, string description) : base(className, description, true, true) { CasterLogger.Debug($"UnitOperation {className} Initializing."); Debug.WriteLine($"UnitOperation {className} Initializing."); this.SpecCalculator = specCalculator; SpecCalculator.UnitOp = this; Isloaded = false; UnitId = Guid.NewGuid().ToString("B"); Ports = new CapeCollection("Ports", "In and Out ports of this unit.", (item) => item is ICapeUnitPort); Parameters = new CapeCollection("Parameters", "User input Parameters of this unit.", (item) => item is ICapeParameter && (item as ICapeParameter).Mode != CapeParamMode.CAPE_OUTPUT); Results = new CapeCollection("Results", "Calculate Results, output Parameters.", (item) => item is ICapeParameter && (item as ICapeParameter).Mode != CapeParamMode.CAPE_INPUT); Reports = new List <ReportBase>(); CasterLogger.Debug("UnitOperation Initialize Completed."); Debug.WriteLine("UnitOperation Initialize Completed."); }
public override double[] GetSinglePhasePropList(string propName, Phases phase, PropertyBasis basis, bool calculate = true) { CasterLogger.Debug($"Get property {propName} for phase {phase}"); object value = null; if (PresentPhases.All(p => p.Value != phase.Value)) { return(new double[CompoundNum]); //default is 0 for every element } try { if (calculate) { _capeThermoPropertyRoutine.CalcSinglePhaseProp(new[] { propName }, phase.Value); } } catch (Exception e) { CasterLogger.ErrorFormatted("Calculate single phase prop {0} fails. {1}", propName, e.Message); Debug.WriteLine("Calculate single phase prop {0} fails. {1}", propName, e.Message); } _capeThermoMaterial.GetSinglePhaseProp(propName, phase.Value, basis.ToString(), ref value); CasterLogger.Debug($"Property {propName} result: {value}"); return(value as double[]); }
/// <summary> /// Release COM resources /// </summary> public void Dispose() { CasterLogger.Debug("Material Dispose"); Dispose(true); GC.SuppressFinalize(this); CasterLogger.Debug("Material Disposed"); }
public override bool SetMaterial(object material) { CasterLogger.Debug("SetMaterial"); if (material == null) { return(false); } if (material is ICapeThermoMaterial) { //_alreadyFlashed = true; MaterialObjectVersion = 11; _capeThermoMaterial = material as ICapeThermoMaterial; _capeThermoMaterialContext = material as ICapeThermoMaterialContext; _capeThermoPhases = material as ICapeThermoPhases; _capeThermoCompounds = material as ICapeThermoCompounds; _capeThermoPropertyRoutine = material as ICapeThermoPropertyRoutine; _capeThermoEquilibriumRoutine = material as ICapeThermoEquilibriumRoutine; _capeThermoUniversalConstant = material as ICapeThermoUniversalConstant; } else if (material is MaterialObject11) { SetMaterial(((MaterialObject11)material).CapeThermoMaterialObject); } else { throw new ArgumentException("parameter is not a CO1.1 material object"); } GetListOfAllowedPhase(out string[] _, out string _2); UpdateCompoundList(); CasterLogger.Debug("SetMaterial completed"); return(true); }
public override bool SetMaterial(object materialObject) { CasterLogger.Debug("SetMaterial"); if (materialObject == null) { return(false); } if (materialObject is ICapeThermoMaterialObject) { //_alreadyFlashed = true; MaterialObjectVersion = 10; _capeThermoMaterialObject = materialObject as ICapeThermoMaterialObject; //_capeThermoPropertyPackage = materialObject as ICapeThermoPropertyPackage; //if (_capeThermoPropertyPackage == null) // Debug.WriteLine("Aspen dont support CapeThermoPropertyPackage interface!"); } else if (materialObject is MaterialObject10) { SetMaterial(((MaterialObject10)materialObject).CapeThermoMaterialObject); } else { throw new ArgumentException("parameter is not a CO1.0 material object"); } GetListOfAllowedPhase(out string[] _, out string _2); UpdateCompoundList(); CasterLogger.Debug("SetMaterial completed"); return(true); }
public override bool DoPVFlash(bool showWarning = false) { CasterLogger.Debug("DoTVFFlash"); if (_capeThermoMaterialObject == null) { return(false); } try { _capeThermoMaterialObject.CalcEquilibrium("PVF", null); //_alreadyFlashed = true; } catch (Exception e) { if (showWarning) { MessageBox.Show("Flash fails. " + e.Message); } CasterLogger.Error("Flash failed. " + e.Message); Debug.WriteLine("Flash fails. {0}", e.Message); return(false); } CasterLogger.Debug("Flash completed."); return(true); }
public override Phases[] GetListOfPresentPhases(out eCapePhaseStatus[] presentPhaseStatus) { CasterLogger.Debug("GetListOfPresentPhases"); object phaseLabel; presentPhaseStatus = null; //CO1.0 Not support if (_capeThermoMaterialObject == null) { return(null); } try { phaseLabel = _capeThermoMaterialObject.PhaseIds; } catch (Exception e) { CasterLogger.ErrorFormatted("No present phase. {0}", e.Message); Debug.WriteLine("No present phase. {0}", e.Message); phaseLabel = new string[0]; } string[] phaseStringList = phaseLabel as string[]; Phases[] phaseList = (from phaseString in phaseStringList select new Phases(phaseString)).ToArray(); var phases = string.Join(", ", phaseList.Select(p => p.Value).ToArray()); CasterLogger.Debug("Material present phases: " + phases); return(phaseList); }
public override Phases[] GetListOfPresentPhases(out eCapePhaseStatus[] presentPhaseStatus) { CasterLogger.Debug("GetListOfPresentPhases"); object phaseLabel = null; object phaseStatus = null; presentPhaseStatus = null; if (_capeThermoMaterial == null) { return(null); } _capeThermoMaterial.GetPresentPhases(ref phaseLabel, ref phaseStatus); string[] status = phaseStatus as string[]; if (status != null) { presentPhaseStatus = new eCapePhaseStatus[status.Length]; for (int i = 0; i < status.Length; i++) { eCapePhaseStatus s; if (Enum.TryParse(status[i], out s)) { presentPhaseStatus[i] = s; } } } string[] phaseStringList = phaseLabel as string[]; Phases[] phaseList = (from phaseString in phaseStringList select new Phases(phaseString)).ToArray(); var phases = string.Join(", ", phaseList.Select(p => p.Value).ToArray()); CasterLogger.Debug("Material present phases: " + phases); return(phaseList); }
/// <summary> /// Default action is to check whether all Parameters is valid, override to customize /// </summary> protected virtual bool ParamtersValidate(out string message) { CasterLogger.Debug("ParamtersValidate"); bool valid = true; message = ""; foreach (var parameter in Parameters) { string temp = ""; if (!((CapeParameterBase)parameter.Value).Validate(ref temp)) { message += "\n" + temp; valid = false; } } if (valid) { CasterLogger.Debug("Parameter valid."); return(true); } else { CasterLogger.Debug("Parameter invalid. Msg: " + message); return(false); } }
/// <summary> /// This method will call ParameterValidate and PortValidate, in most case, no need to override this, just override ParameterValidate and PortValidate /// </summary> /// <paramCollection name="message">return the combined error message</paramCollection> public virtual bool Validate(ref string message) { CasterLogger.Debug("Validate"); string parameterMessage = null; string portMessage = null; Status = CapeValidationStatus.CAPE_VALID; if (!ParamtersValidate(out parameterMessage)) { Status = CapeValidationStatus.CAPE_INVALID; } if (!PortsValidate(out portMessage)) { Status = CapeValidationStatus.CAPE_INVALID; } message = "" + parameterMessage + '\n' + portMessage; if (Status == CapeValidationStatus.CAPE_VALID) { CasterLogger.Debug("Validate success."); return(true); } else { CasterLogger.DebugFormatted("Validate fails. {0}", message); Debug.WriteLine("Validate fails. {0}", message); return(false); } }
/// <summary> /// default name is "capeUnitPort" /// </summary> protected CapeUnitPortBase(string name, CapePortType type, CapePortDirection portDirection, string description = "", bool canRename = false) : base(name, description, canRename) { CasterLogger.Debug($"Create unit port {name}, type is {type}, direction is {portDirection}"); _portDirection = portDirection; _portType = type; }
/// <summary> /// Add available reports /// </summary> public virtual void InitReports() { CasterLogger.Debug("Init reports"); Reports.Add(new StatusReport()); Reports.Add(new LastRunReport()); CasterLogger.Debug("Finish init reports"); }
public override double GetUniversalConstProp(string constantId) { CasterLogger.Debug($"GetUniversalConstProp for {constantId}"); object temp = _capeThermoUniversalConstant.GetUniversalConstant(constantId); return(Convert.ToDouble(temp)); }
public override double[] GetTwoPhasePropList(string propName, Phases phase1, Phases phase2, PropertyBasis basis, bool calculate = true) { CasterLogger.Debug($"Get property {propName} for phase {phase1} and {phase2}"); object value = null; if (PresentPhases.All(p => p.Value != phase1.Value) || PresentPhases.All(p => p.Value != phase2.Value)) { return(new double[CompoundNum]); } string[] phaseList = { phase1.Value, phase2.Value }; try { _capeThermoPropertyRoutine.CalcTwoPhaseProp(new[] { propName }, phaseList); } catch (Exception e) { Debug.WriteLine("Calculate two phase prop {0} fails. {1}", propName, e.Message); } _capeThermoMaterial.GetTwoPhaseProp(propName, phaseList, basis.ToString(), ref value); CasterLogger.Debug($"Property {propName} result: {value}"); return(value as double[]); }
/// <summary> /// Set MaterialObject to this class /// </summary> /// <paramCollection name="material">MaterialObject</paramCollection> /// <returns></returns> public bool SetMaterial(MaterialObject material) { CasterLogger.Debug("SetMaterial"); var result = SetMaterial((object)material); CasterLogger.Debug("SetMaterial " + (result? "successed." : "failed.")); return(result); }
public override void SetOverallPropList(string propName, PropertyBasis basis, IEnumerable <double> value) { CasterLogger.Debug($"Set property {propName} for overall: {value}"); double[] temp = value as double[] ?? value.ToArray(); _capeThermoMaterial.SetOverallProp(propName, basis.ToString(), value); //_alreadyFlashed = false; CasterLogger.Debug($"Set property complete"); }
public override double GetCompoundPDependentProp(string propName, string compoundId, double P) { CasterLogger.Debug($"GetCompoundPDependentProp compound {compoundId} for {propName} at pressure {P}"); object value = null; _capeThermoCompounds.GetPDependentProperty(new[] { propName }, P, new[] { compoundId }, ref value); return((value as double[]).SingleOrDefault()); }
public override double[] GetOverallPropList(string propName, PropertyBasis basis, bool calculate = false) { CasterLogger.Debug($"Get property {propName} for overall"); object value = null; _capeThermoMaterial.GetOverallProp(propName, basis.ToString(), ref value); CasterLogger.Debug($"Property {propName} result: {value}"); return(value as double[]); }
public override void InitPorts() { CasterLogger.Debug("InitPorts"); Ports.Add(new CapeMaterialPort("feed", CapePortDirection.CAPE_INLET, "Inlet Material")); Ports.Add(new CapeMaterialPort("product", CapePortDirection.CAPE_OUTLET, "Outlet Material")); //Ports.Add(new CapeEnergyPort("energy", CapePortDirection.CAPE_INLET)); //Ports.Add(new CapeInformationPort("info", CapePortDirection.CAPE_INLET)); CasterLogger.Debug("InitPorts completed"); }
public override void Disconnect() { CasterLogger.Debug($"Port {this.ComponentName} is disconnecting"); if (_materialObject != null) { _materialObject.Dispose(); } _materialObject = null; CasterLogger.Debug($"Port {this.ComponentName} is disconnected."); }
public override void Disconnect() { CasterLogger.Debug($"Port {this.ComponentName} is disconnecting"); if (paramCollection != null && paramCollection.GetType().IsCOMObject) { Marshal.FinalReleaseComObject(paramCollection); } paramCollection = null; CasterLogger.Debug($"Port {this.ComponentName} disconnected."); }
public override void SetListOfPresentPhases(IEnumerable <Phases> presentPhases, IEnumerable <eCapePhaseStatus> presentPhasesStatus) { CasterLogger.Debug("SetListOfPresentPhases: " + string.Join(", ", presentPhases.Select(p => p.Value).ToArray())); if (_capeThermoMaterial == null) { return; } int[] phaseStatus = (from status in presentPhasesStatus select(int) status).ToArray(); string[] phaseStringList = (from phase in presentPhases select phase.Value).ToArray(); _capeThermoMaterial.SetPresentPhases(phaseStringList, phaseStatus); //_alreadyFlashed = false; }
public override void SetSinglePhasePropList(string propName, Phases phase, PropertyBasis basis, IEnumerable <double> value) { CasterLogger.Debug($"Set property {propName} for phase {phase}: {value}"); if (PresentPhases.All(p => p.Value != phase.Value)) { PresentPhases = AllowedPhases; } double[] temp = value as double[] ?? value.ToArray(); _capeThermoMaterial.SetSinglePhaseProp(propName, phase.Value, basis.ToString(), temp); //_alreadyFlashed = false; CasterLogger.Debug($"Set property complete"); }
/// <summary> /// get single phase property, return a double number, will try to calculate property first, if not present, return 0; if property is an array, throw exception /// </summary> public double GetSinglePhasePropDouble(string propName, Phases phase, PropertyBasis basis, bool calculate = true) { CasterLogger.Debug($"GetSinglePhasePropDouble for {propName} in {phase} Calculate: {calculate}"); if (PresentPhases.All(p => p.Value != phase.Value)) { return(0); } var result = GetSinglePhasePropList(propName, phase, basis, calculate).SingleOrDefault(); CasterLogger.Debug($"GetSinglePhasePropDouble result: {result}"); return(result); }
/// <summary> /// Called after the compound list is changed /// </summary> protected void UpdateCompoundList() { CasterLogger.Debug("UpdateCompoundList"); foreach (var item in Ports) { CapeMaterialPort p = item.Value as CapeMaterialPort; if (p != null && p.Material != null) { p.Material.UpdateCompoundList(); } } }
protected override void Dispose(bool disposing) { CasterLogger.Debug("Dispose material10."); if (_capeThermoMaterialObject != null && _capeThermoMaterialObject.GetType().IsCOMObject) { Marshal.ReleaseComObject(_capeThermoMaterialObject); } //if (_capeThermoPropertyPackage != null && _capeThermoPropertyPackage.GetType().IsCOMObject) // Marshal.FinalReleaseComObject(_capeThermoPropertyPackage); _capeThermoMaterialObject = null; CasterLogger.Debug("Dispose material10 completed."); }
public void DebugTest() { CasterLogger.Debug("Debug message."); CasterLogger.Shutdown(); var logfile = File.ReadAllLines(@"log\logfile.log"); var content = logfile[logfile.Length - 1]; Assert.IsTrue(content.EndsWith("Debug message.")); var dateStr = content.Substring(0, 19); // example: 2020-05-01 22:00:09 var date = Convert.ToDateTime(dateStr); Assert.IsTrue(DateTime.Now - date < new TimeSpan(0, 0, 1)); // less then a second }
/// <summary> /// connect to information, must be ICapeCollection /// </summary> public override void Connect(object objectToConnect) { CasterLogger.Debug($"Port {this.ComponentName} is connecting"); Disconnect(); if (objectToConnect is ICapeCollection) { paramCollection = objectToConnect as ICapeCollection; } else { throw new ECapeUnknownException(this, "object connected to information port must be ICapeCollection"); } CasterLogger.Debug($"Port {this.ComponentName} connected."); }