XSoftwareTelemetryExtension() : base("Software Telemetry", "swtelemetry", EXTENSION_URI)
        {
            IXFactory factory = XFactoryRegistry.Instance.CurrentDefault;

            ATTR_CPU_TOTAL_USER = factory.CreateAttributeDiscrete(KEY_CPU_TOTAL_USER, -1L, this);
            this.eventAttributes.Add(KEY_CPU_TOTAL_USER, (XAttribute)ATTR_CPU_TOTAL_USER.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_CPU_TOTAL_USER), "CPU usage - total time in user space, in milliseconds");

            ATTR_CPU_TOTAL_KERNEL = factory.CreateAttributeDiscrete(KEY_CPU_TOTAL_KERNEL, -1L, this);
            this.eventAttributes.Add(KEY_CPU_TOTAL_KERNEL, (XAttribute)ATTR_CPU_TOTAL_KERNEL.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_CPU_TOTAL_KERNEL), "CPU usage - total time in kernel space, in milliseconds");

            ATTR_CPU_TOTAL_IDLE = factory.CreateAttributeDiscrete(KEY_CPU_TOTAL_IDLE, -1L, this);
            this.eventAttributes.Add(KEY_CPU_TOTAL_IDLE, (XAttribute)ATTR_CPU_TOTAL_IDLE.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_CPU_TOTAL_IDLE), "CPU usage - total time spent idle, in milliseconds");

            ATTR_CPU_LOAD_USER = factory.CreateAttributeContinuous(KEY_CPU_LOAD_USER, -1L, this);
            this.eventAttributes.Add(KEY_CPU_LOAD_USER, (XAttribute)ATTR_CPU_LOAD_USER.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_CPU_LOAD_USER), "CPU usage - load in user space");

            ATTR_CPU_LOAD_KERNEL = factory.CreateAttributeContinuous(KEY_CPU_LOAD_KERNEL, -1L, this);
            this.eventAttributes.Add(KEY_CPU_LOAD_KERNEL, (XAttribute)ATTR_CPU_LOAD_KERNEL.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_CPU_LOAD_KERNEL), "CPU usage - load in kernel space");

            ATTR_THREAD_TOTAL = factory.CreateAttributeDiscrete(KEY_THREAD_TOTAL, -1L, this);
            this.eventAttributes.Add(KEY_THREAD_TOTAL, (XAttribute)ATTR_THREAD_TOTAL.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_THREAD_TOTAL), "Total number of threads");

            ATTR_THREAD_DAEMON = factory.CreateAttributeDiscrete(KEY_THREAD_DAEMON, -1L, this);
            this.eventAttributes.Add(KEY_THREAD_DAEMON, (XAttribute)ATTR_THREAD_DAEMON.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_THREAD_DAEMON), "Number of daemon threads");

            ATTR_MEMORY_USED = factory.CreateAttributeDiscrete(KEY_MEMORY_USED, -1L, this);
            this.eventAttributes.Add(KEY_MEMORY_USED, (XAttribute)ATTR_MEMORY_USED.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_MEMORY_USED), "Total memory used, measured in bytes");


            ATTR_MEMORY_TOTAL = factory.CreateAttributeDiscrete(KEY_MEMORY_TOTAL, -1L, this);
            this.eventAttributes.Add(KEY_MEMORY_TOTAL, (XAttribute)ATTR_MEMORY_TOTAL.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_MEMORY_TOTAL), "Total memory available, measured in bytes");

            ATTR_MEMORY_LOAD = factory.CreateAttributeContinuous(KEY_MEMORY_LOAD, -1L, this);
            this.eventAttributes.Add(KEY_MEMORY_LOAD, (XAttribute)ATTR_MEMORY_LOAD.Clone());
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_MEMORY_LOAD), "Memory usage load");
        }
