protected void LoadWorkflowResourceFile(string filePath)
        {
            try
            {
                XPathDocument  doc = new XPathDocument(filePath);
                XPathNavigator nav = doc.CreateNavigator();
                nav.MoveToChild(XPathNodeType.Element);
                if (nav.LocalName != "Workflow")
                {
                    throw new ArgumentException(
                              "File is no workflow descriptor file (document element must be 'Workflow')");
                }

                bool           versionOk = false;
                XPathNavigator attrNav   = nav.Clone();
                if (attrNav.MoveToFirstAttribute())
                {
                    do
                    {
                        switch (attrNav.Name)
                        {
                        case "DescriptorVersion":
                            Versions.CheckVersionCompatible(attrNav.Value, WORKFLOW_RESOURCE_SPEC_VERSION_MAJOR, MIN_WORKFLOW_RESOURCE_SPEC_VERSION_MINOR);
                            //string specVersion = attr.Value; <- if needed
                            versionOk = true;
                            break;

                        default:
                            throw new ArgumentException("'Workflow' element doesn't support an attribute '" + attrNav.Name + "'");
                        }
                    } while (attrNav.MoveToNextAttribute());
                }
                if (!versionOk)
                {
                    throw new ArgumentException("'DescriptorVersion' attribute expected");
                }

                XPathNavigator childNav = nav.Clone();
                if (childNav.MoveToChild(XPathNodeType.Element))
                {
                    do
                    {
                        switch (childNav.LocalName)
                        {
                        case "MenuActions":
                            foreach (WorkflowAction action in LoadActions(childNav))
                            {
                                if (_menuActions.ContainsKey(action.ActionId))
                                {
                                    throw new ArgumentException(string.Format(
                                                                    "A menu action with id '{0}' was already registered with action name '{1}' (name of duplicate action is '{2}') -> Forgot to create a new GUID?",
                                                                    action.ActionId, _menuActions[action.ActionId].Name, action.Name));
                                }
                                _menuActions.Add(action.ActionId, action);
                            }
                            break;

                        default:
                            throw new ArgumentException("'Workflow' element doesn't support a child element '" + childNav.Name + "'");
                        }
                    } while (childNav.MoveToNext(XPathNodeType.Element));
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Error loading workflow resource file '" + filePath + "'", e);
            }
        }
        /// <summary>
        /// Loads the plugin descriptor file (plugin.xml) from a plugin directory.
        /// </summary>
        /// <param name="pluginDirectoryPath">Root directory path of the plugin to load the metadata.</param>
        /// <returns><c>true</c>, if the plugin descriptor could successfully be loaded, else <c>false</c>.
        /// </returns>
        protected bool Load(string pluginDirectoryPath)
        {
            string path = Path.Combine(pluginDirectoryPath, PLUGIN_META_FILE);

            if (!File.Exists(path))
            {
                return(false);
            }
            _pluginFilePath = path;
            try
            {
                using (Stream pluginFileStream = File.OpenRead(_pluginFilePath))
                {
                    XPathDocument  doc = new XPathDocument(pluginFileStream);
                    XPathNavigator nav = doc.CreateNavigator();
                    nav.MoveToChild(XPathNodeType.Element);
                    if (nav.LocalName != "Plugin")
                    {
                        throw new ArgumentException(
                                  "File is no plugin descriptor file (document element must be 'Plugin')");
                    }

                    bool           versionOk   = false;
                    bool           pluginIdSet = false;
                    XPathNavigator attrNav     = nav.Clone();
                    if (attrNav.MoveToFirstAttribute())
                    {
                        do
                        {
                            switch (attrNav.Name)
                            {
                            case "DescriptorVersion":
                                Versions.CheckVersionCompatible(attrNav.Value, PLUGIN_DESCRIPTOR_VERSION_MAJOR, MIN_PLUGIN_DESCRIPTOR_VERSION_MINOR);
                                //string specVersion = attr.Value; <- if needed
                                versionOk = true;
                                break;

                            case "Name":
                                _name = attrNav.Value;
                                break;

                            case "PluginId":
                                _pluginId   = new Guid(attrNav.Value);
                                pluginIdSet = true;
                                break;

                            case "Author":
                                _author = attrNav.Value;
                                break;

                            case "Copyright":
                                _copyright = attrNav.Value;
                                break;

                            case "Description":
                                _description = attrNav.Value;
                                break;

                            case "PluginVersion":
                                _version = attrNav.Value;
                                break;

                            case "AutoActivate":
                                _autoActivate = Boolean.Parse(attrNav.Value);
                                break;

                            default:
                                throw new ArgumentException("'Plugin' element doesn't support an attribute '" + attrNav.Name + "'");
                            }
                        } while (attrNav.MoveToNextAttribute());
                    }
                    if (!versionOk)
                    {
                        throw new ArgumentException("'Version' attribute not found");
                    }

                    if (!pluginIdSet)
                    {
                        throw new ArgumentException("'PluginId' attribute not found");
                    }

                    XPathNavigator childNav = nav.Clone();
                    if (childNav.MoveToChild(XPathNodeType.Element))
                    {
                        do
                        {
                            switch (childNav.LocalName)
                            {
                            case "Runtime":
                                ParseRuntimeElement(childNav.Clone(), pluginDirectoryPath);
                                break;

                            case "Builder":
                                if (_builders == null)
                                {
                                    _builders = new Dictionary <string, string>();
                                }
                                _builders.Add(ParseBuilderElement(childNav.Clone()));
                                break;

                            case "Register":
                                CollectionUtils.AddAll(_itemsMetadata, ParseRegisterElement(childNav.Clone()));
                                break;

                            case "DependsOn":
                                CollectionUtils.AddAll(_dependsOn, ParsePluginIdEnumeration(childNav.Clone()));
                                break;

                            case "ConflictsWith":
                                CollectionUtils.AddAll(_conflictsWith, ParsePluginIdEnumeration(childNav.Clone()));
                                break;

                            default:
                                throw new ArgumentException("'Plugin' element doesn't support a child element '" + childNav.Name + "'");
                            }
                        } while (childNav.MoveToNext(XPathNodeType.Element));
                    }
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Error parsing plugin descriptor file '" + _pluginFilePath + "'", e);
                return(false);
            }
            return(true);
        }
Beispiel #3
0
    protected bool LoadMetadata(string metaFilePath)
    {
      try
      {
        XPathDocument doc = new XPathDocument(metaFilePath);
        XPathNavigator nav = doc.CreateNavigator();
        nav.MoveToChild(XPathNodeType.Element);
        if (nav.LocalName != "Theme")
          throw new ArgumentException("File is no theme descriptor (needs to contain a 'Theme' element)");

        bool versionOk = false;
        XPathNavigator attrNav = nav.Clone();
        if (attrNav.MoveToFirstAttribute())
          do
          {
            switch (attrNav.Name)
            {
              case "Version":
                Versions.CheckVersionCompatible(attrNav.Value, THEME_DESCRIPTOR_VERSION_MAJOR, MIN_THEME_DESCRIPTOR_VERSION_MINOR);
                _specVersion = attrNav.Value;
                versionOk = true;
                break;
              case "Name":
                if (_name != null && _name != attrNav.Value)
                  throw new ArgumentException("Theme name '" + _name + "' doesn't correspond to specified name '" + attrNav.Value + "'");
                _name = attrNav.Value;
                break;
              default:
                throw new ArgumentException("Attribute '" + attrNav.Name + "' is unknown");
            }
          } while (attrNav.MoveToNextAttribute());
        if (!versionOk)
          throw new ArgumentException("Attribute 'Version' expected");

        XPathNavigator childNav = nav.Clone();
        if (childNav.MoveToChild(XPathNodeType.Element))
          do
          {
            switch (childNav.LocalName)
            {
              case "ShortDescription":
                _description = childNav.Value;
                break;
              case "Preview":
                _previewResourceKey = childNav.Value;
                break;
              case "Author":
                _author = childNav.Value;
                break;
              case "ThemeVersion":
                _themeVersion = childNav.Value;
                break;
              case "SkinEngine":
                _skinEngineVersion = childNav.Value;
                break;
              case "MinColorDepth":
                _minColorDepth = Int32.Parse(childNav.Value);
                break;
              case "BasedOnTheme":
                _basedOnTheme = childNav.Value;
                break;
              default:
                throw new ArgumentException("Child element '" + childNav.Name + "' is unknown");
            }
          } while (childNav.MoveToNext(XPathNodeType.Element));
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Error("Error parsing theme descriptor '" + metaFilePath + "'", e);
        return false;
      }
      return true;
    }
Beispiel #4
0
        protected bool LoadMetadata(string metaFilePath)
        {
            try
            {
                XPathDocument  doc = new XPathDocument(metaFilePath);
                XPathNavigator nav = doc.CreateNavigator();
                nav.MoveToChild(XPathNodeType.Element);
                if (nav.LocalName != "Skin")
                {
                    throw new ArgumentException("File is no skin descriptor (needs to contain a 'Skin' element)");
                }

                bool           versionOk = false;
                XPathNavigator attrNav   = nav.Clone();
                if (attrNav.MoveToFirstAttribute())
                {
                    do
                    {
                        switch (attrNav.Name)
                        {
                        case "Version":
                            Versions.CheckVersionCompatible(attrNav.Value, SKIN_DESCRIPTOR_VERSION_MAJOR, MIN_SKIN_DESCRIPTOR_VERSION_MINOR);
                            _specVersion = attrNav.Value;
                            versionOk    = true;
                            break;

                        case "Name":
                            if (_name != null && _name != attrNav.Value)
                            {
                                throw new ArgumentException("Skin name '" + _name + "' doesn't correspond to specified name '" + attrNav.Value + "'");
                            }
                            _name = attrNav.Value;
                            break;

                        default:
                            throw new ArgumentException("Attribute '" + attrNav.Name + "' is unknown");
                        }
                    } while (attrNav.MoveToNextAttribute());
                }
                if (!versionOk)
                {
                    throw new ArgumentException("Attribute 'Version' expected");
                }

                XPathNavigator childNav = nav.Clone();
                if (childNav.MoveToChild(XPathNodeType.Element))
                {
                    do
                    {
                        switch (childNav.LocalName)
                        {
                        case "ShortDescription":
                            _description = childNav.Value;
                            break;

                        case "UsageNote":
                            _usageNote = childNav.Value;
                            break;

                        case "Preview":
                            _previewResourceKey = childNav.Value;
                            break;

                        case "Author":
                            _author = childNav.Value;
                            break;

                        case "SkinVersion":
                            _skinVersion = childNav.Value;
                            break;

                        case "SkinEngine":
                            _skinEngineVersion = childNav.Value;
                            break;

                        case "FlexibleAspectRatio":
                            _flexibleAspectRatio = bool.Parse(childNav.Value);
                            break;

                        case "NativeWidth":
                            _nativeWidth = Int32.Parse(childNav.Value);
                            break;

                        case "NativeHeight":
                            _nativeHeight = Int32.Parse(childNav.Value);
                            break;

                        case "DefaultTheme":
                            _defaultThemeName = childNav.Value;
                            break;

                        case "BasedOnSkin":
                            _basedOnSkin = childNav.Value;
                            break;

                        case "BasedOnTheme":
                            _basedOnTheme = childNav.Value;
                            break;

                        default:
                            throw new ArgumentException("Child element '" + childNav.Name + "' is unknown");
                        }
                    } while (childNav.MoveToNext(XPathNodeType.Element));
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Error parsing skin descriptor '" + metaFilePath + "'", e);
                return(false);
            }
            return(true);
        }
        protected void LoadShortcutResourceFile(string filePath, bool isWorkflowSate)
        {
            try
            {
                XPathDocument  doc = new XPathDocument(filePath);
                XPathNavigator nav = doc.CreateNavigator();
                nav.MoveToChild(XPathNodeType.Element);
                if (nav.LocalName != "Shortcut")
                {
                    throw new ArgumentException(
                              "File is no shortcut descriptor file (document element must be 'Shortcut')");
                }

                bool           versionOk = false;
                XPathNavigator attrNav   = nav.Clone();
                if (attrNav.MoveToFirstAttribute())
                {
                    do
                    {
                        switch (attrNav.Name)
                        {
                        case "DescriptorVersion":
                            Versions.CheckVersionCompatible(attrNav.Value, SHORTCUT_RESOURCE_SPEC_VERSION_MAJOR, MIN_SHORTCUT_RESOURCE_SPEC_VERSION_MINOR);
                            //string specVersion = attr.Value; <- if needed
                            versionOk = true;
                            break;

                        default:
                            throw new ArgumentException("'Shortcut' element doesn't support an attribute '" + attrNav.Name + "'");
                        }
                    } while (attrNav.MoveToNextAttribute());
                }
                if (!versionOk)
                {
                    throw new ArgumentException("'DescriptorVersion' attribute expected");
                }

                XPathNavigator childNav = nav.Clone();
                if (childNav.MoveToChild(XPathNodeType.Element))
                {
                    do
                    {
                        switch (childNav.LocalName)
                        {
                        case "WorkflowActions":
                            if (!isWorkflowSate)
                            {
                                foreach (KeyActionMapping actionMapping in LoadActionShortcuts(childNav))
                                {
                                    foreach (Key key in actionMapping.Keys)
                                    {
                                        AvoidDuplicateKeys(key);
                                        _workflowActionShortcuts.Add(key, actionMapping.Action);
                                    }
                                }
                            }
                            break;

                        case "WorkflowStates":
                            if (isWorkflowSate)
                            {
                                foreach (KeyStateMapping actionMapping in LoadStateShortcuts(childNav))
                                {
                                    foreach (Key key in actionMapping.Keys)
                                    {
                                        AvoidDuplicateKeys(key);
                                        _workflowStateShortcuts.Add(key, actionMapping.State);
                                    }
                                }
                            }
                            break;

                        default:
                            throw new ArgumentException("'Shortcut' element doesn't support a child element '" + childNav.Name + "'");
                        }
                    } while (childNav.MoveToNext(XPathNodeType.Element));
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Error loading shortcut resource file '" + filePath + "'", e);
            }
        }