Esempio n. 1
0
        public void GetxLogger()
        {
            xLogger test = xLogManager.GetxLogger("test");

            Assert.IsType(typeof(xLogger), test);
            Assert.Equal("test", test.Name);
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SimulationConnector"/> class.
        /// </summary>
        /// <param name="manager">The ApplicationManager instance.</param>
        /// <param name="instanceName">The assigned name for this instance.</param>
        /// <param name="logger">The logger for this instance.</param>
        public SimulationConnector(IApplicationManager manager, string instanceName, xLogger logger)
        {
            InstanceName = instanceName;
            this.logger  = logger;

            Manager = manager;

            Name       = "Simulation";
            FQN        = "OpenIIoT.Plugin.Connector.Simulation";
            Version    = "1.0.0.0";
            PluginType = PluginType.Connector;

            ItemProviderName = FQN;

            logger.Info("Initializing " + PluginType + " " + FQN + "." + instanceName);

            InitializeItems();

            random      = new Random();
            randomValue = 0;

            rwValue     = new ReadWriteValue();
            rwValue.Min = 0L;
            rwValue.Max = 100L;

            Subscriptions = new Dictionary <Item, List <Action <object> > >();

            ConfigureFileWatch();
        }
Esempio n. 3
0
        public void GetCurrentClassxLogger()
        {
            xLogger test = xLogManager.GetCurrentClassxLogger();

            Assert.IsType(typeof(xLogger), test);
            Assert.Equal(GetType().FullName, test.Name);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="SQLConnector"/> class.
        /// </summary>
        /// <param name="manager">The ApplicationManager instance.</param>
        /// <param name="instanceName">The assigned name for this instance.</param>
        /// <param name="logger">The logger for this instance.</param>
        public SQLConnector(IApplicationManager manager, string instanceName, xLogger logger)
        {
            InstanceName = instanceName;
            this.logger = logger;

            Name = "SQL";
            FQN = "OpenIIoT.Plugin.Connector.SQL";
            Version = "1.0.0.0";
            PluginType = PluginType.Connector;

            Manager = manager;

            ItemProviderName = FQN;

            logger.Info("Initializing " + PluginType + " " + FQN + "." + instanceName);

            Configure();

            InitializeItems();

            timer = new System.Timers.Timer(500);
            timer.Elapsed += Timer_Elapsed;

            Subscriptions = new Dictionary<Item, List<Action<object>>>();
            TriggerCache = new Dictionary<Item, string>();
        }
Esempio n. 5
0
        public void Constructor()
        {
            xLogger testLogger = (xLogger)LogManager.GetLogger("test", typeof(xLogger));

            Assert.IsType <xLogger>(testLogger);

            List <Tuple <Guid, DateTime> > persistedMethods = testLogger.PersistedMethods;

            Assert.Equal(0, persistedMethods.Count);
        }
Esempio n. 6
0
        /// <summary>
        ///     Iterates over the specified List of type <see cref="PluginManagerConfigurationPluginInstance"/>, retrieves the
        ///     matching PluginAssembly from the supplied List of type PluginAssembly and instantiates each instance, passing the
        ///     instance name and an instance of xLogger with the Fully Qualified Name of the instance.
        /// </summary>
        /// <remarks>
        ///     The <see cref="InstantiatePlugin{T}(IApplicationManager, string, xLogger)"/> method is invoked via reflection so
        ///     that the type parameter for the method can be specified dynamically.
        /// </remarks>
        /// <returns>A Result containing the result of the operation and a Dictionary containing the instantiated Plugins.</returns>
        private Result <List <IPluginInstance> > InstantiatePlugins()
        {
            logger.EnterMethod();
            logger.Info("Creating Plugin Instances...");

            Result <List <IPluginInstance> > retVal = new Result <List <IPluginInstance> >();

            retVal.ReturnValue = new List <IPluginInstance>();

            IApplicationManager applicationManager = Dependency <IApplicationManager>();

            // iterate over the configured plugin instances from the configuration
            foreach (PluginManagerConfigurationPluginInstance instance in Configuration.Instances)
            {
                logger.SubSubHeading(LogLevel.Debug, "Instance: " + instance.InstanceName);
                logger.Info("Creating instance '" + instance.InstanceName + "' of Type '" + instance.AssemblyName + "'...");

                // locate the PluginAssembly matching the instance
                IPluginAssembly assembly = FindPluginAssembly(instance.AssemblyName);
                if (assembly == default(PluginAssembly))
                {
                    retVal.AddWarning("Plugin assembly '" + instance.AssemblyName + "' not found in the list of loaded assemblies.");
                }
                else
                {
                    // create an instance of xLogger for the new instance
                    xLogger instanceLogger = (xLogger)LogManager.GetLogger(assembly.FQN + "." + instance.InstanceName, typeof(xLogger));

                    // invoke the CreatePluginInstance method
                    MethodInfo method = this.GetType().GetMethod("InstantiatePlugin").MakeGenericMethod(assembly.Type);
                    Result <IPluginInstance> invokeResult = (Result <IPluginInstance>)method.Invoke(this, new object[] { applicationManager, instance.InstanceName, instanceLogger });

                    // if the invocation succeeded, add the result to the Instances Dictionary
                    if (invokeResult.ResultCode == ResultCode.Success)
                    {
                        retVal.ReturnValue.Add(invokeResult.ReturnValue);
                        logger.Info("Instantiated " + assembly.PluginType.ToString() + " plugin '" + instance.InstanceName + "'.");
                    }

                    invokeResult.LogResult(logger, "InstantiatePlugin");
                    retVal.Incorporate(invokeResult);
                }
            }

            retVal.LogResult(logger);
            logger.ExitMethod(retVal);
            return(retVal);
        }
Esempio n. 7
0
        /// <summary>
        ///     The default constructor.
        /// </summary>
        /// <param name="instanceName">The name of the instance, provided by the Plugin Manager.</param>
        public ExampleConnector(IApplicationManager manager, string instanceName, xLogger logger)
        {
            //------ ----------------------  --------------------------------------   -   -     -  -         ---- -
            // boilerplate code; this should appear in the majority of Connectors

            // assign variables and properties
            this.manager = manager;
            InstanceName = instanceName;
            this.logger  = logger;

            // log the entry of the method
            logger.EnterMethod(xLogger.Params(new xLogger.ExcludedParam(), instanceName, new xLogger.ExcludedParam()));

            // set up metadata The name of the assembly should generally be the same as the Connector Name.
            Name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

            // The FQN should generally correspond to the namespace of the Connector class note that the code below references the
            // first Type in the assembly; this may need to be adjusted depending on the composition of the Connector.
            FQN = System.Reflection.Assembly.GetExecutingAssembly().GetTypes()[0].Namespace;

            // The version should generally match the assembly version.
            Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // The PluginType will always be PluginType.Connector.
            PluginType = PluginType.Connector;

            // Set the initial State
            State = State.Stopped;

            logger.Checkpoint(xLogger.Vars(this), "Connector");

            logger.Info("Initializing Plugin " + FQN + "." + instanceName + "'...");

            // end of boilerplate
            //-------------------   --- -- ----------------------------------------------------  --  -  -

            // If the Connector implements ISubscribable, initialize the Subscriptions dictionary.
            Subscriptions = new Dictionary <Item, int>();

            // create a timer to "poll" for the current time this is analogous to code that would poll an external data source
            timer          = new Timer(1000);
            timer.Elapsed += Timer_Elapsed;

            //----------------------------------------------------- -  --------------  -
            // configuration boilerplate
            logger.Info("Configuring '" + instanceName + "'...");

            // configure the Connector
            Result configureResult = Configure();

            // if configuration fails, set the State property to State.Faulted, log the failure, and throw an exception.
            if (configureResult.ResultCode == ResultCode.Failure)
            {
                State = State.Faulted;

                string message = "Failed to configure " + PluginType + " '" + FQN + "." + instanceName + "': " + configureResult.GetLastError();
                logger.Error(message);
                throw new Exception(message);
            }

            logger.Checkpoint("Configured " + InstanceName, xLogger.Vars(Configuration));

            // end of configuration boilerplate
            //-------------------------  -      ------------------  -       --

            // create the Item model for the Connector
            InitializeItems();

            // log the exit of the method
            logger.ExitMethod();
        }
 public ExampleEndpoint(IApplicationManager manager, string instanceName, xLogger logger)
 {
     this.manager = manager;
     InstanceName = instanceName;
     this.logger  = logger;
 }
Esempio n. 9
0
        /// <summary>
        ///     Creates and returns an instance of the specified plugin type with the specified name
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         The instanceName is propagated through the plugin instance and any internal reference (such as a
        ///         ConnectorItem). This name should match references to the plugin, either through fully qualified addressing or configuration.
        ///     </para>
        /// </remarks>
        /// <param name="instanceManager">The ApplicationManager instance to be passed to the Plugin instance.</param>
        /// <param name="instanceName">The desired internal name of the instance</param>
        /// <param name="instanceLogger">The logger for the plugin instance.</param>
        /// <typeparam name="T">The Type of the Plugin instance to create.</typeparam>
        /// <returns>A Result containing the result of the operation and the created Plugin instance.</returns>
        public Result <IPluginInstance> InstantiatePlugin <T>(IApplicationManager instanceManager, string instanceName, xLogger instanceLogger)
        {
            logger.EnterMethod(xLogger.Params(instanceName));
            logger.Debug("Creating plugin instance '" + instanceName + "' of Type '" + typeof(T).Name + "'...");

            Result <IPluginInstance> retVal = new Result <IPluginInstance>();

            try
            {
                // check to see if the instance name has already been used
                if (FindPluginInstance(instanceName) == default(IPluginInstance))
                {
                    logger.Trace("Creating instance of plugin type '" + typeof(T).ToString() + "' with instance name '" + instanceName + "'");
                    retVal.ReturnValue = (IPluginInstance)Activator.CreateInstance(typeof(T), instanceManager, instanceName, instanceLogger);
                }
                else
                {
                    retVal.AddError("A plugin with InstanceName '" + instanceName + "' has already been instantiated.");
                }
            }
            catch (Exception ex)
            {
                logger.Exception(LogLevel.Error, ex);
                retVal.AddError("Exception caught while creating plugin instance '" + instanceName + "': " + ex.Message);
            }

            retVal.LogResult(logger.Debug);
            logger.ExitMethod(retVal);
            return(retVal);
        }