Exemple #1
0
 /// <summary>
 /// Registers a log with this set of event classes. This will result in all
 /// events of this log being analyzed, and potentially new event classes
 /// being added to this set of event classes.Event classes will be
 /// incremented in size, as new members of these classes are found among the
 /// events in the log.
 /// </summary>
 /// <param name="log"> The log to be analyzed</param>
 public void Register(IXLog log)
 {
     foreach (IXTrace trace in log)
     {
         Register(trace);
     }
 }
 public void Serialize(IXLog log, Stream stream, CompressionLevel level)
 {
     using (GZipStream gzos = new GZipStream(stream, level))
         using (BufferedStream bos = new BufferedStream(gzos))
         {
             base.Serialize(log, bos);
             bos.Flush();
         }
 }
Exemple #3
0
 bool FindGlobalEventAttribute(IXLog log, String key)
 {
     foreach (XAttribute attribute in log.GlobalEventAttributes)
     {
         if (attribute.Key.Equals(key))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
        /// <summary>
        /// Creates a new log info summary with a custom event classifier.
        /// </summary>
        /// <returns>The log info summary for this log.</returns>
        /// <param name="log">The event log to create an info summary for.</param>
        /// <param name="classifier">The event classifier to be used.</param>
        public static IXLogInfo CreateLogInfo(IXLog log, IXEventClassifier classifier)
        {
            IXLogInfo info = log.GetInfo(classifier);

            if (info == null)
            {
                info = XLogInfo.Create((XLog)log, classifier);

                log.SetInfo(classifier, info);
            }
            return(info);
        }
Exemple #5
0
        /// <summary>
        /// Attempts to parse a collection of XES models from the given file, using
        /// all available parsers.
        /// </summary>
        /// <returns>The parse.</returns>
        /// <param name="file">File.</param>
        public IXLog Parse(FileInfo file)
        {
            IXLog result = null;

            foreach (XParser parser in XParserRegistry.Instance.GetAvailable())
            {
                if (parser.CanParse(file))
                {
                    try
                    {
                        result = parser.Parse(file.OpenRead());
                        return(result);
                    }
                    catch (Exception)
                    {
                        XLogging.Trace(String.Format("Attempted to parse file {0} with parser {1}",
                                                     file.FullName, parser.Name));
                    }
                }
            }
            throw new Exception("No suitable parser could be found!");
        }
Exemple #6
0
        IList <string> FixKeys(IXLog log, List <string> keys, int index)
        {
            if (index >= keys.Count)
            {
                return(keys);
            }

            if (FindGlobalEventAttribute(log, keys[index]))
            {
                IList <string> fixedKeys = FixKeys(log, keys, index + 1);
                if (fixedKeys != null)
                {
                    return(fixedKeys);
                }
            }

            if (index + 1 == keys.Count)
            {
                return(null);
            }

            List <string> newKeys = new List <string>(keys.Count - 1);

            for (int i = 0; i < index; ++i)
            {
                newKeys.Add(keys[i]);
            }

            newKeys.Add(keys[index] + " " + keys[index + 1]);

            for (int i = index + 2; i < keys.Count; ++i)
            {
                newKeys.Add(keys[i]);
            }

            return(FixKeys(log, newKeys, index));
        }
Exemple #7
0
 static XLog()
 {
     XLog.s_logger = null;
     XLog.s_logger = XLog.GetLog <XLog>();
 }
 public static void Init(IXLog log)
 {
     AssetLogger.s_log = log;
 }
Exemple #9
0
 public static void SetLog(IXLog log)
 {
     AssetLogger.Init(log);
 }
 public static void Init(IXLog log)
 {
     EffectLogger.s_log = log;
 }
 public void SetLog(IXLog log)
 {
     PluginLogger.Init(log);
 }
Exemple #12
0
 /// <summary>
 /// Creates a new log info with the standard event classifier.
 /// </summary>
 /// <returns>log info for this log.</returns>
 /// <param name="log">The event log to create an info summary for.</param>
 public static IXLogInfo CreateLogInfo(IXLog log)
 {
     return(CreateLogInfo(log, XLogInfo.STANDARD_CLASSIFIER));
 }
Exemple #13
0
        public override IXLog Parse(Stream stream)
        {
            Stack <IXAttributable> attributableStack = new Stack <IXAttributable>();
            Stack <XAttribute>     attributeStack    = new Stack <XAttribute>();
            IXEvent           evt     = null;
            IXLog             log     = null;
            IXTrace           trace   = null;
            List <XAttribute> globals = null;

            using (XmlReader reader = XmlReader.Create(stream))
            {
                List <string> ATTR_TYPE_TAGS = new List <string>(new string[] { "string", "date", "int", "float", "boolean", "id", "list", "container" });
                ATTR_TYPE_TAGS.Sort();

                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        // start tag found
                        string tagName = reader.LocalName.Trim();
                        if (tagName.Length == 0)
                        {
                            tagName = reader.Name.Trim(); // <= qualified name
                        }


                        if (ATTR_TYPE_TAGS.Contains(tagName.ToLower()))
                        {
                            // The tag is an attribute
                            string     key        = reader.GetAttribute("key") ?? "";
                            string     val        = reader.GetAttribute("value") ?? "";
                            XExtension ext        = null;
                            int        colonindex = key.IndexOf(":", StringComparison.InvariantCultureIgnoreCase);
                            if (colonindex > 0)
                            {
                                string prefix = key.Substring(0, colonindex);
                                ext = XExtensionManager.Instance.GetByPrefix(prefix);
                            }

                            XAttribute attr = null;
                            switch (tagName)
                            {
                            case "string":
                                attr = factory.CreateAttributeLiteral(key, val, ext);
                                break;

                            case "int":
                                attr = factory.CreateAttributeDiscrete(key, long.Parse(val), ext);
                                break;

                            case "boolean":
                                attr = factory.CreateAttributeBoolean(key, bool.Parse(val), ext);
                                break;

                            case "date":
                                DateTime d = XAttributeTimestamp.Parse(val);
                                attr = factory.CreateAttributeTimestamp(key, d, ext);
                                break;

                            case "float":
                                attr = factory.CreateAttributeContinuous(key, double.Parse(val), ext);
                                break;

                            case "id":
                                attr = factory.CreateAttributeID(key, XID.Parse(val), ext);
                                break;

                            case "list":
                                attr = factory.CreateAttributeList(key, ext);
                                break;

                            case "container":
                                attr = factory.CreateAttributeContainer(key, ext);
                                break;

                            default:
                                XLogging.Log("Unknown tag '" + tagName + "'", XLogging.Importance.WARNING);
                                break;
                            }
                            if (reader.IsEmptyElement)
                            {
                                // No child nodes, we can directly store it
                                if (globals != null)
                                {
                                    // attribute is global
                                    globals.Add(attr);
                                }
                                else
                                {
                                    attributableStack.Peek().GetAttributes().Add(attr.Key, attr);

                                    if ((!(attributeStack.Count == 0)) &&
                                        (attributeStack.Peek() is XAttributeCollection))
                                    {
                                        ((XAttributeCollection)attributeStack.Peek()).AddToCollection(attr);
                                    }
                                }
                            }
                            else if (attr != null)
                            {
                                attributeStack.Push(attr);
                                attributableStack.Push((IXAttributable)attr);
                            }
                        }
                        else if ("event".Equals(tagName.ToLower()))
                        {
                            // Parse an event
                            evt = factory.CreateEvent();
                            attributableStack.Push(evt);
                        }
                        else if ("trace".Equals(tagName.ToLower()))
                        {
                            trace = factory.CreateTrace();
                            attributableStack.Push(trace);
                        }
                        else if ("log".Equals(tagName.ToLower()))
                        {
                            log = factory.CreateLog();
                            ((XLog)log).Version  = reader.GetAttribute("xes.version") ?? "2.0";
                            ((XLog)log).Features = reader.GetAttribute("xes.features") ?? "";
                            attributableStack.Push(log);
                        }
                        else if ("extension".Equals(tagName.ToLower()))
                        {
                            XExtension extension = null;
                            String     uriString = reader.GetAttribute("uri");
                            if (uriString != null)
                            {
                                extension = XExtensionManager.Instance.GetByUri(new UriBuilder(uriString).Uri);
                            }
                            else
                            {
                                string prefixString = reader.GetAttribute("prefix");
                                if (prefixString != null)
                                {
                                    extension = XExtensionManager.Instance.GetByPrefix(prefixString);
                                }
                            }

                            if (extension != null)
                            {
                                log.Extensions.Add(extension);
                            }
                            else
                            {
                                XLogging.Log("Unknown extension: " + uriString, XLogging.Importance.ERROR);
                            }
                        }
                        else if ("global".Equals(tagName.ToLower()))
                        {
                            string scope = reader.GetAttribute("scope");
                            if (scope.Equals("trace"))
                            {
                                globals = log.GlobalTraceAttributes;
                            }
                            else if (scope.Equals("event"))
                            {
                                globals = log.GlobalEventAttributes;
                            }
                        }
                        else if ("classifier".Equals(tagName.ToLower()))
                        {
                            string name = reader.GetAttribute("name");
                            string keys = reader.GetAttribute("keys");
                            if ((name == null) || (keys == null) || (name.Length <= 0) || (keys.Length <= 0))
                            {
                                continue;
                            }
                            IList <string> keysList = FixKeys(log, XTokenHelper.ExtractTokens(keys));

                            string[] keysArray = new string[keysList.Count];
                            int      i         = 0;
                            foreach (string key in keysList)
                            {
                                keysArray[(i++)] = key;
                            }
                            IXEventClassifier classifier = new XEventAttributeClassifier(name, keysArray);

                            log.Classifiers.Add(classifier);
                        }
                    }
                    else
                    {
                        // end tag found
                        string tagName = reader.LocalName.Trim().ToLower();
                        if (tagName.Length == 0)
                        {
                            tagName = reader.Name.Trim().ToLower(); // <= qualified name
                        }

                        if ("global".Equals(tagName))
                        {
                            globals = null;
                        }
                        else if (ATTR_TYPE_TAGS.Contains(tagName))
                        {
                            XAttribute attribute = attributeStack.Pop();
                            attributableStack.Pop();
                            if (globals != null)
                            {
                                globals.Add(attribute);
                            }
                            else
                            {
                                attributableStack.Peek().GetAttributes().Add(attribute.Key, attribute);

                                if ((!(attributeStack.Count == 0)) &&
                                    (attributeStack.Peek() is XAttributeCollection))
                                {
                                    ((XAttributeCollection)attributeStack.Peek()).AddToCollection(attribute);
                                }
                            }
                        }
                        else if ("event".Equals(tagName))
                        {
                            trace.Add(evt);
                            evt = null;
                            attributableStack.Pop();
                        }
                        else if ("trace".Equals(tagName))
                        {
                            log.Add(trace);
                            trace = null;
                            attributableStack.Pop();
                        }
                        else if ("log".Equals(tagName))
                        {
                            attributableStack.Pop();
                        }
                    }
                }
            }
            return(log);
        }
 public static void Init(IXLog logger)
 {
     PluginLogger.logger = logger;
 }
 public new void Serialize(IXLog log, Stream stream)
 {
     this.Serialize(log, stream, CompressionLevel.Optimal);
 }
