Esempio n. 1
0
        public void Start(GraphContextWrapper context)
        {
            this.currentContext  = context;
            this.MemoryVariables = new Dictionary <string, object>();
            GraphsContainer.UpdateStorageStateGraph(context, Enums.GraphStateEnum.STARTED);

            // Init connectors
            foreach (var x in this.Nodes.ToList().FindAll(x => x.Value.NodeBlockType == NodeTypeEnum.Connector))
            {
                try
                {
                    x.Value.SetupConnector();
                }
                catch (Exception ex)
                {
                    this.AppendLog("error", "Can't setup the connector : " + x.Value.FriendlyName + ", " + ex.Message);
                    this.Stop(true);
                    return;
                }
            }

            if (this.Nodes.ToList().FindAll(x => x.Value.IsEventNode).Count == 0)
            {
                try
                {
                    IsRunning = true;
                    this.ExecuteFromEntryPoint();
                    return;
                }
                catch (Exception ex)
                {
                    this.AppendLog("error", "Error when executing the graph : " + ex.Message);
                    this.Stop(true);
                    return;
                }
            }

            IsRunning = true;
            foreach (var x in this.Nodes.ToList().FindAll(x => x.Value.IsEventNode))
            {
                try
                {
                    x.Value.SetupEvent();
                }
                catch (Exception ex)
                {
                    this.AppendLog("error", "Can't setup the event : " + x.Value.FriendlyName + ", " + ex.Message);
                    this.Stop(true);
                    return;
                }
            }
            this.ExecuteFromEntryPoint();
        }
Esempio n. 2
0
        public bool Stop(bool force = false)
        {
            if (!this.IsRunning && !force)
            {
                return(true);
            }
            this.Nodes.ToList().FindAll(x => x.Value.IsEventNode).ForEach(x =>
            {
                try
                {
                    x.Value.OnStop();
                }
                catch (Exception ex)
                {
                    this.AppendLog("error", "Can't release the connector " + x.Value.FriendlyName + " : " + ex.Message);
                }
            });
            this.Nodes.ToList().FindAll(x => x.Value.NodeBlockType == NodeTypeEnum.Connector).ForEach(x =>
            {
                try
                {
                    x.Value.OnStop();
                }
                catch (Exception ex)
                {
                    this.AppendLog("error", "Can't release the event " + x.Value.FriendlyName + " : " + ex.Message);
                }
            });

            try
            {
                this.queueTask.Dispose();
                this.cancelCycleToken.Cancel();
            }
            catch (Exception ex)
            {
                this.AppendLog("error", "Internal error : " + ex.Message);
            }
            logger.Info("Stop requested for graph hash {0}", this.UniqueHash);
            this.AppendLog("warn", string.Format("Stop requested for graph hash {0}", this.UniqueHash));

            IsRunning = false;
            GraphsContainer.StopGraphByHash(this.UniqueHash);
            return(true);
        }