示例#2
0
        XCostExtension() : base("Cost", "cost", EXTENSION_URI)
        {
            IXFactory factory = XFactoryRegistry.Instance.CurrentDefault;

            ATTR_TOTAL    = factory.CreateAttributeContinuous(KEY_TOTAL, 0.0D, this);
            ATTR_CURRENCY = factory.CreateAttributeLiteral(KEY_CURRENCY, "__INVALID__", this);
            ATTR_AMOUNT   = factory.CreateAttributeContinuous(KEY_AMOUNT, 0.0D, this);
            ATTR_DRIVER   = factory.CreateAttributeLiteral(KEY_DRIVER, "__INVALID__", this);
            ATTR_TYPE     = factory.CreateAttributeLiteral(KEY_TYPE, "__INVALID__", this);

            this.traceAttributes.Add(KEY_TOTAL, (XAttribute)ATTR_TOTAL.Clone());
            this.traceAttributes.Add(KEY_CURRENCY, (XAttribute)ATTR_CURRENCY.Clone());
            this.eventAttributes.Add(KEY_TOTAL, (XAttribute)ATTR_TOTAL.Clone());
            this.eventAttributes.Add(KEY_CURRENCY, (XAttribute)ATTR_CURRENCY.Clone());
            this.eventAttributes.Add(KEY_AMOUNT, (XAttribute)ATTR_AMOUNT.Clone());
            this.eventAttributes.Add(KEY_DRIVER, (XAttribute)ATTR_DRIVER.Clone());
            this.eventAttributes.Add(KEY_TYPE, (XAttribute)ATTR_TYPE.Clone());

            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_TOTAL), "Total Cost");
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_CURRENCY), "Currency of Cost");
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_AMOUNT), "Cost Amount");
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_DRIVER), "Cost Driver");
            XGlobalAttributeNameMap.Instance.RegisterMapping("EN", QualifiedName(KEY_TYPE), "Cost Type");
        }
