public LGSPGraphProcessingEnvironment(LGSPGraph graph, LGSPActions actions)
     : base(graph, actions)
 {
     transactionManager = new LGSPTransactionManager(this);
     sequencesManager = new LGSPDeferredSequencesManager();
     SetClearVariables(true);
 }
 public LGSPGraphProcessingEnvironment(LGSPGraph graph, LGSPActions actions)
     : base(graph, actions)
 {
     transactionManager = new LGSPTransactionManager(this);
     sequencesManager   = new LGSPDeferredSequencesManager();
     SetClearVariables(true);
 }
 public LGSPActionExecutionEnvironment(LGSPGraph graph, LGSPActions actions)
 {
     // TODO: evt. IGraph + BaseActions und dann hier cast auf LGSP, mal gucken was an Schnittstelle besser paßt
     this.usedGraphs = new Stack <LGSPGraph>();
     this.usedGraphs.Push(graph);
     this.namedGraphOnTop = graph as LGSPNamedGraph;
     this.curActions      = actions;
     InitActionsProfile(actions);
 }
 public LGSPActionExecutionEnvironment(LGSPGraph graph, LGSPActions actions)
 {
     usedGraphs = new Stack <LGSPGraph>();
     usedGraphs.Push(graph);
     namedGraphOnTop = graph as LGSPNamedGraph;
     curActions      = actions;
     InitActionsProfile(actions);
     customCommandsToDescriptions = new Dictionary <string, string>();
     FillCustomCommandDescriptions();
 }
