Example #1
0
 /// <summary>
 /// Get the type of the action with the specified command name
 /// </summary>
 /// <param name="commandName"></param>
 /// <returns></returns>
 public Type GetActionDefinition(string commandName)
 {
     if (LoadedActions.ContainsKey(commandName))
     {
         return(LoadedActions[commandName]);
     }
     return(null);
 }
Example #2
0
        /// <summary>
        /// Get an action by its command name, without executing it
        /// </summary>
        /// <param name="commandName"></param>
        /// <returns></returns>
        public IAction GetAction(string commandName)
        {
            IAction action = null;

            if (LoadedActions.ContainsKey(commandName))
            {
                Type type = LoadedActions[commandName];
                action = (IAction)Activator.CreateInstance(type, true);
            }
            else if (string.IsNullOrWhiteSpace(commandName))
            {
                action = LastCommand;
            }
            else
            {
                Core.PrintLine("Newt command '" + commandName + "' is not loaded or is not available within this host environment.");
            }
            return(action);
        }
Example #3
0
File: Action.cs Project: VsPun/DPP
        public Action(IActionProcessor parameters)
            : this()
        {
            logger = Logger.GetLoggerEx(this.ActionId + BitConverter.ToInt64(parameters.ProcessId.ToByteArray(), 8));

            Logger.Info(string.Format("Action \"{0}\" activating", this.ActionId));

            if (this.usedActionParams == null)
            {
                throw new ArgumentNullException("The list of used action parameters is not defined.");
            }

            this.Parameters = parameters;

            //Create instance of result
            ConstructorInfo ctor = typeof(R).GetConstructors().First(c => c.GetParameters().Count() == 0);

            LoadedActions.ObjectActivator <R> createdActivator = LoadedActions.GetActivator <R>(ctor);
            this.returnResult = createdActivator();

            Logger.Info(string.Format("Action \"{0}\" activated", this.ActionId));
        }
Example #4
0
        public object ToType(Type conversionType, IFormatProvider provider)
        {
            if (conversionType.Equals(this.GetType()))
            {
                return(this);
            }

            //Get property info for Value poperty
            PropertyInfo pi = conversionType.GetProperty(VALUR_PROPERTY_NAME);

            //Create a new ActionParam
            ConstructorInfo ctor = conversionType.GetConstructors().First(c => c.GetParameters().Count() == 0);

            LoadedActions.ObjectActivator <IActionParam> createdActivator = LoadedActions.GetActivator <IActionParam>(ctor);
            IActionParam art = createdActivator();


            //Convert the value into new type of ActionParam
            pi.SetValue(art, Convert.ChangeType(this.Value, pi.PropertyType, System.Globalization.CultureInfo.InvariantCulture), null);

            return(art);
        }
Example #5
0
 public ActionSereilizer(string actionId)
 {
     actionParameters = LoadedActions.GetActionParams(actionId);
 }
Example #6
0
        /// <summary>
        /// Load a plugin action set from an assembly
        /// </summary>
        /// <param name="filePath"></param>
        public void LoadPlugin(Assembly pluginAss)
        {
            if (pluginAss != null)
            {
                Type[] types = pluginAss.GetTypes();
                foreach (Type type in types)
                {
                    if (typeof(IAction).IsAssignableFrom(type) && !type.IsAbstract)
                    {
                        string   commandName;
                        object[] typeAtts = type.GetCustomAttributes(typeof(ActionAttribute), false);
                        if (typeAtts.Count() > 0)
                        {
                            ActionAttribute aAtt = (ActionAttribute)typeAtts[0];
                            commandName = aAtt.CommandName;
                        }
                        else
                        {
                            commandName = type.Name;
                        }

                        if (LoadedActions.ContainsKey(commandName))
                        {
                            Core.PrintLine("Could not load action with command name '" + commandName +
                                           "' from assembly '" + pluginAss.Location + "' - an action with the same name is already loaded");
                        }
                        else
                        {
                            LoadedActions.Add(commandName, type);

                            //Importer actions
                            if (typeof(IImportAction).IsAssignableFrom(type))
                            {
                                ImportActionAttribute importAtt = ImportActionAttribute.ExtractFrom(type);
                                if (importAtt != null)
                                {
                                    foreach (string extension in importAtt.Extensions)
                                    {
                                        string ext = extension.ToLower();
                                        if (ExtensionImporters.ContainsKey(ext))
                                        {
                                            Core.PrintLine("Warning: Importer for file extension '" + extension + "' is already loaded.  Extension is ambiguous.");
                                        }
                                        ExtensionImporters[ext] = type;
                                    }
                                }
                            }

                            //Exporter actions:
                            if (typeof(IExportAction).IsAssignableFrom(type))
                            {
                                ExportActionAttribute exportAtt = ExportActionAttribute.ExtractFrom(type);
                                if (exportAtt != null)
                                {
                                    foreach (string extension in exportAtt.Extensions)
                                    {
                                        string ext = extension.ToLower();
                                        if (ExtensionExporters.ContainsKey(ext))
                                        {
                                            Core.PrintLine("Warning: Exporter for file extension '" + extension + "' is already loaded.  Extension is ambiguous.");
                                        }
                                        ExtensionExporters[ext] = type;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #7
0
 public T GetDefaultInstance()
 {
     return(LoadedActions.GetDefaultInstance <T>());
 }