Esempio n. 1
0
        /// <summary>
        /// Asks user for an alternate name for a Resource Action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnDuplicateResourceAction(object sender, ResourceActionEventArgs e)
        {
            StringInputBox sib = null;
            try
            {
                sib = new StringInputBox(Properties.AdminUIResources.ACTION_NAME_EXISTS, Properties.AdminUIResources.GENERAL_CAPTION);
                sib.MaxLength = ResourceListController.ACTION_NAME_MAX_LENGTH;
                sib.Value = e.ResourceAction.Name;
                sib.CustomValidating += new CancelEventHandler(sib_CustomValidating);

                if (sib.ShowDialog() == DialogResult.OK)
                {
                    e.ResourceAction.Name = sib.Value;
                }
                else
                {
                    e.Cancel = true;
                }
            }
            finally
            {
                if (null != sib)
                {
                    sib.CustomValidating -= new CancelEventHandler(sib_CustomValidating);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Asks user for the name of a Resource Action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnBeforeAddResourceAction(object sender, ResourceActionEventArgs e)
        {
            if (!m_controller.AllowPreAddNameChange(e.ResourceAction))
            {
                return;
            }

            StringInputBox sib = null;
            try
            {
                sib = new StringInputBox(Properties.AdminUIResources.ACTION_NAME_ENTRY, Properties.AdminUIResources.GENERAL_CAPTION);
                sib.MaxLength = ResourceListController.ACTION_NAME_MAX_LENGTH;
                sib.CustomValidating += new CancelEventHandler(sib_CustomValidating);

                if (sib.ShowDialog() == DialogResult.OK)
                {
                    e.ResourceAction.Name = sib.Value;
                }
                else
                {
                    e.Cancel = true;
                }
            }
            finally
            {
                if (null != sib)
                {
                    sib.CustomValidating -= new CancelEventHandler(sib_CustomValidating);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This is the main method for adding actions to the resources.
        /// It is currently assumed that only a single action class and
        /// action property set class exists in the assembly. If the action
        /// property set does not exist then an empty one will be added
        /// </summary>
        /// <remarks>
        /// The action will not be added if an action of the same name already exists
        /// in the internal list
        /// </remarks>
        /// <param name="assemblypath">The fully specified path and filename of the assembly to be loaded</param>
        /// <returns>The resource action created from the action assembly, null if the Add was cancelled</returns>
        public IResourceAction Add(string assemblypath)
        {
            IResourceAction resourceAction = new ResourceAction();
            bool actionClassFound = false;

            Logger.LogDebug("Trying to load assembly: " + assemblypath);
            
            try
            {
                Assembly actionAssembly = Assembly.LoadFrom(assemblypath);

                // Need to find the action class and the property class within the assembly
                // Note that we're just getting the first one we find of each
                Type[] types = actionAssembly.GetTypes();

                //QUE???
                if (OnBeforeAddResourceAction != null)
                {
                    ResourceActionEventArgs args = new ResourceActionEventArgs(resourceAction);
                    OnBeforeAddResourceAction(this, args);
                    if (args.Cancel)
                    {
                        //We no longer want to add this action so can return straight away
                        return null;
                    }
                }
                actionClassFound = AddIAction3(types, actionAssembly, resourceAction as ResourceAction);

                if (!actionClassFound)
                    actionClassFound = AddIAction(types, actionAssembly, resourceAction as ResourceAction);

                if (actionClassFound)
                {
                    resourceAction.Assembly = actionAssembly.ManifestModule.Name;
                    //check for duplicate action already existing
                    if (DuplicateFoundInList(resourceAction) && OnDuplicateResourceAction != null)
                    {
                        ResourceActionEventArgs args = new ResourceActionEventArgs(resourceAction);
                        do
                        {
                            OnDuplicateResourceAction(this, args);
                        }
                        while (!args.Cancel && DuplicateFoundInList(resourceAction));

                        if (args.Cancel)
                        {
                            //We no longer want to add this action so can return straight away
                            return null;
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (Exception e in ex.LoaderExceptions)
                {
					Logger.LogError(string.Format(CultureInfo.InvariantCulture, "ResourceActions: error loading DLL {0}, {1}", assemblypath, e.GetType().ToString()));
					Logger.LogError(e);
                    Console.WriteLine(e.Message + e.GetType().ToString());
                }
            }
            catch (Exception e)
            {
                // File couldn't be found or couldn't be opened
				Logger.LogError("ResourceActions: error loading DLL " + assemblypath);
				Logger.LogError(e);
                throw new ApplicationException(Properties.Resources.COULD_NOT_LOAD_ACTION);
            }

            if (actionClassFound)
            {
                // Does the action already exist? If it does then don't add it.
                if (Contains(resourceAction))
                {
                    Logger.LogError(String.Format(CultureInfo.InvariantCulture, "ResourceActions: error loading DLL {0}, as action {1} already exists", assemblypath, resourceAction.Name));
                    throw new ApplicationException(Properties.Resources.COULD_NOT_LOAD_ACTION_ALREADY_EXISTS);
                }

                Add(resourceAction);
                return resourceAction; 
            }

            Logger.LogError(String.Format(CultureInfo.InvariantCulture, "ResourceActions: error loading DLL {0}, no action or property set in the dll", assemblypath));
            throw new ApplicationException(Properties.Resources.COULD_NOT_LOAD_ACTION);
        }
Esempio n. 4
0
        private bool AddIAction(Type[] types, Assembly actionAssembly, ResourceAction resourceAction)
        {
            bool actionClassFound = false;
            bool actionPropertyFound = false;
            bool actionPropertySetLayoutFound = false;

            foreach (Type type in types)
            {
                if (type.GetInterface(typeof(IAction).FullName) != null)
                {
                    actionClassFound = true;
                    
                    Logger.LogDebug("Loading action class: " + type.FullName);
                    resourceAction.ActionClass = type.FullName;
                    resourceAction.SetAction(actionAssembly.CreateInstance(type.FullName) as IAction);

                    if (null != OnBeforeAddResourceAction)
                    {
                        ResourceActionEventArgs args = new ResourceActionEventArgs(resourceAction);
                        OnBeforeAddResourceAction(this, args);
                        if (args.Cancel)
                        {
                            //We no longer want to add this action so can return straight away
                            return false;
                        }
                    }

                    //check for duplicate action already existing
                    if (DuplicateFoundInList(resourceAction) && OnDuplicateResourceAction != null)
                    {
                        ResourceActionEventArgs args = new ResourceActionEventArgs(resourceAction);
                        do
                        {
                            OnDuplicateResourceAction(this, args);
                        }
                        while (!args.Cancel && DuplicateFoundInList(resourceAction));

                        if (args.Cancel)
                        {
                            //We no longer want to add this action so can return straight away
                            return false;
                        }
                    }
                }
                if (type.GetInterface(typeof(IActionPropertySet).FullName) != null)
                {
                    actionPropertyFound = true;
                    LoadActionProperties(actionAssembly, resourceAction, type);
                }
                else
                {
                    CreateActionProperties(resourceAction);
                }

                //If we have this interface, we can populate an extra data structure 
                //and get some extra layout info
                if (type.GetInterface(typeof(IPropertySetLayout).FullName) != null)
                {
                    actionPropertySetLayoutFound = true;
                    LoadActionPropertyLayout(actionAssembly, resourceAction, type);
                }

                if (actionClassFound && actionPropertyFound && actionPropertySetLayoutFound)
                {
                    return true;
                }
            }

            // The least requirement is for the action and the action properties to be present.
            return (actionClassFound && actionPropertyFound); 
        }
Esempio n. 5
0
 public void OnDuplicateFound(object sender, ResourceActionEventArgs args)
 {
     DuplicateFound = true;
     args.Cancel = true;
 }