Esempio n. 5
0
        /// <summary>
        /// Creates a new LGSPGraph and LGSPActions instance from the specified specification file.
        /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
        /// A name for the graph is automatically generated.
        /// </summary>
        /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
        /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
        /// <param name="newGraph">Returns the new graph.</param>
        /// <param name="newActions">Returns the new BaseActions object.</param>
        /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
        /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
        public void CreateFromSpec(String grgFilename, String statisticsPath,
                                   out LGSPGraph newGraph, out LGSPActions newActions)
        {
            LGSPGraph   graph;
            LGSPActions actions;

            CreateFromSpec(grgFilename, GetNextGraphName(), statisticsPath, ProcessSpecFlags.UseNoExistingFiles, new List <String>(), false, 0,
                           out graph, out actions);
            newGraph   = graph;
            newActions = actions;
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a new LGSPNamedGraph and LGSPActions instance from the specified specification file.
        /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
        /// A name for the graph is automatically generated.
        /// </summary>
        /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
        /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
        /// <param name="capacity">The initial capacity for the name maps (performance optimization, use 0 if unsure).</param>
        /// <param name="newGraph">Returns the new named graph.</param>
        /// <param name="newActions">Returns the new BaseActions object.</param>
        /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
        /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
        public void CreateNamedFromSpec(String grgFilename, String statisticsPath, int capacity,
                                        out LGSPNamedGraph newGraph, out LGSPActions newActions)
        {
            LGSPGraph   graph;
            LGSPActions actions;

            CreateFromSpec(grgFilename, GetNextGraphName(), statisticsPath, ProcessSpecFlags.UseNoExistingFiles, new List <String>(), true, capacity,
                           out graph, out actions);
            newGraph   = (LGSPNamedGraph)graph;
            newActions = actions;
        }
        public static bool ApplyXGRS_huh(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv)
        {
            object x = procEnv.GetVariableValue("x");

            GRGEN_LGSP.LGSPGraph   graph   = procEnv.graph;
            GRGEN_LGSP.LGSPActions actions = procEnv.curActions;
            object a = procEnv.GetVariableValue("a");

            GRGEN_MODEL.N node_a = (GRGEN_MODEL.N)a;
            int           val_x  = (int)x;

            // announce change so that debugger can show new value or transaction manager can record it and roll it back
            graph.ChangingNodeAttribute(node_a, GRGEN_MODEL.NodeType_N.AttributeType_i, GRGEN_LIBGR.AttributeChangeType.Assign, val_x, null);
            node_a.i = val_x;
            // add reflexive edge
            GRGEN_MODEL.E someEdge = GRGEN_MODEL.E.CreateEdge(graph, node_a, node_a);
            // here you could do other nifty things like deleting nodes, retyping graph elements, or calling rules
            return(false);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new LGSPGraph or LGSPNamedGraph and LGSPActions instance from the specified specification file.
        /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
        /// </summary>
        /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
        /// <param name="graphName">Name of the new graph.</param>
        /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
        /// <param name="flags">Specifies how the specification is to be processed; only KeepGeneratedFiles and CompileWithDebug are taken care of!</param>
        /// <param name="externalAssemblies">List of external assemblies to reference.</param>
        /// <param name="named">Returns a named graph if true otherwise a non-named graph. You must cast the LGSPGraph returned to the inherited LGSPNamedGraph if named=true.</param>
        /// <param name="capacity">The initial capacity for the name maps, only used if named (performance optimization, use 0 if unsure).</param>
        /// <param name="newGraph">Returns the new graph.</param>
        /// <param name="newActions">Returns the new BaseActions object.</param>
        /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
        /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
        public void CreateFromSpec(String grgFilename, String graphName, String statisticsPath,
                                   ProcessSpecFlags flags, List <String> externalAssemblies, bool named, int capacity,
                                   out LGSPGraph newGraph, out LGSPActions newActions)
        {
            if (!File.Exists(grgFilename))
            {
                throw new FileNotFoundException("The rule specification file \"" + grgFilename + "\" does not exist!", grgFilename);
            }

            String actionsFilename;
            String modelFilename;

            if (MustGenerate(grgFilename, statisticsPath, flags, out actionsFilename, out modelFilename))
            {
                LGSPGrGen.ProcessSpecification(grgFilename, statisticsPath, flags, externalAssemblies.ToArray());
            }

            newGraph   = named ? (LGSPNamedGraph)CreateNamedGraph(modelFilename, graphName, "capacity=" + capacity.ToString()) : (LGSPGraph)CreateGraph(modelFilename, graphName);
            newActions = LGSPActions.LoadActions(actionsFilename, newGraph);
        }
        public void InitActionsProfile(LGSPActions actions)
        {
            if (actions == null)
            {
                return;
            }
            if (!actions.Profile)
            {
                return;
            }

            perfInfo.ActionProfiles.Clear();
            foreach (IAction action in actions.Actions)
            {
                ActionProfile actionProfile   = new ActionProfile();
                int           branchingFactor = ((LGSPAction)action).patternGraph.branchingFactor;
                actionProfile.averagesPerThread = new ProfileAverages[branchingFactor];
                for (int i = 0; i < branchingFactor; ++i)
                {
                    actionProfile.averagesPerThread[i] = new ProfileAverages();
                }
                perfInfo.ActionProfiles.Add(action.PackagePrefixedName, actionProfile);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Loads a LGSPActions instance from the given file.
        /// If the file is a ".cs" file it will be compiled first.
        /// </summary>
        public static LGSPActions LoadActions(String actionFilename, LGSPGraph graph)
        {
            Assembly assembly;
            String   assemblyName;

            String extension = Path.GetExtension(actionFilename);

            if (extension.Equals(".cs", StringComparison.OrdinalIgnoreCase))
            {
                CSharpCodeProvider compiler   = new CSharpCodeProvider();
                CompilerParameters compParams = new CompilerParameters();
                compParams.ReferencedAssemblies.Add("System.dll");
                compParams.ReferencedAssemblies.Add(Assembly.GetAssembly(typeof(IBackend)).Location);
                compParams.ReferencedAssemblies.Add(Assembly.GetAssembly(typeof(LGSPActions)).Location);
                compParams.ReferencedAssemblies.Add(graph.modelAssemblyName);

                //                compParams.GenerateInMemory = true;
                compParams.CompilerOptions = "/optimize";
                compParams.OutputAssembly  = String.Format("lgsp-action-assembly-{0:00000}.dll", actionID++);

                CompilerResults compResults = compiler.CompileAssemblyFromFile(compParams, actionFilename);
                if (compResults.Errors.HasErrors)
                {
                    String errorMsg = compResults.Errors.Count + " Errors:";
                    foreach (CompilerError error in compResults.Errors)
                    {
                        errorMsg += String.Format("\r\nLine: {0} - {1}", error.Line, error.ErrorText);
                    }
                    throw new ArgumentException("Illegal actions C# source code: " + errorMsg);
                }

                assembly     = compResults.CompiledAssembly;
                assemblyName = compParams.OutputAssembly;
            }
            else if (extension.Equals(".dll", StringComparison.OrdinalIgnoreCase))
            {
                assembly     = Assembly.LoadFrom(actionFilename);
                assemblyName = actionFilename;
                LGSPBackend.Instance.AddAssembly(assembly);          // TODO: still needed??
            }
            else
            {
                throw new ArgumentException("The action filename must be either a .cs or a .dll filename!");
            }

            Type actionsType = null;

            try
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (!type.IsClass || type.IsNotPublic)
                    {
                        continue;
                    }
                    if (type.BaseType == typeof(LGSPActions))
                    {
                        if (actionsType != null)
                        {
                            throw new ArgumentException(
                                      "The given action file contains more than one LGSPActions implementation!");
                        }
                        actionsType = type;
                    }
                }
            }
            catch (ReflectionTypeLoadException e)
            {
                String errorMsg = "";
                foreach (Exception ex in e.LoaderExceptions)
                {
                    errorMsg += "- " + ex.Message + Environment.NewLine;
                }
                if (errorMsg.Length == 0)
                {
                    errorMsg = e.Message;
                }
                throw new ArgumentException(errorMsg);
            }
            if (actionsType == null)
            {
                throw new ArgumentException("The given action file doesn't contain an LGSPActions implementation!");
            }

            LGSPActions actions = (LGSPActions)Activator.CreateInstance(actionsType, graph, graph.modelAssemblyName, assemblyName);

            if (graph.Model.MD5Hash != actions.ModelMD5Hash)
            {
                throw new ArgumentException("The given action file has been compiled with another model assembly!");
            }

            return(actions);
        }
Esempio n. 11
0
 /// <summary>
 /// Creates a new LGSPNamedGraph and LGSPActions instance from the specified specification file.
 /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
 /// A name for the graph is automatically generated.
 /// </summary>
 /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
 /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
 /// <param name="capacity">The initial capacity for the name maps (performance optimization, use 0 if unsure).</param>
 /// <param name="newGraph">Returns the new named graph.</param>
 /// <param name="newActions">Returns the new BaseActions object.</param>
 /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
 /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
 public void CreateNamedFromSpec(String grgFilename, String statisticsPath, int capacity,
     out LGSPNamedGraph newGraph, out LGSPActions newActions)
 {
     LGSPGraph graph;
     LGSPActions actions;
     CreateFromSpec(grgFilename, GetNextGraphName(), statisticsPath, ProcessSpecFlags.UseNoExistingFiles, new List<String>(), true, capacity,
         out graph, out actions);
     newGraph = (LGSPNamedGraph)graph;
     newActions = actions;
 }
 public override void Initialize(LGSPGraph graph, LGSPActions actions)
 {
     SetClearVariables(false);
     base.Initialize(graph, actions);
     SetClearVariables(true);
 }
 public LGSPSubactionAndOutputAdditionEnvironment(LGSPGraph graph, LGSPActions actions)
     : base(graph, actions)
 {
     recorder = new Recorder(graph as LGSPNamedGraph, this);
 }
 public virtual void Initialize(LGSPGraph graph, LGSPActions actions)
 {
     this.Graph = graph;
     this.Actions = actions;
     ((Recorder)recorder).Initialize(graph as LGSPNamedGraph, this);
 }
Esempio n. 15
0
 /// <summary>
 /// Creates a new LGSPGraph and LGSPActions instance from the specified specification file.
 /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
 /// A name for the graph is automatically generated.
 /// </summary>
 /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
 /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
 /// <param name="newGraph">Returns the new graph.</param>
 /// <param name="newActions">Returns the new BaseActions object.</param>
 /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
 /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
 public void CreateFromSpec(String grgFilename, String statisticsPath,
     out LGSPGraph newGraph, out LGSPActions newActions)
 {
     LGSPGraph graph;
     LGSPActions actions;
     CreateFromSpec(grgFilename, GetNextGraphName(), statisticsPath, ProcessSpecFlags.UseNoExistingFiles, new List<String>(), false, 0,
         out graph, out actions);
     newGraph = graph;
     newActions = actions;
 }
Esempio n. 16
0
 public LGSPSubactionAndOutputAdditionEnvironment(LGSPGraph graph, LGSPActions actions)
     : base(graph, actions)
 {
     recorder = new Recorder(graph as LGSPNamedGraph, this);
 }
 public override void Initialize(LGSPGraph graph, LGSPActions actions)
 {
     SetClearVariables(false);
     base.Initialize(graph, actions);
     SetClearVariables(true);
 }
Esempio n. 18
0
 public virtual void Initialize(LGSPGraph graph, LGSPActions actions)
 {
     this.Graph   = graph;
     this.Actions = actions;
     ((Recorder)recorder).Initialize(graph as LGSPNamedGraph, this);
 }
Esempio n. 19
0
        /// <summary>
        /// Creates a new LGSPGraph or LGSPNamedGraph and LGSPActions instance from the specified specification file.
        /// If the according dlls do not exist or are out of date, the needed processing steps are performed automatically.
        /// </summary>
        /// <param name="grgFilename">Filename of the rule specification file (.grg).</param>
        /// <param name="graphName">Name of the new graph.</param>
        /// <param name="statisticsPath">Optional path to a file containing the graph statistics to be used for building the matchers.</param>
        /// <param name="flags">Specifies how the specification is to be processed; only KeepGeneratedFiles and CompileWithDebug are taken care of!</param>
        /// <param name="externalAssemblies">List of external assemblies to reference.</param>
        /// <param name="named">Returns a named graph if true otherwise a non-named graph. You must cast the LGSPGraph returned to the inherited LGSPNamedGraph if named=true.</param>
        /// <param name="capacity">The initial capacity for the name maps, only used if named (performance optimization, use 0 if unsure).</param>
        /// <param name="newGraph">Returns the new graph.</param>
        /// <param name="newActions">Returns the new BaseActions object.</param>
        /// <exception cref="System.IO.FileNotFoundException">Thrown, when a needed specification file does not exist.</exception>
        /// <exception cref="System.Exception">Thrown, when something goes wrong.</exception>
        public void CreateFromSpec(String grgFilename, String graphName, String statisticsPath,
            ProcessSpecFlags flags, List<String> externalAssemblies, bool named, int capacity,
            out LGSPGraph newGraph, out LGSPActions newActions)
        {
            if(!File.Exists(grgFilename))
                throw new FileNotFoundException("The rule specification file \"" + grgFilename + "\" does not exist!", grgFilename);

            String actionsFilename;
            String modelFilename;
            if(MustGenerate(grgFilename, statisticsPath, flags, out actionsFilename, out modelFilename))
                LGSPGrGen.ProcessSpecification(grgFilename, statisticsPath, flags, externalAssemblies.ToArray());

            newGraph = named ? (LGSPNamedGraph)CreateNamedGraph(modelFilename, graphName, "capacity=" + capacity.ToString()) : (LGSPGraph)CreateGraph(modelFilename, graphName);
            newActions = LGSPActions.LoadActions(actionsFilename, newGraph);
        }