예제 #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();
            }
        }
예제 #2
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);
        }
예제 #3
0
 /// <summary>
 ///     Stops the session by closing the main window
 /// </summary>
 public void Stop()
 {
     try
     {
         EfsAccess.WaitOne();
         GuiUtils.MdiWindow.Close();
     }
     finally
     {
         EfsAccess.ReleaseMutex();
     }
 }
예제 #4
0
 /// <summary>
 ///     Loads the dictionary designated by filename
 /// </summary>
 /// <param name="fileName"></param>
 public void Load(string fileName)
 {
     try
     {
         EfsAccess.WaitOne();
         MainWindow window = GuiUtils.MdiWindow;
         window.Invoke((MethodInvoker)(() => window.OpenFile(fileName)));
     }
     finally
     {
         EfsAccess.ReleaseMutex();
     }
 }
예제 #5
0
 /// <summary>
 ///     Restarts the engine with default values
 /// </summary>
 public void Restart()
 {
     try
     {
         EfsAccess.WaitOne();
         ClearFunctionCaches(true);
         EfsSystem.Instance.Runner = new Runner(Explain, KeepEventCount);
     }
     finally
     {
         EfsAccess.ReleaseMutex();
     }
 }
예제 #6
0
 /// <summary>
 /// Awakes the connection
 /// </summary>
 /// <param name="clientId"></param>
 public void Awake(int clientId)
 {
     try
     {
         CheckClient(clientId);
         EfsAccess.WaitOne();
         Connections[clientId].Suspended = false;
     }
     finally
     {
         EfsAccess.ReleaseMutex();
     }
 }
예제 #7
0
        /// <summary>
        ///     Connects to the service
        /// </summary>
        /// <param name="listener">Indicates that the client is a listener</param>
        /// <returns>The client identifier</returns>
        public int ConnectUsingDefaultValues(bool listener)
        {
            int clientId;

            try
            {
                EfsAccess.WaitOne();
                clientId = AddClient(listener);
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }

            return(clientId);
        }
예제 #8
0
        /// <summary>
        ///     Connects to the service
        /// </summary>
        /// <param name="listener">Indicates that the client is a listener</param>
        /// <param name="explain">Indicates that the explain view should be updated according to the scenario execution</param>
        /// <param name="logEvents">Indicates that the events should be logged</param>
        /// <param name="keepEventCount">The number of events that should be kept in memory</param>
        public int Connect(bool listener, bool explain, bool logEvents, int keepEventCount)
        {
            int clientId;

            try
            {
                EfsAccess.WaitOne();
                clientId       = AddClient(listener);
                Explain        = explain;
                LogEvents      = logEvents;
                KeepEventCount = keepEventCount;
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }

            return(clientId);
        }
예제 #9
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();
            }
        }
예제 #10
0
        /// <summary>
        ///     Provides the value of a specific variable
        /// </summary>
        /// <param name="variableName"></param>
        /// <returns></returns>
        public Value GetVariableValue(string variableName)
        {
            Value retVal = null;

            EfsAccess.WaitOne();
            try
            {
                IVariable variable = EfsSystem.Instance.FindByFullName(variableName) as IVariable;
                if (variable != null)
                {
                    retVal = ConvertOut(variable.Value);
                }
            }
            catch (Exception)
            {
                // TODO
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }

            return(retVal);
        }
예제 #11
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();
            }
        }