示例#3
0
        protected XExtension Parse(XmlReader reader)
        {
            XExtension extension        = null;
            XAttribute currentAttribute = null;
            Dictionary <string, XAttribute> xAttributes = null;
            IXFactory factory = XFactoryRegistry.Instance.CurrentDefault;

            while (reader.Read())
            {
                // When a start tag is found
                if (reader.IsStartElement())
                {
                    string tagName = reader.LocalName;
                    if (tagName.Equals("", StringComparison.CurrentCultureIgnoreCase))
                    {
                        tagName = reader.Name;
                    }

                    if (tagName.Equals("xesextension", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string xName   = reader.GetAttribute("name");
                        string xPrefix = reader.GetAttribute("prefix");
                        Uri    xUri    = null;
                        try
                        {
                            xUri = new Uri(reader.GetAttribute("uri"));
                        }
                        catch (UriFormatException e)
                        {
                            XLogging.Log(e.Message, XLogging.Importance.ERROR);
                            throw e;
                        }
                        extension = new XExtension(xName, xPrefix, xUri);
                    }
                    else if (tagName.Equals("log", StringComparison.CurrentCultureIgnoreCase))
                    {
                        xAttributes = extension.LogAttributes;
                    }
                    else if (tagName.Equals("trace", StringComparison.CurrentCultureIgnoreCase))
                    {
                        xAttributes = extension.TraceAttributes;
                    }
                    else if (tagName.Equals("event", StringComparison.CurrentCultureIgnoreCase))
                    {
                        xAttributes = extension.EventAttributes;
                    }
                    else if (tagName.Equals("meta", StringComparison.CurrentCultureIgnoreCase))
                    {
                        xAttributes = extension.MetaAttributes;
                    }
                    else if (tagName.Equals("string", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string key = reader.GetAttribute("key");
                        currentAttribute = factory.CreateAttributeLiteral(key, "DEFAULT", extension);
                        xAttributes.Add(key, currentAttribute);
                    }
                    else if (tagName.Equals("date", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string key = reader.GetAttribute("key");
                        currentAttribute = factory.CreateAttributeTimestamp(key, 0L, extension);
                        xAttributes.Add(key, currentAttribute);
                    }
                    else if (tagName.Equals("int", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string key = reader.GetAttribute("key");
                        currentAttribute = factory.CreateAttributeDiscrete(key, 0L, extension);
                        xAttributes.Add(key, currentAttribute);
                    }
                    else if (tagName.Equals("float", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string key = reader.GetAttribute("key");
                        currentAttribute = factory.CreateAttributeContinuous(key, 0.0D, extension);
                        xAttributes.Add(key, currentAttribute);
                    }
                    else if (tagName.Equals("boolean", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string key = reader.GetAttribute("key");
                        currentAttribute = factory.CreateAttributeBoolean(key, false, extension);
                        xAttributes.Add(key, currentAttribute);
                    }
                    else if (tagName.Equals("id", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string key = reader.GetAttribute("key");
                        currentAttribute = factory.CreateAttributeID(key, XIDFactory.Instance.CreateId(),
                                                                     extension);
                        xAttributes.Add(key, currentAttribute);
                    }
                    else if (tagName.Equals("alias", StringComparison.CurrentCultureIgnoreCase) && currentAttribute != null)
                    {
                        string mapping = reader.GetAttribute("mapping");
                        string name    = reader.GetAttribute("name");
                        XGlobalAttributeNameMap.Instance.RegisterMapping(mapping, currentAttribute.Key, name);
                    }
                    else
                    {
                        // non supported tag
                        XLogging.Log(String.Format("Non-supported tag '{0}' found. Ignoring it.", tagName), XLogging.Importance.TRACE);
                    }
                }
                // When a close tag is found (including empty elements)
                if (reader.IsEmptyElement || !reader.IsStartElement())
                {
                    string tagName = reader.LocalName;
                    if (tagName.Equals("", StringComparison.InvariantCultureIgnoreCase))
                    {
                        tagName = reader.Name;
                    }
                    if (ATTRIBUTE_TYPES.Contains(tagName.Trim().ToLower()))
                    {
                        currentAttribute = null;
                    }
                }
            }
            return(extension);
        }
示例#4
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);
        }
示例#5
-1
        /// <summary>
        /// Composes the appropriate attribute type from the string-based information
        /// found, e.g., in XML serializations.
        /// </summary>
        /// <returns>An appropriate attribute.</returns>
        /// <param name="factory">Factory to use for creating the attribute.</param>
        /// <param name="key">Key of the attribute.</param>
        /// <param name="value">Value of the attribute.</param>
        /// <param name="type">Type string of the attribute.</param>
        /// <param name="extension">Extension of the attribute (can be <code>null</code>).</param>
        public static XAttribute ComposeAttribute(IXFactory factory, string key, string value, string type,
                                                  XExtension extension)
        {
            type = type.Trim();
            if (type.Equals("LIST", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeList attr = factory.CreateAttributeList(key, extension);
                return(attr);
            }
            if (type.Equals("CONTAINER", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeContainer attr = factory.CreateAttributeContainer(key, extension);
                return(attr);
            }
            if (type.Equals("LITERAL", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeLiteral attr = factory.CreateAttributeLiteral(key, value, extension);

                return(attr);
            }
            if (type.Equals("BOOLEAN", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeBoolean attr = factory.CreateAttributeBoolean(key, bool.Parse(value), extension);

                return(attr);
            }
            if (type.Equals("CONTINUOUS", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeContinuous attr = factory.CreateAttributeContinuous(key, double.Parse(value), extension);

                return(attr);
            }
            if (type.Equals("DISCRETE", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeDiscrete attr = factory.CreateAttributeDiscrete(key, long.Parse(value), extension);

                return(attr);
            }
            if (type.Equals("TIMESTAMP", StringComparison.CurrentCultureIgnoreCase))
            {
                IXAttributeTimestamp attr;
                try
                {
                    attr = factory.CreateAttributeTimestamp(key, DateTime.Parse(value), extension);
                }
                catch (FormatException)
                {
                    throw new InvalidOperationException("OpenXES: could not parse date-time attribute. Value: " + value);
                }

                return((XAttributeTimestamp)attr);
            }
            if (type.Equals("ID", StringComparison.CurrentCultureIgnoreCase))
            {
                XAttributeID attr = factory.CreateAttributeID(key, XID.Parse(value), extension);
                return(attr);
            }
            throw new InvalidOperationException("OpenXES: could not parse attribute type!");
        }