public void InitializeFromFilePath()
        {
            var test = new
                {
                    TemplateName = "EventContainingAttributesOfAllTypes",
                    UInt16Attribute = new { Name = "UnsignedShortValue", Token = TypeToken.UINT16, Ordinal = 0 },
                    Int16Attribute = new { Name = "SignedShortValue", Token = TypeToken.INT16, Ordinal = 1 },
                    UInt32Attribute = new { Name = "UnsignedIntValue", Token = TypeToken.UINT32, Ordinal = 2 },
                    Int32Attribute = new { Name = "SignedIntValue", Token = TypeToken.INT32, Ordinal = 3 },
                    StringAttribute = new { Name = "StringValue", Token = TypeToken.STRING, Ordinal = 4 },
                    IPAddressAttribute = new { Name = "IPAddressValue", Token = TypeToken.IP_ADDR, Ordinal = 5 },
                    Int64Attribute = new { Name = "SignedLongValue", Token = TypeToken.INT64, Ordinal = 6 },
                    UInt64Attribute = new { Name = "UnsignedLongValue", Token = TypeToken.UINT64, Ordinal = 7 },
                    BooleanAttribute = new { Name = "BooleanValue", Token = TypeToken.BOOLEAN, Ordinal = 8 }
                };

            FilePathEventTemplateDB db = new FilePathEventTemplateDB();

            Assert.IsFalse(db.IsInitialized);

            string filePath = Environment.CurrentDirectory;
            db.InitializeFromFilePath(filePath, false);

            Assert.IsTrue(db.IsInitialized);
            Assert.IsTrue(db.TemplateExists(test.TemplateName));

            EventTemplate ev = db.GetEventTemplate(test.TemplateName);
            Assert.IsInstanceOfType(ev, typeof(EventTemplate));

            EventTemplate ev1;
            Assert.IsTrue(db.TryGetEventTemplate(test.TemplateName, out ev1));

            Assert.IsTrue(ev.HasAttribute(test.UInt16Attribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.Int16Attribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.UInt32Attribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.Int32Attribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.StringAttribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.IPAddressAttribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.Int64Attribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.UInt64Attribute.Name));
            Assert.IsTrue(ev.HasAttribute(test.BooleanAttribute.Name));

            Assert.AreEqual(TypeToken.UINT16, ev[test.UInt16Attribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.INT16, ev[test.Int16Attribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.UINT32, ev[test.UInt32Attribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.INT32, ev[test.Int32Attribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.STRING, ev[test.StringAttribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.IP_ADDR, ev[test.IPAddressAttribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.INT64, ev[test.Int64Attribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.UINT64, ev[test.UInt64Attribute.Ordinal].TypeToken);
            Assert.AreEqual(TypeToken.BOOLEAN, ev[test.BooleanAttribute.Ordinal].TypeToken);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an event template DB from the configuration.
        /// </summary>
        /// <param name="name">name of the instance to create</param>
        /// <returns>the named instance if it exists within the configuration;
        /// otherwise null</returns>
        /// <remarks>Note that two subsequent calls to this method will return
        /// two separate instances of the configured instance.</remarks>
        public static IEventTemplateDB CreateFromConfig(string name)
        {
            LwesConfigurationSection config = LwesConfigurationSection.Current;
            if (config.TemplateDBs == null) return null;

            TemplateDBConfigurationSection namedTemplateDBConfig = config.TemplateDBs[name];
            if (namedTemplateDBConfig == null)
            {
                Traceable.TraceData(typeof(EventTemplateDB), TraceEventType.Verbose, () =>
                {
                    return new object[] { String.Concat("EventTemplateDB - no configuration for template db: ", name) };
                });
                return null;
            }

            Traceable.TraceData(typeof(EventTemplateDB), TraceEventType.Verbose, () =>
            {
                return new object[] { String.Concat("EventTemplateDB - configuration found for template db: ", name) };
            });
            FilePathEventTemplateDB db = new FilePathEventTemplateDB();
            db.InitializeFromFilePath(namedTemplateDBConfig.Path, namedTemplateDBConfig.IncludeSubdirectories);
            return db;
        }
Ejemplo n.º 3
0
        private static IEventTemplateDB CreateFallbackTemplateDB()
        {
            Traceable.TraceData(typeof(EventTemplateDB), TraceEventType.Verbose, "EventTemplateDB - using fallback template DB" );

            FilePathEventTemplateDB db = new FilePathEventTemplateDB();
            db.InitializeFromFilePath(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, true);
            return db;
        }