Esempio n. 1
0
 public OutputDll(string name,
                  string outputDllName,
                  Mode[]         modes,
                  OutputParams parameters)
 {
     this.name          = name;
     this.localizedName = StringLocalization.Localize(this.name);
     this.dllName       = outputDllName;
     this.modes         = modes;
     this.parameters    = parameters;
 }
Esempio n. 2
0
        /*************************************/

        public virtual bool CanRemoveOutput(string name)
        {
            if (OutputParams.Count < 2)
            {
                return(false);
            }
            else
            {
                ParamInfo match = OutputParams.Find(x => x.Name == name);
                return(match != null && !match.IsRequired);
            }
        }
Esempio n. 3
0
        /*************************************/

        public override bool UpdateInput(int index, string name, Type type = null)
        {
            bool isAllowedToUpdate = OutputParams.All(x => x.IsSelected);

            if (isAllowedToUpdate)
            {
                return(CollectOutputTypes());
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
 public OutputDll(string name,
                  string outputDllName,
                  string[]       modes,
                  OutputParams parameters)
 {
     this.name          = name;
     this.localizedName = StringLocalization.Localize(this.name);
     this.dllName       = outputDllName;
     this.modes         = new Mode[modes.Length];
     for (int i = 0; i < modes.Length; ++i)
     {
         this.modes[i] = new Mode(modes[i], i);
     }
     this.parameters = parameters;
 }
Esempio n. 5
0
        /*************************************/
        /**** Output Methods              ****/
        /*************************************/

        public bool RemoveOutput(string name)
        {
            if (name == null)
            {
                return(false);
            }

            ParamInfo match = OutputParams.Find(x => x.Name == name);

            if (match != null)
            {
                match.IsSelected = false;
            }

            return(true);
        }
        private OutputParams CloseWindow(InputParams inputs, ref bool SkillIsPausable)
        {
            //This is the implementation of the "second" Method provided to the Skills (the "closing method")
            //Which was more or less designed to cancel/stop/quit an execution

            //Skill is currently not pausable, and will never be pausable => so let SkillIsPausable set to false
            SkillIsPausable = false;

            InputsForFakeWindow value;

            //First cast the inputs
            try
            {
                value = (InputsForFakeWindow)inputs.Values;
            }
            catch (System.InvalidCastException ex)
            {
                //If you can't cast the inputs, then there is a special error code for this
                return(new OutputParams(Skill.ERROR_VALUES_CLOSING_INVALID, null));
            }

            try
            {
                //Ask the UI thread to close the window
                InputsForFakeWindow argsClose = new InputsForFakeWindow()
                {
                    StartANewWindow = false,
                    RemainingTimeMs = 0,
                    CloseTheWindow  = false,
                    ExecutionTimeMs = value.ExecutionTimeMs,
                    NameOfSkill     = value.NameOfSkill,
                    Status          = "(EMERGENCY) STOP CALLED => EXECUTION FINISHED"
                };

                OnDisplayOnSkillWindow(argsClose);

                OutputParams outp = new OutputParams(ERROR_DURING_EXECUTION, null, false, new SkillProException("(EMERGENCY) STOP CALLED"));

                return(outp);
            }
            catch (Exception ex)
            {
                return(new OutputParams(ERROR_DURING_EXECUTION, null, false, new SkillProException(ex.Message, ex)));
            }
        }
Esempio n. 7
0
        /*************************************/
        /**** Override Methods            ****/
        /*************************************/

        public override object Run(List <object> inputs)
        {
            if (inputs.Count != 1)
            {
                BH.Engine.Reflection.Compute.RecordError("The number of inputs is invalid.");
                return(null);
            }
            else
            {
                object obj = inputs[0];
                if (obj == null)
                {
                    return(Enumerable.Repeat <object>(null, m_CompiledSetters.Count).ToList());
                }

                List <object> result = OutputParams.Select(x => obj.PropertyValue(x.Name)).ToList();
                return((result.Count == 1) ? result[0] : result);
            }
        }
Esempio n. 8
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public virtual void SetItem(object item, bool sendNotification = true, bool updateOriginal = true)
        {
            if (item == null)
            {
                return;
            }

            if (updateOriginal)
            {
                m_OriginalItem = item;
            }
            SelectedItem = FromGeneric(item as dynamic);

            List <ParamInfo> oldInputs  = InputParams.ToList();
            List <ParamInfo> oldOutputs = OutputParams.ToList();

            SetComponentDetails();

            SetInputs();
            SetOutputs();

            SetInputSelectionMenu();
            SetOutputSelectionMenu();

            CompileMethod();
            CompileInputGetters();
            CompileOutputSetters();

            if (sendNotification)
            {
                MarkAsModified(new CallerUpdate
                {
                    Cause           = CallerUpdateCause.ItemSelected,
                    ComponentUpdate = new ComponentUpdate {
                        Name = Name, Description = Description
                    },
                    InputUpdates  = InputParams.Changes(oldInputs).Where(x => x.Param.IsSelected).ToList(),
                    OutputUpdates = OutputParams.Changes(oldOutputs).Where(x => x.Param.IsSelected).ToList()
                });
            }
        }
Esempio n. 9
0
        /*************************************/

        protected bool RestoreItem(object selectedItem, List <ParamInfo> inputParams, List <ParamInfo> outputParams)
        {
            // Finally Set the item
            SetItem(selectedItem, false);

            // Make sure that saved selection is copied over
            if (inputParams != null)
            {
                SelectInputs(inputParams.GroupBy(x => x.Name).Select(g => g.First()).ToDictionary(x => x.Name, x => x.IsSelected));
            }
            if (outputParams != null)
            {
                SelectOutputs(outputParams.GroupBy(x => x.Name).Select(g => g.First()).ToDictionary(x => x.Name, x => x.IsSelected));
            }

            // Look for changes
            CallerUpdate update = new CallerUpdate
            {
                Cause           = CallerUpdateCause.ReadFromSave,
                ComponentUpdate = new ComponentUpdate {
                    Name = Name, Description = Description
                },
                InputUpdates  = InputParams.Changes(inputParams).Where(x => x.Param.IsSelected).ToList(),
                OutputUpdates = OutputParams.Changes(outputParams).Where(x => x.Param.IsSelected).ToList()
            };

            // Record warnings if changes happened
            List <IParamUpdate> paramUpdates = update.InputUpdates.Concat(update.OutputUpdates).ToList();

            if (paramUpdates.Count > 0)
            {
                Engine.Reflection.Compute.RecordWarning("This component was upgraded. Here's the resulting changes: \n"
                                                        + paramUpdates.Select(x => "  - " + x.IToText()).Aggregate((a, b) => a + "\n" + b));
            }

            // Send the notification
            MarkAsModified(update);

            return(true);
        }
Esempio n. 10
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public bool CollectOutputTypes(List <object> objects = null)
        {
            if (objects == null)
            {
                objects = m_DataAccessor.GetAllData(0);
            }

            // Do not update if the list of input is empty or if user has manually selected outputs
            if (objects.Count == 0)
            {
                return(false);
            }

            // Save old outputs
            List <ParamInfo> oldOutputs = OutputParams.ToList();

            // Collect the new output params
            OutputParams = Engine.UI.Query.OutputParams(objects);

            // Compile the setters
            CompileOutputSetters();

            // Create the output menu
            SetOutputSelectionMenu();

            // Mark as modified if output have changed
            List <IParamUpdate> changes = OutputParams.Changes(oldOutputs).Where(x => x.Param.IsSelected).ToList();

            if (changes.Count > 0)
            {
                MarkAsModified(new CallerUpdate {
                    Cause = CallerUpdateCause.ItemSelected, OutputUpdates = changes
                });
            }

            return(true);
        }
        private static OutputParams InterativeAskReturnedCode(InputsForFakeWindow value, int errorCode)
        {
            //Here ask the user the returned code.
            // YES : do as if the execution worked well
            //NO : simulate that there were an error in the process
            System.Windows.MessageBoxResult res = System.Windows.MessageBox.Show("Press \"YES\" to return error code == 0 (no error during execution)" + Environment.NewLine + " or " + Environment.NewLine + "press \"NO\" to return error code == " + errorCode + " (simulate that an error occured during execution)", "Question", System.Windows.MessageBoxButton.YesNo);

            OutputParams outp;

            switch (res)
            {
            case System.Windows.MessageBoxResult.OK:
                outp = new OutputParams(0, value);
                break;

            case System.Windows.MessageBoxResult.Yes:
                outp = new OutputParams(0, value);
                break;

            default:
                throw new Exception("User decided to return the error code " + errorCode + " by clicking on the \"NO\" button");
            }
            return(outp);
        }
 protected override void GetOutputsOfExecutedSkill(ExecutableSkill SkillExecuted, OutputParams OutputOfExecution)
 {
     switch (SkillExecuted.AmlSkillDescription.Execution.Type)
     {
     default:
         //In our case, whatever the skill type, we will execute the same method
         Console.WriteLine("==========================================================================================================");
         Console.WriteLine("Returned code of skill " + SkillExecuted.AmlSkillDescription.ID + " is " + OutputOfExecution.ReturnCode);
         Console.WriteLine("==========================================================================================================");
         break;
     }
 }
Esempio n. 13
0
File: Pro2Calc.cs Progetto: x893/WDS
 private bool ParseOutputFile(string path, out OutputParams output)
 {
     bool flag = false;
     output = new OutputParams();
     try
     {
         using (StreamReader reader = new StreamReader(path))
         {
             for (string str = reader.ReadLine(); str != null; str = reader.ReadLine())
             {
                 str = str.Trim();
                 if (str.StartsWith("set"))
                 {
                     string[] strArray = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                     if (strArray.Length == 3)
                     {
                         string name = strArray[1];
                         byte result = 0;
                         if (strArray[2].StartsWith("0x"))
                         {
                             strArray[2] = strArray[2].Remove(0, 2);
                         }
                         if (!byte.TryParse(strArray[2], NumberStyles.HexNumber, (IFormatProvider) null, out result))
                         {
                             return flag;
                         }
                         output.propertyValues.Add(new PropertyValuePair(name, result));
                     }
                 }
             }
         }
         try
         {
             string str3 = Path.Combine(Path.GetDirectoryName(path), "modem_params.h");
             if (File.Exists(str3))
             {
                 this.HeaderFileContent = File.ReadAllText(str3);
             }
         }
         catch
         {
         }
         try
         {
             string str4 = Path.Combine(Path.GetDirectoryName(path), "calc_log.txt");
             if (File.Exists(str4))
             {
                 this.LogFileContent = File.ReadAllText(str4);
             }
         }
         catch
         {
         }
         flag = true;
     }
     catch (Exception exception)
     {
         exception.ToString();
     }
     return flag;
 }
        private OutputParams ProcessWindow(InputParams inputs, ref bool SkillIsPausable)
        {
            //This is the implementation of the "first" Method provided to the Skills (the "process method")

            //Remark : this method is quite complicated because it has to deal with windows and HMI, so it requires access to the UI thread.

            //Skill is currently not pausable
            SkillIsPausable = false;
            InputsForFakeWindow value;

            //First cast the inputs
            try
            {
                value = (InputsForFakeWindow)inputs.Values;
            }
            catch (System.InvalidCastException ex)
            {
                //If you can't cast the inputs, then there is a special error code for this
                return(new OutputParams(Skill.ERROR_VALUES_PROCESS_INVALID, null));
            }

            //Then execute the code

            try
            {
                //Lets say skill is productive (even if it is not that true)
                inputs.IsProductive = true;

                //Update remaining time
                value.RemainingTimeMs = value.ExecutionTimeMs;

                inputs.RemainingDuration = (UInt32)value.RemainingTimeMs;

                //First Ask (the UI thread) to pop a new window
                InputsForFakeWindow argsFirst = new InputsForFakeWindow()
                {
                    StartANewWindow = true,
                    RemainingTimeMs = value.RemainingTimeMs,
                    CloseTheWindow  = false,
                    ExecutionTimeMs = value.ExecutionTimeMs,
                    NameOfSkill     = value.NameOfSkill,
                    Status          = "EXECUTING"
                };

                OnDisplayOnSkillWindow(argsFirst);


                //Then perform a loop, each second, after each second
                int subdivision = value.ExecutionTimeMs / 1000;

                //You can subscribe to the "Pausing" event, if you want to have notification of the Pausing.
                //The SEE mother class also subscribed to that event, to notify the OPC-UA about the state change
                inputs.Pausing += inputs_Pausing;

                if (subdivision >= 1)
                {
                    //SKill is now pausable => turn SkillIsPausable to true
                    SkillIsPausable = true;

                    //there are more than 1 second of execution time
                    for (int i = 0; i < subdivision; i++)
                    {
                        double remainingTime = (((double)value.ExecutionTimeMs) - i * 1000.0);

                        inputs.StopOrPauseIfRequired(); //You can use this line of code to block or stop the execution, if a Stop or pause was required

                        InputsForFakeWindow argsLoop = new InputsForFakeWindow()
                        {
                            StartANewWindow = false,
                            RemainingTimeMs = (int)remainingTime,
                            CloseTheWindow  = false,
                            ExecutionTimeMs = value.ExecutionTimeMs,
                            NameOfSkill     = value.NameOfSkill,
                            Status          = "EXECUTING"
                        };

                        OnDisplayOnSkillWindow(argsLoop);

                        //Update remaining time before sleeping
                        inputs.RemainingDuration = (UInt32)remainingTime;

                        //Sleep 1s
                        System.Threading.Thread.Sleep(1000);

                        inputs.StopOrPauseIfRequired(); //You can use this line of code to block or stop the execution, if a Stop or pause was required
                    }

                    double LastValue = (((double)value.ExecutionTimeMs) - subdivision * 1000.0);

                    inputs.StopOrPauseIfRequired(); //You can use this line of code to block or stop the execution, if a Stop or pause was required

                    InputsForFakeWindow argsLastLoop = new InputsForFakeWindow()
                    {
                        StartANewWindow = false,
                        RemainingTimeMs = (int)LastValue,
                        CloseTheWindow  = false,
                        ExecutionTimeMs = value.ExecutionTimeMs,
                        NameOfSkill     = value.NameOfSkill,
                        Status          = "EXECUTING"
                    };

                    OnDisplayOnSkillWindow(argsLastLoop);

                    //SKill is no longer pausable => turn SkillIsPausable to false
                    SkillIsPausable = false;
                    inputs.StopOrPauseIfRequired();
                    inputs.Pausing -= inputs_Pausing;

                    //Update remaining time before sleeping
                    inputs.RemainingDuration = (UInt32)LastValue;

                    //Sleep the remaining time
                    System.Threading.Thread.Sleep((int)LastValue);
                }
                else
                {
                    //there are Less than 1 second of execution time

                    //SKill is now pausable => turn SkillIsPausable to true
                    SkillIsPausable = true;
                    inputs.StopOrPauseIfRequired();//You can use this line of code to block or stop the execution, if a Stop or pause was required

                    InputsForFakeWindow argsLess1 = new InputsForFakeWindow()
                    {
                        StartANewWindow = false,
                        RemainingTimeMs = value.ExecutionTimeMs,
                        CloseTheWindow  = false,
                        ExecutionTimeMs = value.ExecutionTimeMs,
                        NameOfSkill     = value.NameOfSkill,
                        Status          = "EXECUTING"
                    };

                    OnDisplayOnSkillWindow(argsLess1);

                    //SKill is no longer pausable => turn SkillIsPausable to false
                    SkillIsPausable = false;
                    inputs.StopOrPauseIfRequired();
                    inputs.Pausing -= inputs_Pausing;

                    //Update remaining time before sleeping
                    inputs.RemainingDuration = (UInt32)value.ExecutionTimeMs;

                    //Sleep
                    System.Threading.Thread.Sleep(value.ExecutionTimeMs);
                }


                //Display that skill execution is about to finish

                InputsForFakeWindow argsAboutToClose = new InputsForFakeWindow()
                {
                    StartANewWindow = false,
                    RemainingTimeMs = 0,
                    CloseTheWindow  = false,
                    ExecutionTimeMs = value.ExecutionTimeMs,
                    NameOfSkill     = value.NameOfSkill,
                    Status          = "ABOUT TO FINISH : ANSWER QUESTION FIRST"
                };

                OnDisplayOnSkillWindow(argsAboutToClose);


                //Then finnaly, you have to prepare the "OutputParams".
                //These "OutputParams" then returned in the overriden method GetOutputsOfExecutedSkill
                //So take care of what you are providing

                OutputParams outp = InterativeAskReturnedCode(value, ERROR_DURING_EXECUTION);

                InputsForFakeWindow argsClose = new InputsForFakeWindow()
                {
                    StartANewWindow = false,
                    RemainingTimeMs = 0,
                    CloseTheWindow  = false,
                    ExecutionTimeMs = value.ExecutionTimeMs,
                    NameOfSkill     = value.NameOfSkill,
                    Status          = "FINISHED"
                };

                OnDisplayOnSkillWindow(argsClose);

                //Check if you have an alternative post condition
                if (value.AlternativePostConditionAvailable && outp.ReturnCode == 0)
                {
                    //Ask user if he wants to go to alternative post condition
                    System.Windows.MessageBoxResult res = System.Windows.MessageBox.Show("Do you want to go to alternative post condition?", "Alternative", System.Windows.MessageBoxButton.YesNo);

                    switch (res)
                    {
                    case System.Windows.MessageBoxResult.Yes:
                        outp.GoToAlternativePostCondition = true;
                        break;

                    default:
                        outp.GoToAlternativePostCondition = false;
                        break;
                    }
                }

                //you don't have to Update remaining time to "0" => it is already done in the SEE mother class

                return(outp);
            }
            catch (OperationCanceledException ex)
            {
                //External element asked for "emergency stop".
                //The "Closing Method" will be called (second method passed to the constructor of the skill)

                //You can do some memory freeing here.

                //And then, rethrow the exception
                throw;
            }
            catch (Exception ex)
            {
                return(new OutputParams(ERROR_DURING_EXECUTION, null, false, new SkillProException(ex.Message, ex)));
            }
        }
Esempio n. 15
0
 internal void AddOutParam(ZclValue parameter)
 {
     OutputParams.Add(parameter);
 }
        protected override void GetOutputsOfExecutedSkill(ExecutableSkill SkillExecuted, OutputParams OutputOfExecution)
        {
            //Here you will receive the outputs of the executed skills (in our case, the outputs of "ProcessWindow" or "CloseWindow")

            //So here you will do everything required specifically to your SEE
            //like updating a database, displaying something on a human/machine interface, logging, beeping...

            //but you can also do nothing, if you don't care about the outputs, or maybe you did everyhting in the Skill methods allready

            //So here is a common way of processing your outputs

            //Check that your outputs are OK
            if (SkillExecuted == null)
            {
                System.Windows.MessageBox.Show("SkillExecuted is null");
                return;
            }

            if (SkillExecuted.AmlSkillDescription.Name == null)
            {
                System.Windows.MessageBox.Show("Name of SkillExecuted is null");
                return;
            }

            if (OutputOfExecution == null)
            {
                System.Windows.MessageBox.Show("Outputs of skill " + SkillExecuted.AmlSkillDescription.Name + "  are null");
                return;
            }

            //Display the return code of the Skill.
            System.Windows.MessageBox.Show("Skill " + SkillExecuted.AmlSkillDescription.Name + "  returned code " + OutputOfExecution.ReturnCode.ToString());
            return;
        }
Esempio n. 17
0
        public static void Public_NWM_SReceiptPermanent(string baseUrl, AuthenticationHeaderValue ahv,
                                                        string authTokenFilePath, InputParams inputParams)
        {
            try
            {
                string     authToken = TokenTools.GetAuthToken(authTokenFilePath);
                HttpClient client    = new HttpClient();
                client.DefaultRequestHeaders.Authorization = ahv;
                client.BaseAddress = new Uri(baseUrl);
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"));
                client.DefaultRequestHeaders.Add("AuthToken", authToken);


                HttpResponseMessage response =
                    client.PostAsJsonAsync("services/PublicNWMSReceiptPermanent", inputParams).Result;
                string result     = response.Content.ReadAsStringAsync().Result;
                var    statusCode = response.StatusCode;
                if (statusCode == HttpStatusCode.OK)
                {
                    OutputParams output        = JsonConvert.DeserializeObject <OutputParams>(result);
                    string       error_code    = output.error_code;
                    string       error_message = output.error_message;
                    output = response.Content.ReadAsAsync <OutputParams>().Result;

                    if (response.IsSuccessStatusCode)
                    {
                        // print results
                        Console.WriteLine($"city: {output.city}");
                        Console.WriteLine($"province: {output.province}");
                        Console.WriteLine($"township: {output.township}");
                        Console.WriteLine($"contractor_name: {output.contractor_name}");
                        Console.WriteLine($"contractor_national_id: {output.contractor_national_id}");
                        Console.WriteLine($"create_date: {output.create_date}");
                        Console.WriteLine($"creator: {output.creator}");
                        Console.WriteLine($"warehouse_id: {output.warehouse_id}");
                        Console.WriteLine($"id: {output.id}");
                        Console.WriteLine($"owner_name: {output.owner_name}");
                        Console.WriteLine($"postal_code: {output.postal_code}");
                        Console.WriteLine($"receipt items:");
                        output.receipt_items.ForEach(delegate(ReceiptItemResponse rcp_item_resp)
                        {
                            Console.WriteLine($"\tid: {rcp_item_resp.id}");
                            Console.WriteLine($"\tgood_id: {rcp_item_resp.good_id}");
                            Console.WriteLine($"\tgood_desc: {rcp_item_resp.good_desc}");
                            Console.WriteLine("");
                        });
                    }
                    else
                    {
                        // error
                        Console.WriteLine($"status code:{statusCode}");

                        Console.WriteLine($"error_code: {output.error_code}");
                        Console.WriteLine($"error_message: {output.error_message}");
                        Console.WriteLine($"failed_condition: {output.failed_condition}");
                        Console.WriteLine($"failed_item: {output.failed_item}");
                        Console.WriteLine($"error_detail: {output.error_detail}");
                    }
                }
                else
                {
                    Console.WriteLine($"The Web Service {statusCode}");
                    return;
                }
            }
            catch (ApplicationException ex)
            {
                Console.WriteLine("ApplicationException");
                Console.WriteLine(ex);
            }
            catch (UnsupportedMediaTypeException ex)
            {
                Console.WriteLine("UnsupportedMediaType");
                Console.WriteLine(ex);
            }
            catch (HttpRequestException ex)
            {
                Console.WriteLine("HttpRequestException");
                Console.WriteLine(ex);
            }
            catch (AggregateException ex)
            {
                Console.WriteLine("AggregateException");
                Console.WriteLine(ex);
            }
        }
        private OutputParams MethodHelloWorldAndQuestions(InputParams inputs, ref bool SkillIsPausable)
        {
            SkillIsPausable = false;
            ValuesForSee value;

            //First cast the inputs
            try
            {
                value = (ValuesForSee)inputs.Values;
            }
            catch (System.InvalidCastException ex)
            {
                //If you can't cast the inputs, then there is a special error code for this
                return(new OutputParams(Skill.ERROR_VALUES_PROCESS_INVALID, null));
            }

            //Then execute the code
            try
            {
                //Lets say skill is productive (even if it is not that true)
                inputs.IsProductive = true;

                //Let's say the skill needs 3000ms to execute (because of the question)
                inputs.RemainingDuration = 3000;

                Console.WriteLine("==========================================================================================================");
                Console.WriteLine(inputs.ToString());
                Console.WriteLine("==========================================================================================================");

                OutputParams outputs = InterativeAskReturnedCode(inputs, -301);

                //Check if you have an alternative post condition
                if (value.AlternativePostConditionAvailable && outputs.ReturnCode == 0)
                {
                    //Ask user if he wants to go to alternative post condition
                    System.Windows.MessageBoxResult res = System.Windows.MessageBox.Show("Do you want to go to alternative post condition?", "Alternative", System.Windows.MessageBoxButton.YesNo);

                    switch (res)
                    {
                    case System.Windows.MessageBoxResult.Yes:
                        outputs.GoToAlternativePostCondition = true;
                        break;

                    default:
                        outputs.GoToAlternativePostCondition = false;
                        break;
                    }
                }

                //you don't have to Update remaining time to "0" => it is already done in the SEE mother class

                return(outputs);
            }
            catch (OperationCanceledException ex)
            {
                //External element asked for "emergency stop".
                //The "Closing Method" will be called (second method passed to the constructor of the skill)

                //You can do some memory freeing here.
                Console.WriteLine("==========================================================================================================");
                Console.WriteLine("emergency stop");
                Console.WriteLine("==========================================================================================================");


                //And then, rethrow the exception
                throw;
            }
            catch (Exception ex)
            {
                //Your user code, which starts at -300
                return(new OutputParams(-301, null, false, new SkillProException(ex.Message, ex)));
            }
        }
Esempio n. 19
0
File: Pro2Calc.cs Progetto: x893/WDS
 public Result Calculate(out OutputParams regularOutput, out OutputParams iqOutput, out string inputFile)
 {
     Result success = Result.Success;
     regularOutput = null;
     iqOutput = null;
     inputFile = "";
     if (!Directory.Exists(this.TempFolder))
     {
         Directory.CreateDirectory(this.TempFolder);
     }
     if ((success == Result.Success) && !this.ExtractCalculator(Path.Combine(this.TempFolder, this.Input.IqCalibrationNeeded ? "pro2_calc_IQcal.exe" : "Pro2_calc.exe")))
     {
         success = Result.FailedExtractingCalculator;
     }
     if ((success == Result.Success) && !this.GenerateInputFile(Path.Combine(this.TempFolder, "Pro2_parameters.txt"), out inputFile))
     {
         success = Result.FailedGeneratingInputFile;
     }
     if ((success == Result.Success) && !this.RunCalculator(Path.Combine(this.TempFolder, this.Input.IqCalibrationNeeded ? "pro2_calc_IQcal.exe" : "Pro2_calc.exe"), Path.Combine(this.TempFolder, "Pro2_parameters.txt")))
     {
         success = Result.FailedRunningCalculator;
     }
     if (((success == Result.Success) && this.Input.IqCalibrationNeeded) && !this.ParseOutputFile(Path.Combine(this.TempFolder, this.FILE_NAME_IQ_OUTPUT), out iqOutput))
     {
         success = Result.FailedParsingOutputFile;
     }
     if ((success == Result.Success) && !this.ParseOutputFile(Path.Combine(this.TempFolder, this.FILE_NAME_REGULAR_OUTPUT), out regularOutput))
     {
         success = Result.FailedParsingOutputFile;
     }
     return success;
 }
        protected override void GetOutputsOfExecutedSkill(ExecutableSkill SkillExecuted, OutputParams OutputOfExecution)
        {
            //Here you will receive the outputs of the executed skills (in our case, the outputs of "MethodHelloWorld" or "MethodStop"

            //So here you will do everything required specifically to your SEE
            //like updating a database, displaying something on a human/machine interface, logging, beeping...

            //but you can also do nothing, if you don't care about the outputs, or maybe you did everyhting in the Skill methods allready

            //Here, do a big switch case on the Execution's type of the skill.
            //In our case, just print the returned code of skill

            switch (SkillExecuted.AmlSkillDescription.Execution.Type)
            {
            default:
                //In our case, whatever the skill type, we will execute the same method
                Console.WriteLine("==========================================================================================================");
                Console.WriteLine("Returned code of skill " + SkillExecuted.AmlSkillDescription.ID + " is " + OutputOfExecution.ReturnCode);
                Console.WriteLine("==========================================================================================================");
                break;
            }

            //You can throw an exeception if something does not suits you => the SEE will go in error state
        }