Esempio n. 1
0
        /// <summary>
        ///     Sets the value of a specific variable
        /// </summary>
        /// <param name="variableName"></param>
        /// <param name="value"></param>
        public void SetVariableValue(string variableName, Value value)
        {
            EfsAccess.WaitOne();
            try
            {
                if (Runner != null)
                {
                    IVariable variable = EfsSystem.Instance.FindByFullName(variableName) as IVariable;

                    if (variable != null)
                    {
                        Util.DontNotify(() =>
                        {
                            Runner.CacheImpact = new CacheImpact();
                            SyntheticVariableUpdateAction action = new SyntheticVariableUpdateAction(variable,
                                                                                                     value.ConvertBack(variable.Type));
                            VariableUpdate variableUpdate = new VariableUpdate(action, null, null);
                            Runner.EventTimeLine.AddModelEvent(variableUpdate, true);
                            Runner.ClearCaches();
                        });
                    }
                    else
                    {
                        throw new FaultException <EFSServiceFault> (
                                  new EFSServiceFault("Cannot find variable " + variableName),
                                  new FaultReason(new FaultReasonText("Cannot find variable " + variableName)));
                    }
                }
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Saves the dictionary according to its filename
        /// </summary>
        public void Save()
        {
            Util.DontNotify(() =>
            {
                if (Watcher != null)
                {
                    Watcher.StopWatching();
                }

                Updater updater = new Updater(true);
                updater.visit(this);

                VersionedWriter writer = new VersionedWriter(FilePath);
                unParse(writer, false);
                writer.Close();

                updater = new Updater(false);
                updater.visit(this);

                if (Watcher != null)
                {
                    Watcher.StartWatching();
                }

                foreach (DeleteFilesHandler file in FilesToDelete)
                {
                    file.DeleteFile();
                }
                FilesToDelete.Clear();
            });
        }
Esempio n. 3
0
        /// <summary>
        ///     Provides the value of an expression
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Value GetExpressionValue(string expression)
        {
            Value retVal = null;

            EfsAccess.WaitOne();
            try
            {
                Expression expressionTree = new Parser().Expression(EfsSystem.Instance.Dictionaries[0],
                                                                    expression);
                if (expressionTree != null)
                {
                    Util.DontNotify(() =>
                    {
                        retVal =
                            ConvertOut(expressionTree.GetExpressionValue(new InterpretationContext(), null));
                    });
                }
            }
            catch (Exception)
            {
                // TODO
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }

            return(retVal);
        }
Esempio n. 4
0
        /// <summary>
        ///     Creates a default element
        /// </summary>
        /// <param name="enclosingCollection"></param>
        /// <returns></returns>
        public static Parameter CreateDefault(ICollection enclosingCollection)
        {
            Parameter retVal = (Parameter)acceptor.getFactory().createParameter();

            Util.DontNotify(() => { retVal.Name = "Parameter" + GetElementNumber(enclosingCollection); });

            return(retVal);
        }
Esempio n. 5
0
 /// <summary>
 ///     Sets the default values for the element provided as parameter
 /// </summary>
 /// <param name="model"></param>
 public void SetDefaultValue <T>(T model)
     where T : IXmlBBase
 {
     // We are creating a new element, notification about changes in that element
     // are not necessary.
     Util.DontNotify(() =>
     {
         // ReSharper disable once ConvertToLambdaExpression
         dispatch(model);
     });
 }
Esempio n. 6
0
 /// <summary>
 ///     Step once
 /// </summary>
 public void StepOnce()
 {
     Util.DontNotify(() =>
     {
         CheckRunner();
         if (EfsSystem.Runner != null)
         {
             EfsSystem.Runner.StepOnce();
             EfsSystem.Instance.Context.HandleEndOfCycle();
         }
     });
 }
Esempio n. 7
0
        /// <summary>
        ///     Checks the model for unused element
        /// </summary>
        public void CheckDeadModel()
        {
            Util.DontNotify(() =>
            {
                // Rebuilds everything
                EFSSystem.Compiler.Compile_Synchronous(EFSSystem.ShouldRebuild);
                EFSSystem.ShouldRebuild = false;

                // Check dead model
                UsageChecker visitor = new UsageChecker(this);
                visitor.visit(this, true);
            });
        }
Esempio n. 8
0
        /// <summary>
        ///     Update the information stored in the position handler according to the test case
        /// </summary>
        protected override void UpdatePositionHandler()
        {
            Util.DontNotify(() =>
            {
                PositionHandler.CleanPositions();
                if ((TestCase != null) || SubSequence != null)
                {
                    double currentTime = 0.0;
                    foreach (Step step in Steps)
                    {
                        if (step.SubSteps.Count > 0)
                        {
                            foreach (SubStep subStep in step.SubSteps)
                            {
                                PositionSubStep(currentTime, subStep);
                                currentTime += 1;
                            }
                        }
                        else
                        {
                            StepActivation stepActivated = new StepActivation(step)
                            {
                                Time = currentTime
                            };
                            PositionHandler.RegisterEvent(stepActivated);
                            currentTime += 1;
                        }
                    }
                }
                else if (Translation != null)
                {
                    double currentTime = 0.0;
                    if (Translation.SubSteps.Count > 0)
                    {
                        foreach (SubStep subStep in Translation.SubSteps)
                        {
                            PositionSubStep(currentTime, subStep);
                            currentTime += 1;
                        }
                    }
                }
            });

            base.UpdatePositionHandler();
        }
Esempio n. 9
0
        /// <summary>
        ///     Checks the rules stored in the dictionary
        /// </summary>
        public void CheckRules()
        {
            Util.DontNotify(() =>
            {
                try
                {
                    // Rebuilds everything
                    EFSSystem.Compiler.Compile_Synchronous(EFSSystem.ShouldRebuild);
                    EFSSystem.ShouldRebuild = false;

                    // Check rules
                    RuleCheckerVisitor visitor = new RuleCheckerVisitor(this);
                    visitor.visit(this, true);
                }
                catch (Exception)
                {
                }
            });
        }
Esempio n. 10
0
        /// <summary>
        ///     Duplicates the model element and avoid duplicated GUID
        /// </summary>
        /// <returns></returns>
        public ModelElement Duplicate()
        {
            ModelElement retVal = null;

            Util.DontNotify(() =>
            {
                XmlBStringContext ctxt = new XmlBStringContext(ToXMLString());
                try
                {
                    retVal = acceptor.accept(ctxt) as ModelElement;
                    RegererateGuidVisitor visitor = new RegererateGuidVisitor();
                    visitor.visit(retVal, true);
                }
                catch (Exception)
                {
                }
            });

            return(retVal);
        }
Esempio n. 11
0
        /// <summary>
        ///     Refreshes the model of the tree view
        /// </summary>
        /// <param name="modifiedElement">The element that has been modified</param>
        public void RefreshModel(IModelElement modifiedElement)
        {
            BaseTreeNode selected = Selected;

            Util.DontNotify(() =>
            {
                try
                {
                    SuspendLayout();

                    // Ensure the root nodes are correct
                    List <BaseTreeNode> rootNodes = BuildModel();
                    if (rootNodes.Count != Nodes.Count)
                    {
                        Nodes.Clear();
                        foreach (BaseTreeNode node in rootNodes)
                        {
                            Nodes.Add(node);
                        }
                    }

                    // Refresh the selected node
                    foreach (BaseTreeNode node in Nodes)
                    {
                        if (modifiedElement == null || (node.Model != null && node.Model.IsParent(modifiedElement)))
                        {
                            node.BuildOrRefreshSubNodes(modifiedElement);
                        }
                    }

                    if (selected != null)
                    {
                        Select(selected.Model);
                    }
                }
                finally
                {
                    ResumeLayout(true);
                }
            });
        }
Esempio n. 12
0
 /// <summary>
 ///     Do not raise errors while execution the action
 /// </summary>
 /// <param name="silent">Indicates that the action should be silent</param>
 /// <param name="action"></param>
 public static void DontRaiseError(bool silent, SilentAction action)
 {
     // Heuristic :
     // Do not notify changes in the model when we are not interested
     // in the errors raised while performing the action
     Util.DontNotify(() =>
     {
         if (silent)
         {
             try
             {
                 SilentCount += 1;
                 if (SilentCount == 1)
                 {
                     BeSilent = true;
                     action();
                 }
                 else
                 {
                     action();
                 }
             }
             finally
             {
                 SilentCount -= 1;
                 if (SilentCount == 0)
                 {
                     BeSilent = false;
                 }
             }
         }
         else
         {
             action();
         }
     });
 }
Esempio n. 13
0
        /// <summary>
        ///     Applies a specific statement on the model
        /// </summary>
        /// <param name="statementText"></param>
        public void ApplyStatement(string statementText)
        {
            EfsAccess.WaitOne();
            try
            {
                if (Runner != null)
                {
                    const bool silent = true;
                    using (Parser parser = new Parser())
                    {
                        Statement statement = parser.Statement(EfsSystem.Instance.Dictionaries[0],
                                                               statementText, silent);

                        if (statement != null)
                        {
                            Util.DontNotify(() =>
                            {
                                Runner.CacheImpact            = new CacheImpact();
                                Action action                 = (Action)acceptor.getFactory().createAction();
                                action.ExpressionText         = statementText;
                                VariableUpdate variableUpdate = new VariableUpdate(action, null, null);
                                Runner.EventTimeLine.AddModelEvent(variableUpdate, true);
                                Runner.ClearCaches();
                            });
                        }
                    }
                }
            }
            catch (Exception)
            {
                // TODO
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }
        }
Esempio n. 14
0
        /// <summary>
        ///     Handles the move event, which, in case of an arrow is selected to be modified,
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        private void HandleMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            GraphicElement element = ElementForLocation(mouseEventArgs.Location, null);

            if (element != null)
            {
                element.HandleMouseMove(sender, mouseEventArgs);
            }

            if (_changingArrow != null && _chaningArrowAction != ChangeAction.None)
            {
                BoxControl <TEnclosing, TBoxModel, TArrowModel> box = BoxForLocation(mouseEventArgs.Location, null);
                if (box != null)
                {
                    switch (_chaningArrowAction)
                    {
                    case ChangeAction.InitialBox:
                        if (_changingArrow.TypedModel.Source != box.Model)
                        {
                            _changingArrow.SetInitialBox(box.TypedModel);
                        }
                        break;

                    case ChangeAction.TargetBox:
                        if (_changingArrow.TypedModel.Target != box.Model)
                        {
                            if (_changingArrow.TypedModel.Source != null)
                            {
                                _changingArrow.SetTargetBox(box.TypedModel);
                            }
                        }
                        break;
                    }
                }
            }

            if (_movingBox != null)
            {
                Point mouseMoveLocation = mouseEventArgs.Location;

                int deltaX = mouseMoveLocation.X - _moveStartLocation.X;
                int deltaY = mouseMoveLocation.Y - _moveStartLocation.Y;

                if (Math.Abs(deltaX) > 5 || Math.Abs(deltaY) > 5)
                {
                    IModelElement model = _movingBox.TypedModel;
                    if (model != null && !_movingBoxHasMoved)
                    {
                        Context.SelectionCriteria criteria = GuiUtils.SelectionCriteriaBasedOnMouseEvent(mouseEventArgs);
                        EfsSystem.Instance.Context.SelectElement(model, this, criteria);
                        _movingBoxHasMoved = true;
                    }

                    Util.DontNotify(() =>
                    {
                        int newX = _positionBeforeMove.X + deltaX;
                        int newY = _positionBeforeMove.Y + deltaY;
                        SetBoxPosition(_movingBox, newX, newY);
                        UpdatePositions();
                    });
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        ///     Performs a single cycle
        /// </summary>
        public void Cycle()
        {
            EfsAccess.WaitOne();

            try
            {
                DateTime now = DateTime.Now;

                // Close inactive connections
                foreach (ConnectionStatus status in Connections)
                {
                    TimeSpan delta = now - status.LastCycleRequest;
                    if (delta > MaxDelta && !status.Suspended)
                    {
                        status.Active = false;
                    }
                }

                // Launches the runner when all active client have selected their next step
                while (CheckLaunch())
                {
                    LastStep = NextStep(LastStep);

                    if (Runner != null)
                    {
                        try
                        {
                            if (!AllListeners)
                            {
                                Util.DontNotify(() =>
                                {
                                    Runner.ExecuteOnePriority(convertStep2Priority(LastStep));
                                    if (LastStep == Step.CleanUp)
                                    {
                                        EfsSystem.Instance.Context.HandleEndOfCycle();
                                        ClearFunctionCaches();
                                    }
                                });
                            }
                        }
                        catch (Exception)
                        {
                            // Ignore
                        }
                    }

                    while (PendingClients(LastStep))
                    {
                        // Let the processes waiting for the end of this step run
                        StepAccess[LastStep].ReleaseMutex();
                        EfsAccess.ReleaseMutex();

                        // Let the other processes wake up
                        Thread.Sleep(1);

                        // Wait until all processes for this step have executed their work
                        StepAccess[LastStep].WaitOne();
                        EfsAccess.WaitOne();
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }
        }
Esempio n. 16
0
        /// <summary>
        ///     Displays the graph
        /// </summary>
        /// <returns></returns>
        public void Display()
        {
            Util.DontNotify(() =>
            {
                GraphVisualiser.Reset();
                String name = null;

                // Computes the expected end to display
                double expectedEndX = 0;
                Dictionary <Function, Graph> graphs = new Dictionary <Function, Graph>();
                foreach (Function function in Functions)
                {
                    InterpretationContext context = new InterpretationContext(function);
                    if (function.FormalParameters.Count == 1)
                    {
                        Parameter parameter = (Parameter)function.FormalParameters[0];
                        Graph graph         = function.CreateGraph(context, parameter, null);
                        if (graph != null)
                        {
                            expectedEndX = Math.Max(expectedEndX, graph.ExpectedEndX());
                            graphs.Add(function, graph);
                        }
                    }
                }

                double expectedEndY = 0;
                Dictionary <Function, Surface> surfaces = new Dictionary <Function, Surface>();
                foreach (Function function in Functions)
                {
                    InterpretationContext context = new InterpretationContext(function);
                    if (function.FormalParameters.Count == 2)
                    {
                        Surface surface = function.CreateSurface(context, null);
                        if (surface != null)
                        {
                            expectedEndX = Math.Max(expectedEndX, surface.ExpectedEndX());
                            expectedEndY = Math.Max(expectedEndY, surface.ExpectedEndY());
                            surfaces.Add(function, surface);
                        }
                    }
                }

                try
                {
                    int maxX     = Int32.Parse(Tb_MaxX.Text);
                    expectedEndX = Math.Min(expectedEndX, maxX);
                }
                catch (Exception)
                {
                }

                // Creates the graphs
                foreach (KeyValuePair <Function, Graph> pair in graphs)
                {
                    Function function = pair.Key;
                    Graph graph       = pair.Value;

                    if (function != null && graph != null)
                    {
                        EfsProfileFunction efsProfileFunction = new EfsProfileFunction(graph);
                        if (function.Name.Contains("Gradient"))
                        {
                            GraphVisualiser.AddGraph(new EfsGradientProfileGraph(GraphVisualiser, efsProfileFunction,
                                                                                 function.FullName));
                        }
                        else
                        {
                            GraphVisualiser.AddGraph(new EfsProfileFunctionGraph(GraphVisualiser, efsProfileFunction,
                                                                                 function.FullName));
                        }

                        if (name == null)
                        {
                            name = function.Name;
                        }
                    }
                }

                // Creates the surfaces
                foreach (KeyValuePair <Function, Surface> pair in surfaces)
                {
                    Function function = pair.Key;
                    Surface surface   = pair.Value;

                    if (surface != null)
                    {
                        EfsSurfaceFunction efsSurfaceFunction = new EfsSurfaceFunction(surface);
                        GraphVisualiser.AddGraph(new EfsSurfaceFunctionGraph(GraphVisualiser, efsSurfaceFunction,
                                                                             function.FullName));
                        if (name == null)
                        {
                            name = function.Name;
                        }
                    }
                }

                Train train = new Train(GraphVisualiser);
                train.InitializeTrain(TrainPosition.GetDistance(), TrainPosition.GetSpeed(), TrainPosition.GetUnderReadingAmount(), TrainPosition.GetOverReadingAmount());
                GraphVisualiser.AddGraph(train);
                GraphVisualiser.Annotations.Add(train.TrainLineAnnotation);
                GraphVisualiser.Annotations.Add(train.TrainAnnotation);

                if (name != null)
                {
                    try
                    {
                        double val = double.Parse(Tb_MinX.Text);
                        GraphVisualiser.SetMinX(val);
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        double val = double.Parse(Tb_MaxX.Text);
                        GraphVisualiser.SetMaxX(val);
                    }
                    catch (Exception)
                    {
                    }

                    if (Cb_AutoYSize.Checked)
                    {
                        GraphVisualiser.SetMaxY(double.NaN);
                    }
                    else
                    {
                        double height;
                        if (double.TryParse(Tb_MaxY.Text, out height))
                        {
                            GraphVisualiser.SetMaxY(height);
                        }
                        else
                        {
                            GraphVisualiser.SetMaxY(double.NaN);
                        }
                    }

                    GraphVisualiser.SetMinY2(double.NaN);
                    GraphVisualiser.SetMaxY2(double.NaN);
                    double top, bottom;
                    if (double.TryParse(Tb_MinGrad.Text, out bottom))
                    {
                        GraphVisualiser.SetMinY2(bottom);
                    }
                    if (double.TryParse(Tb_MaxGrad.Text, out top))
                    {
                        GraphVisualiser.SetMaxY2(top);
                    }

                    GraphVisualiser.DrawGraphs(expectedEndX);
                }
            });
        }