コード例 #1
0
        /// <summary>
        /// Shows a form for the user to select/change settings through a GUI. All interactive
        /// GUI operations MUST happen within this function scope.
        /// </summary>
        /// <param name="preConfig">Result of PreConfig</param>
        /// <param name="previousConfig">Previous configuration to initialize the GUI.</param>
        /// <returns>Null if operation is canceled by the user. Otherwise returns with a new
        /// configuration object.</returns>
        public IInterpreterConfiguration DoGUIConfiguration(
            IInterpreterPreConfiguration preConfig,
            IInterpreterConfiguration previousConfig)
        {
            CyPhy2Schematic_Settings settings = (previousConfig as CyPhy2Schematic_Settings);

            // If none found, we should do GUI.
            // If available, seed the GUI with the previous settings.
            if (settings == null || settings.skipGUI == null)
            {
                // Do GUI
                var gui = new CyPhy2Schematic.GUI.CyPhy2Schematic_GUI();
                gui.settings = settings;

                var result = gui.ShowDialog();

                if (result == DialogResult.OK)
                {
                    return(gui.settings);
                }
                else
                {
                    // USER CANCELED.
                    return(null);
                }
            }

            return(settings);
        }
コード例 #2
0
        private CyPhy2Schematic_Settings InitializeSettingsFromWorkflow(CyPhy2Schematic_Settings settings)
        {
            // Seed with settings from workflow.
            String str_WorkflowParameters = "";

            try
            {
                MgaGateway.PerformInTransaction(delegate
                {
                    var testBench          = TonkaClasses.TestBench.Cast(this.mainParameters.CurrentFCO);
                    var workflowRef        = testBench.Children.WorkflowRefCollection.FirstOrDefault();
                    var workflow           = workflowRef.Referred.Workflow;
                    var taskCollection     = workflow.Children.TaskCollection;
                    var myTask             = taskCollection.FirstOrDefault(t => t.Attributes.COMName == this.ComponentProgID);
                    str_WorkflowParameters = myTask.Attributes.Parameters;
                },
                                                transactiontype_enum.TRANSACTION_NON_NESTED,
                                                abort: true
                                                );

                Dictionary <string, string> dict_WorkflowParameters = (Dictionary <string, string>)
                                                                      Newtonsoft.Json.JsonConvert.DeserializeObject(str_WorkflowParameters, typeof(Dictionary <string, string>));

                if (dict_WorkflowParameters != null)
                {
                    settings = new CyPhy2Schematic_Settings();
                    foreach (var property in settings.GetType().GetProperties()
                             .Where(p => p.GetCustomAttributes(typeof(WorkflowConfigItemAttribute), false).Any())
                             .Where(p => dict_WorkflowParameters.ContainsKey(p.Name)))
                    {
                        property.SetValue(settings, dict_WorkflowParameters[property.Name], null);
                    }
                }
            }
            catch (NullReferenceException)
            {
                Logger.WriteInfo("Could not find workflow object for CyPhy2Schematic interpreter.");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                Logger.WriteWarning("Workflow Parameter has invalid Json String: {0}", str_WorkflowParameters);
            }

            return(settings);
        }