Exemple #16
0
        public void Serialize(IXLog log, Stream stream)
        {
            XLogging.Log("Start serializing log to XES.XML", XLogging.Importance.DEBUG);

            long        start = DateTime.Now.Ticks;
            XmlDocument doc   = new XmlDocument();

            doc.AppendChild(doc.CreateComment("This file has been generated with the OpenXES.Net library. It conforms"));
            doc.AppendChild(doc.CreateComment("to the XML serialization of the XES standard for log storage and management."));
            doc.AppendChild(doc.CreateComment("XES standard version: 2.0"));
            doc.AppendChild(doc.CreateComment(String.Format("OpenXES.Net library version: {0}", openXesNetVersion)));
            doc.AppendChild(doc.CreateComment("OpenXES is available from http://www.openxes.org/")); // TODO: update this string

            XmlNode logNode = doc.CreateElement("log");

            doc.AppendChild(logNode);

            // Log metadata
            XmlAttribute xesNetVersion = doc.CreateAttribute("openxesnet.version");

            xesNetVersion.Value = String.Format("{0}", openXesNetVersion);
            logNode.Attributes.Append(xesNetVersion);

            XmlAttribute xesVersion = doc.CreateAttribute("xes.version");

            xesVersion.Value = ((XLog)log).Version;
            logNode.Attributes.Append(xesVersion);

            XmlAttribute xesFeatures = doc.CreateAttribute("xes.features");

            xesFeatures.Value = ((XLog)log).Features;
            logNode.Attributes.Append(xesFeatures);

            // Log extensions
            foreach (XExtension extension in log.Extensions)
            {
                XmlNode extNode = doc.CreateElement("extension");

                XmlAttribute name = doc.CreateAttribute("name");
                name.Value = extension.Name;
                extNode.Attributes.Append(name);

                XmlAttribute prefix = doc.CreateAttribute("prefix");
                prefix.Value = extension.Prefix;
                extNode.Attributes.Append(prefix);

                XmlAttribute uri = doc.CreateAttribute("uri");
                uri.Value = extension.Uri.ToString();
                extNode.Attributes.Append(uri);

                logNode.AppendChild(extNode);
            }

            // Global attributes: we add this tag and subtags only if present

            /*
             * if (log.GlobalEventAttributes.Count > 0 || log.GlobalTraceAttributes.Count > 0)
             * {
             *  XmlNode globalNode = doc.CreateElement("global");
             *  logNode.AppendChild(globalNode);
             *
             *  if (log.GlobalTraceAttributes.Count > 0)
             *  {
             *      XmlNode globalTraceNode = doc.CreateElement("trace");
             *      globalNode.AppendChild(globalTraceNode);
             *      AddAttributes(doc, globalTraceNode, log.GlobalTraceAttributes);
             *  }
             *
             *  if (log.GlobalEventAttributes.Count > 0)
             *  {
             *      XmlNode globalEventNode = doc.CreateElement("event");
             *      globalNode.AppendChild(globalEventNode);
             *      AddAttributes(doc, globalEventNode, log.GlobalEventAttributes);
             *  }
             * }*/

            if (log.GlobalEventAttributes.Count > 0)
            {
                XmlNode      globalEventNode = doc.CreateElement("global");
                XmlAttribute scope           = doc.CreateAttribute("scope");
                scope.Value = "event";
                globalEventNode.Attributes.Append(scope);

                logNode.AppendChild(globalEventNode);
                AddAttributes(doc, globalEventNode, log.GlobalEventAttributes);
            }

            if (log.GlobalTraceAttributes.Count > 0)
            {
                XmlNode      globalTraceNode = doc.CreateElement("global");
                XmlAttribute scope           = doc.CreateAttribute("scope");
                scope.Value = "trace";
                globalTraceNode.Attributes.Append(scope);

                logNode.AppendChild(globalTraceNode);
                AddAttributes(doc, globalTraceNode, log.GlobalTraceAttributes);
            }

            foreach (IXEventClassifier classifier in log.Classifiers)
            {
                if (classifier is XEventAttributeClassifier)
                {
                    XEventAttributeClassifier attrClass = (XEventAttributeClassifier)classifier;
                    XmlNode      clsNode = doc.CreateElement("classifier");
                    XmlAttribute name    = doc.CreateAttribute("name");
                    name.Value = ((XEventAttributeClassifier)classifier).Name;
                    clsNode.Attributes.Append(name);
                    XmlAttribute keys = doc.CreateAttribute("keys");
                    keys.Value = XTokenHelper.FormatTokenString(new List <string>(attrClass.DefiningAttributeKeys));
                    clsNode.Attributes.Append(keys);
                }
            }

            // Log attributes
            AddAttributes(doc, logNode, log.GetAttributes().AsList());

            // Log traces
            foreach (XTrace trace in log)
            {
                XmlNode traceNode = doc.CreateElement("trace");
                logNode.AppendChild(traceNode);

                // Trace attributes
                AddAttributes(doc, traceNode, trace.GetAttributes().AsList());

                // Trace events
                foreach (XEvent evt in trace)
                {
                    // Event attributes
                    XmlNode eventNode = doc.CreateElement("event");
                    traceNode.AppendChild(eventNode);
                    AddAttributes(doc, eventNode, evt.GetAttributes().AsList());
                }
            }

            // Save the doc
            doc.Save(stream);

            string duration = " (" + (new TimeSpan(DateTime.Now.Ticks - start)).TotalMilliseconds + " msec.)";

            XLogging.Log("Finished serializing log" + duration, XLogging.Importance.DEBUG);
        }
Exemple #17
0
        IList <String> FixKeys(IXLog log, List <string> keys)
        {
            IList <string> fixedKeys = FixKeys(log, keys, 0);

            return(fixedKeys ?? keys);
        }