public RunProcess(XElement taskElement) { this.ExecutablePath.BaseFolder = ParseKnownFolder(taskElement.Attribute("ExecutablePathParent")?.Value, defaultIfNotSpecified: KnownFolder.Output); this.ExecutablePath.RelativePath = taskElement.Attribute("ExecutablePath").Value; var arguments = ImmutableArray.CreateBuilder <ProcessArgument>(); foreach (var el in taskElement.Elements("Argument")) { var argument = new ProcessArgument { Value = el.Value }; arguments.Add(argument); switch (el.Attribute("Type")?.Value) { case null: break; case "PathUnderOutputFolder": argument.Kind = ProcessArgumentKind.PathUnderOutputFolder; break; default: throw new NotSupportedException("Argument type " + el.Attribute("Type")?.Value + " was not recognized."); } } this.Arguments = arguments.MoveToImmutableSafe(); }
IMetadataObject DeepClone(IMetadataObject node, ProcessArgument processArgument, ChildChangesGetter childChangesGetter, Func <IMetadataObject, bool> mustForceVisit) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (processArgument == null) { throw new ArgumentNullException(nameof(processArgument)); } if (childChangesGetter == null) { throw new ArgumentNullException(nameof(childChangesGetter)); } if (mustForceVisit == null) { throw new ArgumentNullException(nameof(mustForceVisit)); } ILazyChildren ProcessChildren(ChildPropertyInfo childProperty, ILazyChildren children, IMetadataObject @new, IModelDataAccessor childDataAccessor) { var childChanges = childChangesGetter.Invoke(node, childProperty); return(children.Clone( forceVisit: mustForceVisit(children.Parent), update: n => DeepClone(n, processArgument, childChangesGetter, mustForceVisit), added: childChanges.Additions, deleted: childChanges.Deletions)); } return(node.DataAccessor.ConstructorParameterBinding.Cloner(node, processArgument, ProcessChildren)); }
/// <inheritdoc /> public IObjectRepository DeepClone(IObjectRepository instance, ProcessArgument processArgument, ChildChangesGetter childChangesGetter, Func <IMetadataObject, bool> mustForceVisit) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } return((IObjectRepository)DeepClone((IMetadataObject)instance, processArgument, childChangesGetter, mustForceVisit)); }
private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { // Disable Screen SafeEnableControl(false, txtYear, cboMonth, cboSystem, btnClear, btnProcess); // Start process. ProcessArgument arg = (ProcessArgument)e.Argument; StartProcess(arg); }
private void ProcessData() { //################################## // 1. Check mandatory data // Year, Month, System //################################## if (!ValidateRequire()) { return; } int Year = txtYear.IntValue; int Period = Util.ConvertObjectToInteger(cboMonth.SelectedValue); int System = Util.ConvertObjectToInteger(cboSystem.SelectedValue); //################################## //# 2. Check data transfer to SAP B1 //################################## bool bExistTransfer = m_bizProcess.CheckExistTransfer(Year, Period); if (bExistTransfer) { MessageDialog.ShowBusinessErrorMsg(this, "This month can't be processed"); return; } //################################## //# 3. Check Repeat Process //################################## bool bRepeatProcess = m_bizProcess.CheckRepeatProcess(Year, Period, System); if (bRepeatProcess) { if (MessageDialog.ShowConfirmationMsg(this, "Do you want to do repeat process?") == DialogButton.No) { return; } } //################################## //# 4. Retrieve Data (Async) //################################## AppEnvironment.ShowWaitForm("Please Wait", "Processing"); ProcessArgument argument = new ProcessArgument(); argument.Year = Year; argument.Period = Period; argument.System = System; argument.ByUser = AppEnvironment.UserLogin; bgWorker.RunWorkerAsync(argument); }
public static T[] ProcessArray <T>(T[] array, ProcessArgument <T> d) { if (array == null) { throw new ArgumentNullException("array"); } T[] result = new T[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = d(array[i]); } return(result); }
private void StartProcess(ProcessArgument arg) { try { SafeUpdateProgressValue(0); m_bizProcess.RetrieveData(arg.Year, arg.Period, arg.System, arg.ByUser, ConnOnInfoMessage); } catch (Exception ex) { ExceptionManager.ManageException(this, ex); } }
private static string GetArgument(ProcessArgument arg, SetupContext context) { switch (arg.Kind) { case ProcessArgumentKind.Simple: return(arg.Value); case ProcessArgumentKind.PathUnderOutputFolder: return(context.ResolveFile(new DeferredAbsolutePath(KnownFolder.Output, arg.Value)).FullName); } throw new NotSupportedException("Argument type " + arg.Kind + " was not recognized."); }
private void ProcessReCalculate() { if (!ValidateReCalRequire()) { return; } //################################## //#Check process //################################## bool bRepeat = m_bizProcess.CheckRepeatProcess(txtYear.IntValue, Util.ConvertObjectToInteger(cboMonth.SelectedValue)); if (!bRepeat) { MessageDialog.ShowBusinessErrorMsg(this, "Please Process Data First."); return; } if (Util.ConvertObjectToDecimal(txtActualCapacity.DecimalValue) != (Util.ConvertObjectToDecimal(txtSoldLiterSum.DecimalValue) + Util.ConvertObjectToDecimal(txtEndLiterSum.DecimalValue))) { MessageDialog.ShowBusinessErrorMsg(this, "Total FG Production is not equal to Total of Sold Liter and Ending Liter."); return; } AppEnvironment.ShowWaitForm("Please Wait", "Calculating"); ProcessArgument arg = new ProcessArgument(); arg.Year = txtYear.IntValue; arg.Period = Util.ConvertObjectToInteger(cboMonth.SelectedValue); arg.pActMOH = Util.ConvertObjectToDecimal(txtActualMOH.DecimalValue); arg.pActCapaUsed = Util.ConvertObjectToDecimal(txtActualCapacity.DecimalValue); arg.pSoldLiter = Util.ConvertObjectToDecimal(txtSoldLiter.DecimalValue); arg.pEndingLiter = Util.ConvertObjectToDecimal(txtEndLiter.DecimalValue); arg.pSoldLiterOEM = Util.ConvertObjectToDecimal(txtSoldLiterOEM.DecimalValue); arg.pEndingLiterOEM = Util.ConvertObjectToDecimal(txtEndLiterOEM.DecimalValue); arg.ByUser = AppEnvironment.UserLogin; var resultDo = m_bizProcess.ReCalculateData(arg.Year, arg.Period, arg.pActMOH, arg.pActCapaUsed, arg.pSoldLiter, arg.pEndingLiter, arg.pSoldLiterOEM, arg.pEndingLiterOEM, arg.ByUser); UpdateReCalValue(resultDo); AppEnvironment.CloseWaitForm(); MessageDialog.ShowInformationMsg("Calculate Completed"); }
private void StartProcess(ProcessArgument arg) { try { SafeUpdateProgressValue(0); var resultDo = m_bizProcess.CalculateData(arg.Year, arg.Period, arg.ByUser, ConnOnInfoMessage); UpdateProgressValue(resultDo); //this.Invoke(new Action(() => //{ // txtActualMOH.DecimalValue = resultDo.ActMOH; //})); //txtActualMOH.DecimalValue = resultDo.ActMOH; //txtActualCapacity.DecimalValue = resultDo.ActCapaUsed; //txtActualMOHRate.DecimalValue = resultDo.ActCostRate; } catch (Exception ex) { ExceptionManager.ManageException(this, ex); } }
public void ProcessApplicationAssemblies(ProcessArgument args) { try { #if !WINDOWS_PHONE && !iOS && !ANDROID AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += CurrentDomain_ReflectionOnlyAssemblyResolve; if (args.loadedDomains != null) { foreach (var domain in args.loadedDomains) { try { AppDomain.CurrentDomain.Load(domain); } catch (FileNotFoundException) { } } } #endif //Store the serializer and processor types as we will need then repeatedly var serializerType = typeof(DPSBase.DataSerializer); var processorType = typeof(DPSBase.DataProcessor); //We're now going to look through the assemly reference tree to look for more components //This will be done by first checking whether a relefection only load of each assembly and checking //for reference to DPSBase. We will therefore get a reference to DPSBase var dpsBaseAssembly = typeof(DPSManager).Assembly; //Loop through all loaded assemblies looking for types that are not abstract and implement DataProcessor or DataSerializer. They also need to have a paramterless contstructor var alreadyLoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); //We are also going to keep a track of all assemblies with which we have considered types within var dicOfSearchedAssemblies = new Dictionary <string, Assembly>(); //And all the assembly names we have tried to load var listofConsideredAssemblies = new List <string>(); foreach (var ass in alreadyLoadedAssemblies) { #if WINDOWS_PHONE || iOS || ANDROID #else foreach (var refAss in ass.GetReferencedAssemblies()) { if (AssemblyComparer.Instance.Equals(dpsBaseAssembly.GetName(), refAss) || ass == dpsBaseAssembly) { #endif foreach (var type in ass.GetTypes()) { byte id; var attributes = type.GetCustomAttributes(typeof(DataSerializerProcessorAttribute), false); if (attributes.Length == 1) { id = (attributes[0] as DataSerializerProcessorAttribute).Identifier; } else { continue; } if (serializerType.IsAssignableFrom(type) && !type.IsAbstract && (type.GetConstructors(BindingFlags.Instance).Length != 0 || type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Length != 0)) { //SerializersByType.Add(type, null); //DataSerializerIdToType.Add(id, type); serializerTypes.Add(id, type.AssemblyQualifiedName); } if (processorType.IsAssignableFrom(type) && !type.IsAbstract && (type.GetConstructors(BindingFlags.Instance).Length != 0 || type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Length != 0)) { //DataProcessorsByType.Add(type, null); //DataProcessorIdToType.Add(id, type); processorTypes.Add(id, type.AssemblyQualifiedName); } } #if WINDOWS_PHONE || iOS || ANDROID #else break; } } #endif dicOfSearchedAssemblies.Add(ass.FullName, ass); } #if WINDOWS_PHONE || iOS || ANDROID #else //Set an identifier to come back to as we load assemblies AssemblySearchStart: //Loop through all assemblies foreach (var pair in dicOfSearchedAssemblies) { var assembly = pair.Value; //Loop through the assemblies this assemlby references foreach (var referencedAssembly in assembly.GetReferencedAssemblies()) { //If we've already tried this assembly name then keep going. Otherwise record that we will have tried this assembly if (listofConsideredAssemblies.Contains(referencedAssembly.FullName)) { continue; } else { listofConsideredAssemblies.Add(referencedAssembly.FullName); } Assembly refAssembly = null; //Occationally assemblies will not resolve (f**k knows why). They will then throw a FileNotFoundException that we can catch and ignore try { //Do a reflection only load of the assembly so that we can see if it references DPSBase and also what it does reference refAssembly = System.Reflection.Assembly.ReflectionOnlyLoad(referencedAssembly.FullName); } catch (FileNotFoundException) { continue; } //Note that multiple assembly names/versions could resolve to this assembly so check if we're already considered the actual //loaded assembly if (!dicOfSearchedAssemblies.ContainsKey(refAssembly.FullName)) { //if not add it to the considered list dicOfSearchedAssemblies.Add(refAssembly.FullName, refAssembly); //if it references DPSBase directly it might contain components. Add the assembly to the catalog foreach (var refAss in refAssembly.GetReferencedAssemblies()) { if (AssemblyComparer.Instance.Equals(dpsBaseAssembly.GetName(), refAss)) { foreach (var type in refAssembly.GetTypes()) { bool idSet = false; byte id = 0; //var attributes = type.GetCustomAttributes(typeof(DataSerializerProcessorAttribute), false); var attributes = CustomAttributeData.GetCustomAttributes(type); foreach (var attr in attributes) { if (attr.Constructor.ReflectedType.AssemblyQualifiedName == typeof(DataSerializerProcessorAttribute).AssemblyQualifiedName) { id = (byte)attr.ConstructorArguments[0].Value; idSet = true; } } if (!idSet) { continue; } Type baseType = type.BaseType; while (baseType != null) { if (baseType.AssemblyQualifiedName == serializerType.AssemblyQualifiedName) { //SerializersByType.Add(type, null); //DataSerializerIdToType.Add(id, type); serializerTypes.Add(id, type.AssemblyQualifiedName); break; } if (baseType.AssemblyQualifiedName == processorType.AssemblyQualifiedName) { //DataProcessorsByType.Add(type, null); //DataProcessorIdToType.Add(id, type); processorTypes.Add(id, type.AssemblyQualifiedName); break; } baseType = baseType.BaseType; } } break; } } //We're changed allAssemblies and loadedAssemblies so restart goto AssemblySearchStart; } } } #endif } catch (Exception) { //int i = 1; //using (StreamWriter sw = new StreamWriter("DPSManagerLoadError.txt", false)) //Console.WriteLine(ex.ToString()); } finally { args.processorTypes = processorTypes; args.serializerTypes = serializerTypes; } }
private void ProcessData() { //################################## // 1. Check mandatory data // Year, Month, System //################################## if (!ValidateRequire()) { return; } int Year = txtYear.IntValue; int Period = Util.ConvertObjectToInteger(cboMonth.SelectedValue); //################################## //# 2. Check data transfer to SAP B1 //################################## bool bExistTransfer = m_bizProcess.CheckExistTransfer(Year, Period); if (bExistTransfer) { MessageDialog.ShowBusinessErrorMsg(this, "This month can't be processed"); return; } //################################## //# 3. Check retrieve data from SAP B1 //################################## bool bRetrieveData = m_bizProcess.CheckRetrieve(Year, Period); if (!bRetrieveData) { MessageDialog.ShowBusinessErrorMsg(this, "Please Retrieve data before Calculation"); return; } //################################## //# 4. Check repeat process //################################## bool bRepeat = m_bizProcess.CheckRepeatProcess(Year, Period); if (bRepeat) { if (MessageDialog.ShowConfirmationMsg(this, "Do you want to do repeat process?") == DialogButton.No) { return; } } //################################## //# 5. Start Process Calculation (Async) //################################## AppEnvironment.ShowWaitForm("Please Wait", "Processing"); ProcessArgument argument = new ProcessArgument(); argument.Year = Year; argument.Period = Period; argument.ByUser = AppEnvironment.UserLogin; bgWorkerProcess.RunWorkerAsync(argument); while (bgWorkerProcess.IsBusy) { Thread.Sleep(200); Application.DoEvents(); } //################################## //# 7. Show information message after process complete. //################################## tb_Transfer transferResult = null; if (progressBar.Value == 100) { AppEnvironment.CloseWaitForm(); MessageDialog.ShowInformationMsg("Process completed 100%"); //transferResult = m_bizProcess.GetTransferData(Year, Period); } else { AppEnvironment.CloseWaitForm(); MessageDialog.ShowInformationMsg("Process not completed."); } //################################## //# 8. Display output after process complete. //################################## //if (transferResult == null) //{ // txtActualMOH.Text = string.Empty; // txtActualCapacity.Text = string.Empty; // txtActualMOHRate.Text = string.Empty; //} //else //{ // txtActualMOH.DecimalValue = transferResult.ActualMOH.GetValueOrDefault(0); // txtActualCapacity.DecimalValue = transferResult.ActualCapacity.GetValueOrDefault(0); // txtActualMOHRate.DecimalValue = transferResult.ActualMOHRate.GetValueOrDefault(0); //} }
/// <summary> /// Adds an option argument with value. /// </summary> /// <param name="optionName">The name of the option argument.</param> /// <param name="value">The value of the option argument.</param> /// <returns> /// The current <see cref="ProcessArguments"/> instance for chaining purposes. /// </returns> public ProcessArguments AddOption(string optionName, string value) { _arguments.Add(ProcessArgument.Option(optionName, value)); return(this); }
/// <summary> /// Adds a noun argument. /// </summary> /// <param name="value">The value of the noun argument.</param> /// <returns> /// The current <see cref="ProcessArguments"/> instance for chaining purposes. /// </returns> public ProcessArguments AddNoun(string value) { _arguments.Add(ProcessArgument.Noun(value)); return(this); }
/// <summary> /// Adds a verb argument. /// </summary> /// <param name="verb">The name of the verb argument.</param> /// <returns> /// The current <see cref="ProcessArguments"/> instance for chaining purposes. /// </returns> public ProcessArguments AddVerb(string verb) { _arguments.Add(ProcessArgument.Verb(verb)); return(this); }
private DPSManager() { //This constructor loops through referenced assemblies looking for types that inherit off of DataSerializer and //DataProcessor. On windows this should mean perfect auto detection of serializers and compressors. On windows //phone we cannot get a list of referenced assemblies so we can only do this for already loaded assemblies. //Any others that are used will have to be added manually. On windows this will be done from a new app domain //so we can unload it afterwards //This action will perform the load in the background on some client dependent "thread" Action loadAction = new Action(() => { //Initialise the core extensions DPSManager.GetDataSerializer <ExplicitSerializer>(); DPSManager.GetDataSerializer <NullSerializer>(); DPSManager.GetDataProcessor <DataPadder>(); #if !FREETRIAL //Only the full version includes the encrypter DPSManager.GetDataProcessor <RijndaelPSKEncrypter>(); #endif #if !WINDOWS_PHONE && !NETFX_CORE DPSManager.GetDataSerializer <BinaryFormaterSerializer>(); #endif AssemblyLoader loader; ProcessArgument args; #if !WINDOWS_PHONE && !iOS && !ANDROID && !NETFX_CORE AppDomain tempDomain = null; try { //Create a new domain with the same settings as the current domain AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; tempDomain = AppDomain.CreateDomain("Temp_" + Guid.NewGuid().ToString(), AppDomain.CurrentDomain.Evidence, setup); try { //First try creating the proxy from the assembly using the assembly name loader = (AssemblyLoader)tempDomain.CreateInstanceFromAndUnwrap(typeof(AssemblyLoader).Assembly.FullName, typeof(AssemblyLoader).FullName); } catch (FileNotFoundException) { //If that fails try with the assembly location. An exception here loader = (AssemblyLoader)tempDomain.CreateInstanceFromAndUnwrap(typeof(AssemblyLoader).Assembly.Location, typeof(AssemblyLoader).FullName); } args = new ProcessArgument(); //If an entry assembly exists just pass that, the rest can be worked out from there. //On WCF there is no entry assembly. In that case fill the loaded domains list with those already loaded if (Assembly.GetEntryAssembly() != null) { args.loadedDomains = new List <string>() { Assembly.GetEntryAssembly().FullName } } ; else { List <string> loadedDomains = new List <string>(); foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { loadedDomains.Add(ass.FullName); } args.loadedDomains = loadedDomains; } loader.ProcessApplicationAssemblies(args); } catch (FileNotFoundException) { //In mono, using mkbundle, the above load method may not work so we will fall back to our older way of doing the same //The disadvantage of this approach is that all assemblies are loaded and then stay in memory increasing the footprint slightly loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); } catch (MissingMethodException) { loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); } catch (Exception) { loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); } finally { if (tempDomain != null) { try { AppDomain.Unload(tempDomain); } catch (Exception) { } finally { tempDomain = null; GC.Collect(); } } } #else loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); #endif foreach (var serializer in args.serializerTypes) { lock (addRemoveObjectLocker) { if (!SerializersByType.ContainsKey(serializer.Value)) { SerializersByType.Add(serializer.Value, null); DataSerializerIdToType.Add(serializer.Key, serializer.Value); } } } foreach (var processor in args.processorTypes) { lock (addRemoveObjectLocker) { if (!DataProcessorsByType.ContainsKey(processor.Value)) { DataProcessorsByType.Add(processor.Value, null); DataProcessorIdToType.Add(processor.Key, processor.Value); } } } loadCompleted.Set(); }); #if NET2 || NET35 Thread loadThread = new Thread(new ThreadStart(loadAction)); loadThread.Name = "DPS load thread"; loadThread.Start(); #else Task.Factory.StartNew(loadAction); #endif }
private DPSManager() { //This constructor loops through referenced assemblies looking for types that inherit off of DataSerializer and DataProcessor. On windows this should mean perfect autodetection //of serializers and compressors. On windows phone we cannot get a list of referenced assemblies so we can only do this for already loaded assemblies. Any others that are used will //have to be added manually. On windows this will be done from a new app domain so we can unload it afterwards AssemblyLoader loader; ProcessArgument args; #if !WINDOWS_PHONE && !iOS && !ANDROID AppDomain tempDomain = null; try { //Create a new domain with the same settings as the current domain AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; tempDomain = AppDomain.CurrentDomain;// AppDomain.CreateDomain("Temp_" + Guid.NewGuid().ToString(), AppDomain.CurrentDomain.Evidence, setup); try { //First try creating the proxy from the assembly using the assembly name loader = (AssemblyLoader)tempDomain.CreateInstanceFromAndUnwrap(typeof(AssemblyLoader).Assembly.FullName, typeof(AssemblyLoader).FullName); } catch (FileNotFoundException) { //If that fails try with the assembly location. An exception here loader = (AssemblyLoader)tempDomain.CreateInstanceFromAndUnwrap(typeof(AssemblyLoader).Assembly.Location, typeof(AssemblyLoader).FullName); } args = new ProcessArgument(); //If an entry asssembly exists just pass that, the rest can be worked out from there. //On WCF there is no entry assembly. In that case fill the loaded domains list with those already loaded if (Assembly.GetEntryAssembly() != null) { args.loadedDomains = new List <string>() { Assembly.GetEntryAssembly().FullName } } ; else { List <string> loadedDomains = new List <string>(); foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { loadedDomains.Add(ass.FullName); } args.loadedDomains = loadedDomains; } loader.ProcessApplicationAssemblies(args); } catch (FileNotFoundException) { //In mono, using mkbundle, the above load method may not work so we will fall back to our older way of doing the same //The disadvantage of this approach is that all assemblies are loaded and then stay in memory increasing the footprint slightly loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); } catch (MissingMethodException) { loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); } catch (Exception) { loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); } finally { if (tempDomain != null) { try { AppDomain.Unload(tempDomain); } catch (Exception) { } finally { tempDomain = null; GC.Collect(); } } } #else loader = new AssemblyLoader(); args = new ProcessArgument(); loader.ProcessApplicationAssemblies(args); #endif foreach (var serializer in args.serializerTypes) { SerializersByType.Add(serializer.Value, null); DataSerializerIdToType.Add(serializer.Key, serializer.Value); } foreach (var processor in args.processorTypes) { DataProcessorsByType.Add(processor.Value, null); DataProcessorIdToType.Add(processor.Key, processor.Value); } }