コード例 #3
0
        private CyPhy2Schematic_Settings InitializeSettingsFromWorkflow(CyPhy2Schematic_Settings settings)
        {
            // Seed with settings from workflow.
            String str_WorkflowParameters = "";
            try
            {
                MgaGateway.PerformInTransaction(delegate
                {
                    var testBench = TonkaClasses.TestBench.Cast(this.mainParameters.CurrentFCO);
                    var workflowRef = testBench.Children.WorkflowRefCollection.FirstOrDefault();
                    var workflow = workflowRef.Referred.Workflow;
                    var taskCollection = workflow.Children.TaskCollection;
                    var myTask = taskCollection.FirstOrDefault(t => t.Attributes.COMName == this.ComponentProgID);
                    str_WorkflowParameters = myTask.Attributes.Parameters;
                },
                transactiontype_enum.TRANSACTION_NON_NESTED,
                abort: true
                );

                Dictionary<string, string> dict_WorkflowParameters = (Dictionary<string, string>)
                    Newtonsoft.Json.JsonConvert.DeserializeObject(str_WorkflowParameters, typeof(Dictionary<string, string>));

                if (dict_WorkflowParameters != null)
                {
                    settings = new CyPhy2Schematic_Settings();
                    foreach (var property in settings.GetType().GetProperties()
                                                               .Where(p => p.GetCustomAttributes(typeof(WorkflowConfigItemAttribute), false).Any())
                                                               .Where(p => dict_WorkflowParameters.ContainsKey(p.Name)))
                    {
                        property.SetValue(settings, dict_WorkflowParameters[property.Name], null);
                    }
                }
            }
            catch (NullReferenceException)
            {
                Logger.WriteInfo("Could not find workflow object for CyPhy2Schematic interpreter.");
            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                Logger.WriteWarning("Workflow Parameter has invalid Json String: {0}", str_WorkflowParameters);
            }

            return settings;
        }
コード例 #4
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (this.enabled == false)
            {
                return;
            }

            try
            {
                // Need to call this interpreter in the same way as the MasterInterpreter will call it.
                // initialize main parameters
                var parameters = new InterpreterMainParameters()
                {
                    Project        = project,
                    CurrentFCO     = currentobj,
                    SelectedFCOs   = selectedobjs,
                    StartModeParam = param
                };

                this.mainParameters         = parameters;
                parameters.ProjectDirectory = project.GetRootDirectoryPath();

                // set up the output directory
                MgaGateway.PerformInTransaction(delegate
                {
                    string outputDirName = project.Name;
                    if (currentobj != null)
                    {
                        outputDirName = currentobj.Name;
                    }

                    var outputDirAbsPath = Path.GetFullPath(Path.Combine(
                                                                parameters.ProjectDirectory,
                                                                "results",
                                                                outputDirName));

                    parameters.OutputDirectory = outputDirAbsPath;

                    if (Directory.Exists(outputDirAbsPath))
                    {
                        Logger.WriteWarning("Output directory {0} already exists. Unexpected behavior may result.", outputDirAbsPath);
                    }
                    else
                    {
                        Directory.CreateDirectory(outputDirAbsPath);
                    }

                    //this.Parameters.PackageName = Schematic.Factory.GetModifiedName(currentobj.Name);
                });

                PreConfigArgs preConfigArgs = new PreConfigArgs()
                {
                    ProjectDirectory = parameters.ProjectDirectory,
                    Project          = parameters.Project
                };

                // call the preconfiguration with no parameters and get preconfig
                var preConfig = this.PreConfig(preConfigArgs);

                // get previous GUI config
                var settings_ = META.ComComponent.DeserializeConfiguration(parameters.ProjectDirectory,
                                                                           typeof(CyPhy2Schematic_Settings),
                                                                           this.ComponentProgID);
                CyPhy2Schematic_Settings settings = (settings_ != null) ? settings_ as CyPhy2Schematic_Settings : new CyPhy2Schematic_Settings();

                // Set configuration based on Workflow Parameters. This will override all [WorkflowConfigItem] members.
                settings = InitializeSettingsFromWorkflow(settings);

                // Don't skip GUI -- we've been invoked directly here.
                settings.skipGUI = null;

                // get interpreter config through GUI
                var config = this.DoGUIConfiguration(preConfig, settings);
                if (config == null)
                {
                    Logger.WriteWarning("Operation canceled by the user.");
                    return;
                }

                // if config is valid save it and update it on the file system
                META.ComComponent.SerializeConfiguration(parameters.ProjectDirectory, config, this.ComponentProgID);

                // assign the new configuration to mainParameters
                parameters.config = config;

                // call the main (ICyPhyComponent) function
                this.Main(parameters);
            }
            catch (Exception ex)
            {
                Logger.WriteError("Interpretation failed {0}<br>{1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                DisposeLogger();
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }