コード例 #1
0
ファイル: HideCheckingFrom.cs プロジェクト: MinhHuong/WSN-PN
        //private string GetOption()
        //{
        //    string option = "";
        //    option += MenuButton_EnableSimplificationOfTheFormula.Checked ? "" : "l";
        //    option += MenuButton_EnableOntheflyAutomataSimplification.Checked ? "" : "o";
        //    option += MenuButton_EnableAPosterioriAutomataSimplification.Checked ? "" : "p";
        //    option += MenuButton_EnableStronglyConnectedComponentsSimplification.Checked ? "" : "c";
        //    option += MenuButton_EnableTrickingInAcceptingConditions.Checked ? "" : "a";
        //    return option;
        //}

        private SpecificationBase parseSpecification()
        {
            SpecificationBase spec = null;

            do
            {
                if (mTabItem == null || mTabItem.Text.Trim() == "")
                {
                    DevLog.e(TAG, "mTabItem is null");
                    break;
                }

                // DisableAllControls();
                try
                {
                    string moduleName = mTabItem.ModuleName;
                    if (LoadModule(moduleName))
                    {
                        //string option = GetOption();
                        Stopwatch t = new Stopwatch();
                        // DisableAllControls();
                        disableAllControls();
                        t.Start();
                        spec = mModule.ParseSpecification(mTabItem.Text, "", mTabItem.FileName);
                        t.Stop();

                        if (spec != null)
                        {
                            mTabItem.Specification = spec;
                            if (spec.Errors.Count > 0)
                            {
                                string key = "";
                                foreach (KeyValuePair <string, ParsingException> pair in spec.Errors)
                                {
                                    key = pair.Key;
                                    break;
                                }

                                ParsingException parsingException = spec.Errors[key];
                                spec.Errors.Remove(key);
                                throw parsingException;
                            }
                        }

                        // Spec = spec;
                        initLogic();
                        enableAllControls();
                        // EnableAllControls();
                    }
                }
                catch (ParsingException ex) { }
                catch (Exception ex) { }
            } while (false);

            return(spec);
        }
コード例 #2
0
        // This method is called on a worker thread (via asynchronous
        // delegate invocation).  This is where we call the operation (as
        // defined in the deriving class's DoWork method).
        public void InternalStart()
        {
            // isRunning is set during Start to avoid a race condition
            try
            {
                Spec = CurrentModule.ParseSpecification(this.Text, Options, File);

                OnReturnResult();
            }
            catch (CancelRunningException)
            {
                AcknowledgeCancel();
            }
            catch (Exception e)
            {
                // Raise the Failed event.  We're in a catch handler, so we
                // had better try not to throw another exception.
                try
                {
                    if (e is System.OutOfMemoryException)
                    {
                        e = new PAT.Common.Classes.Expressions.ExpressionClass.OutOfMemoryException("");
                    }

                    FailOperation(e);
                }
                catch
                {
                }

                // The documentation recommends not catching
                // SystemExceptions, so having notified the caller we
                // rethrow if it was one of them.
                if (e is SystemException)
                {
                    throw;
                }
            }


            lock (this)
            {
                // If the operation wasn't cancelled (or if the UI thread
                // tried to cancel it, but the method ran to completion
                // anyway before noticing the cancellation) and it
                // didn't fail with an exception, then we complete the
                // operation - if the UI thread was blocked waiting for
                // cancellation to complete it will be unblocked, and
                // the Completion event will be raised.
                if (!cancelAcknowledgedFlag && !failedFlag)
                {
                    CompleteOperation();
                }
            }
        }
コード例 #3
0
ファイル: PATService.cs プロジェクト: liyistc/trans4you
        public List <string> VerifyModel(string model)
        {
            SpecificationBase Spec             = modulebase.ParseSpecification(model, "", "");
            List <string>     RouteDescription = new List <string>();

            try
            {
                AssertionBase assertion = Spec.AssertionDatabase.Values.ElementAt(0);
                assertion.UIInitialize(null, FairnessType.NO_FAIRNESS, false, false, false, true, false, false);
                assertion.InternalStart();

                //if (assertion.VerificationOutput.VerificationResult.Equals(VerificationResultType.INVALID))
                //{
                //    RouteDescription.Add("NoSolution");
                //    return RouteDescription;
                //}
                foreach (ConfigurationBase step in assertion.VerificationOutput.CounterExampleTrace)
                {
                    if (step.Event != "init")
                    {
                        RouteDescription.Add(step.GetDisplayEvent());
                    }
                }
                return(RouteDescription);
            }
            catch (RuntimeException ex)
            {
                System.Console.Out.WriteLine("Runtime exception occurred: " + ex.Message);
                if (ex is OutOfMemoryException)
                {
                    System.Console.Out.WriteLine(
                        "This error suggests your model is too big to be verified. Please make sure all your variables are bounded. You can use domain range values to check it, e.g., \"var x:{1..100}=0;\". Alternatively you can simplify your model by using fewer events, simplier processes, and smaller constants and variables.");
                }
                else
                {
                    System.Console.Out.WriteLine("Check your input model for the possiblity of errors.");
                }
            }
            catch (Exception ex)
            {
                System.Console.Out.WriteLine("Error occurred: " + ex.Message);
            }

            return(null);
        }
コード例 #4
0
        public void Verify()
        {
            try
            {
                ModuleFacadeBase  modulebase = PAT.Common.Ultility.Ultility.LoadModule("CSP");
                SpecificationBase Spec       = modulebase.ParseSpecification(File.ReadAllText(fullModelPath), "", fullModelPath);
                string            resultMsg  = "";
                foreach (var assertion in Spec.AssertionDatabase.Values)
                {
                    Console.WriteLine("Verifying the assertion: " + assertion.ToString());
                    // Apply verification settings
                    assertion.UIInitialize(null, 0, 0);
                    //Start the verification
                    assertion.InternalStart();
                    if (assertion.VerificationOutput.VerificationResult.Equals(VerificationResultType.INVALID))
                    {
                        resultMsg += "The assertion is invalid: " + assertion.ToString() + "\n";

                        if (assertion.VerificationOutput.CounterExampleTrace != null)
                        {
                            if (assertion.VerificationOutput.CounterExampleTrace.Count > 0)
                            {
                                //Get the counterexample trace
                                resultMsg += "Counter Example Trace: ";
                                foreach (ConfigurationBase step in assertion.VerificationOutput.CounterExampleTrace)
                                {
                                    resultMsg += "->" + step.GetDisplayEvent();
                                }
                                resultMsg += "\n";
                            }
                        }
                    }
                    else if (assertion.VerificationOutput.VerificationResult.Equals(VerificationResultType.VALID))
                    {
                        resultMsg += "The assertion is valid: " + assertion.ToString() + "\n";
                    }
                    else
                    {
                        resultMsg += "The assertion could not be verified: " + assertion.ToString() + "\n";
                    }
                    resultMsg += "\n";
                }
                System.Windows.MessageBox.Show(resultMsg, "Refinement and Verification Completed!");
            }
            catch (RuntimeException ex)
            {
                string runtimeErrMsg = "Runtime exception occurred: " + ex.Message + "\n";
                //Out of memory Exception
                if (ex is OutOfMemoryException)
                {
                    runtimeErrMsg += "Model is too big, out of memory.";
                }
                else
                {
                    runtimeErrMsg += "Check your input model for the possiblity of errors.";
                }
                System.Windows.MessageBox.Show(runtimeErrMsg);
            }
            //General Exceptions
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Error occurred: " + ex.Message);
            }
        }
コード例 #5
0
        private void StartVerification(bool completed, bool correct)
        {
            FlushString();
            MCTimer.Stop();


            if (AssertionIndex == 0)
            {
                if (completed && FileIndex > 0)
                {
                    if (correct)
                    {
                        ListView_Assertions.Items[FileIndex - 1].ImageIndex = CORRECT_ICON;
                    }
                    else
                    {
                        ListView_Assertions.Items[FileIndex - 1].ImageIndex = WRONG_ICON;
                    }
                }

                if (FileIndex < ListView_Assertions.Items.Count)
                {
                    try
                    {
                        string file = ListView_Assertions.Items[FileIndex].SubItems[2].Text;
                        FileIndex++;

                        this.OutputWriter.WriteLine("*******************************************************");
                        this.OutputWriter.WriteLine("*" + file);
                        this.OutputWriter.WriteLine("**************************START************************");
                        StatusLabel_Text.Text = Resources.Checking_file_ + file;

                        StreamReader tr         = new StreamReader(file);
                        string       specString = tr.ReadToEnd();
                        tr.Close();

                        if (Spec != null)
                        {
                            Spec.UnLockSharedData();
                        }

                        string           modulefolder = Common.Utility.Utilities.ModuleFolderNames[this.ComboBox_Modules.SelectedIndex];
                        ModuleFacadeBase modulebase   = Common.Utility.Utilities.LoadModule(modulefolder);
                        Spec = modulebase.ParseSpecification(specString, "", file);

                        if (Spec != null)
                        {
                            Assertions = new List <string>(Spec.AssertionDatabase.Keys);
                        }
                        else
                        {
                            throw new Exception("ERROR Spec!");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (FileIndex > 0)
                        {
                            ListView_Assertions.Items[FileIndex - 1].ImageIndex = WRONG_ICON;
                        }
                        this.OutputWriter.WriteLine("Error occurred: " + ex.Message + "\r\n" + ex.StackTrace);
                        StartVerification(false, false);
                    }
                }
                else
                {
                    EnableAllControls();
                    return;
                }
            }


            try
            {
                if (Assertions.Count > 0)
                {
                    OutputWriter.WriteLine("=======================================================");
                    OutputWriter.WriteLine("Assertion: " + Assertions[AssertionIndex]);
                    StatusLabel_Text.Text = Resources.Verifying_Assertion__ + Assertions[AssertionIndex];
                    FlushString();

                    Assertion = Spec.AssertionDatabase[Assertions[AssertionIndex]];
                    AssertionIndex++;
                    AssertionIndex = AssertionIndex % Assertions.Count;

                    //Assertion.UIInitialize(this, Fairness, this.CheckBox_PartialOrderReduction.Checked, this.CheckBox_Verbose.Checked, this.CheckBox_Parallel.Checked, this.ShortestPath, this.CheckBox_BDD.Checked, this.CheckBox_CheckNonZenoness.Checked, GetParameters());

                    Assertion.UIInitialize(this, (int)NUD_AdmissibleBehavior.Value, (int)NUD_VerificationEngine.Value);
                    Assertion.VerificationOutput.GenerateCounterExample = CheckBox_GenerateCounterexample.Checked;

                    Assertion.Action       += OnAction;
                    Assertion.ReturnResult += VerificationFinished;
                    Assertion.Cancelled    += Verification_Cancelled;
                    Assertion.Failed       += MC_Failed;

                    seconds           = 1;
                    ProgressBar.Value = 0;
                    //timer.Reset();
                    //startMemroySize = GC.GetTotalMemory(true);
                    MCTimer.Start();
                    //timer.Start();
                    Assertion.Start();
                }
                else
                {
                    StartVerification(true, true);
                }
            }
            catch (RuntimeException e)
            {
                EnableAllControls();
                Common.Utility.Utilities.LogRuntimeException(e);
                this.Close();
                return;
            }
            catch (Exception ex)
            {
                EnableAllControls();
                Common.Utility.Utilities.LogException(ex, Spec);
                this.Close();
                return;
            }
        }
コード例 #6
0
ファイル: FormMain.cs プロジェクト: cnacha/PAT.ADL
        private SpecificationBase ParseSpecification(bool showVerbolMsg)
        {
            if (CurrentEditorTabItem == null || this.CurrentEditorTabItem.Text.Trim() == "")
            {
                if (showVerbolMsg)
                {
                    MessageBox.Show(Resources.Please_input_a_model_first_, Ultility.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(null);
            }

            DisableAllControls();
            SpecificationBase spec = null;

            try
            {
                //clear the error list
                if (!ErrorListWindow.IsDisposed)
                {
                    ErrorListWindow.Clear();
                }

                CurrentModule = new ModuleFacade();
                spec          = CurrentModule.ParseSpecification(this.CurrentEditorTabItem.Text, "",
                                                                 CurrentEditorTabItem.FileName);

                if (spec != null)
                {
                    CurrentEditorTabItem.Specification = spec;

                    if (spec.Errors.Count > 0)
                    {
                        string key = "";
                        foreach (KeyValuePair <string, ParsingException> pair in spec.Errors)
                        {
                            key = pair.Key;
                            break;
                        }
                        ParsingException parsingException = spec.Errors[key];
                        spec.Errors.Remove(key);
                        throw parsingException;
                    }

                    if (showVerbolMsg)
                    {
                        this.StatusLabel_Status.Text = Resources.Grammar_Checked;

                        MenuButton_OutputPanel.Checked = true;
                        Output_Window.TextBox.Text     = spec.GetSpecification() + "\r\n" + Output_Window.TextBox.Text;
                        Output_Window.Show(DockContainer);

                        if (spec.Warnings.Count > 0)
                        {
                            this.MenuButton_ErrorList.Checked = true;
                            ErrorListWindow.AddWarnings(spec.Warnings);

                            //ErrorListWindow.Show(DockContainer);
                            ShowErrorMessage();
                        }
                    }


                    EnableAllControls();

                    return(spec);
                }
                else
                {
                    EnableAllControls();

                    return(null);
                }
            }
            catch (ParsingException ex)
            {
                EnableAllControls();

                if (showVerbolMsg)
                {
                    if (spec != null)
                    {
                        ErrorListWindow.AddWarnings(spec.Warnings);
                        ErrorListWindow.AddErrors(spec.Errors);
                        //MenuButton_ErrorList.Checked = true;
                    }


                    CurrentEditorTabItem.HandleParsingException(ex);
                    ErrorListWindow.InsertError(ex);
                    MenuButton_ErrorList.Checked = true;

                    if (ex.Line > 0)
                    {
                        MessageBox.Show(Resources.Parsing_error_at_line_ + ex.Line + Resources._column_ + ex.CharPositionInLine + ": " + ex.Text + "\nFile:" + ex.DisplayFileName + "\n" + ex.Message, Ultility.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        MenuButton_OutputPanel.Checked  = true;
                        this.Output_Window.TextBox.Text = Resources.Parsing_error_at_line_ + ex.Line + Resources._column_ + ex.CharPositionInLine + ": " + ex.Text + "\nFile:" + ex.DisplayFileName + "\n" + ex.Message + "\r\n\r\n" + this.Output_Window.TextBox.Text; //"\n" + ex.StackTrace +
                    }
                    else
                    {
                        MessageBox.Show(Resources.Parsing_error__ + ex.Message, Ultility.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        MenuButton_OutputPanel.Checked  = true;
                        this.Output_Window.TextBox.Text = Resources.Parsing_error__ + ex.Message + "\r\n\r\n" + this.Output_Window.TextBox.Text; //"\n" + ex.StackTrace +
                    }
                    ShowErrorMessage();
                }
            }
            catch (Exception ex)
            {
                EnableAllControls();
                if (showVerbolMsg)
                {
                    MessageBox.Show(Resources.Parsing_error__ + ex.Message, Ultility.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MenuButton_OutputPanel.Checked  = true;
                    this.Output_Window.TextBox.Text = Resources.Parsing_error__ + ex.Message + "\n" + ex.StackTrace + "\r\n\r\n" + this.Output_Window.TextBox.Text;
                }
            }

            return(null);
        }