Esempio n. 1
0
 protected static ConfigSectionMetadata BuildSection(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
   string text = null;
   string iconSmallPath = null;
   string iconLargePath = null;
   foreach (KeyValuePair<string, string> attr in itemData.Attributes)
   {
     switch (attr.Key)
     {
       case "Text":
         text = attr.Value;
         break;
       case "IconSmallPath":
         iconSmallPath = attr.Value;
         break;
       case "IconLargePath":
         iconLargePath = attr.Value;
         break;
       default:
         throw new ArgumentException("'ConfigSection' builder doesn't define an attribute '" + attr.Key + "'");
     }
   }
   if (text == null)
     throw new ArgumentException("'ConfigSection' item needs an attribute 'Text'");
   return new ConfigSectionMetadata(location, text,
                                    plugin.Metadata.GetAbsolutePath(iconSmallPath),
                                    plugin.Metadata.GetAbsolutePath(iconLargePath));
 }
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ClassName", itemData);
   BuilderHelper.CheckParameter("ProviderName", itemData);
   BuilderHelper.CheckParameter("Priority", itemData);
   return new ThumbnailProviderRegistration(plugin.GetPluginType(itemData.Attributes["ClassName"]), itemData.Id, itemData.Attributes["ProviderName"], itemData.Attributes["Priority"]);
 }
 /// <summary>
 /// Registers the specified plugin item in the plugin tree.
 /// </summary>
 /// <param name="itemMetadata">Metadata structure of the item to register.</param>
 /// <returns><c>true</c>, if the plugin item could be registered, <c>false</c>,
 /// if the item already existed and <see cref="PluginItemMetadata.IsRedundant"/> is specified.</returns>
 /// <exception cref="ArgumentException">If there is already an item registered at the registration
 /// location and the <see cref="PluginItemMetadata.IsRedundant"/> flag is not set.</exception>
 internal bool RegisterItem(PluginItemMetadata itemMetadata)
 {
     lock (_syncObj)
     {
         IRegistryNode node = GetRegistryNode(itemMetadata.RegistrationLocation, true);
         itemMetadata.PluginRuntime = this;
         if (node.Items != null && node.Items.ContainsKey(itemMetadata.Id))
         {
             if (itemMetadata.IsRedundant)
             {
                 PluginItemRegistration itemRegistration = (PluginItemRegistration)node.Items[itemMetadata.Id];
                 itemRegistration.AdditionalRedundantItemsMetadata.Add(itemMetadata);
                 return(false);
             }
             else
             {
                 throw new ArgumentException(string.Format("At location '{0}', a plugin item with id '{1}' is already registered",
                                                           itemMetadata.RegistrationLocation, itemMetadata.Id));
             }
         }
         PluginItemRegistration resultItemRegistration = new PluginItemRegistration(itemMetadata);
         node.AddItem(itemMetadata.Id, resultItemRegistration);
         _itemRegistrations.Add(itemMetadata, resultItemRegistration);
     }
     return(true);
 }
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ClassName", itemData);
   BuilderHelper.CheckParameter("Caption", itemData);
   BuilderHelper.CheckParameter("Sort", itemData);
   return new MediaItemActionExtension(plugin.GetPluginType(itemData.Attributes["ClassName"]), itemData.Attributes["Caption"], itemData.Attributes["Sort"], itemData.Id);
 }
 /// <summary>
 /// Unregisters the specified plugin item from the plugin tree.
 /// </summary>
 /// <param name="itemMetadata">Meta data structure of the item to unregister.</param>
 /// <returns>Plugin item registration structure of the item to be unregistered.</returns>
 internal void UnregisterItem(PluginItemMetadata itemMetadata)
 {
     lock (_syncObj)
         try
         {
             IRegistryNode node = GetRegistryNode(itemMetadata.RegistrationLocation, false);
             if (node == null || node.Items == null)
             {
                 return;
             }
             if (node.Items.ContainsKey(itemMetadata.Id))
             {
                 PluginItemRegistration itemRegistration = (PluginItemRegistration)node.Items[itemMetadata.Id];
                 // Check, if there are additional redundant items registered at this position. If yes, we'll use
                 // the first of them instead of the old item to be unregistered.
                 PluginItemMetadata newItemMetadata          = null;
                 IEnumerator <PluginItemMetadata> enumerator = itemRegistration.AdditionalRedundantItemsMetadata.GetEnumerator();
                 if (enumerator.MoveNext())
                 {
                     newItemMetadata = enumerator.Current;
                     itemRegistration.AdditionalRedundantItemsMetadata.Remove(newItemMetadata);
                 }
                 node.Items.Remove(itemMetadata.Id);
                 if (newItemMetadata != null)
                 {
                     newItemMetadata.PluginRuntime.RegisterItem(newItemMetadata);
                 }
             }
         }
         finally
         {
             _itemRegistrations.Remove(itemMetadata);
         }
 }
Esempio n. 6
0
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ServiceClassName", itemData);
   string serviceClassName = itemData.Attributes["ServiceClassName"];
   object serviceInstance = plugin.InstantiatePluginObject(serviceClassName);
   if (serviceInstance == null)
   {
     ServiceRegistration.Get<ILogger>().Warn("ServiceBuilder: Could not instantiate service class '{0}' in plugin '{1}' (id: '{2}')",
         serviceClassName, itemData.PluginRuntime.Metadata.Name, itemData.PluginRuntime.Metadata.PluginId);
     return null;
   }
   string registrationClassAssembly;
   if (!itemData.Attributes.TryGetValue("RegistrationClassAssembly", out registrationClassAssembly))
     registrationClassAssembly = null;
   string registrationClassName;
   if (!itemData.Attributes.TryGetValue("RegistrationClassName", out registrationClassName))
     registrationClassName = null;
   Type registrationType;
   if (string.IsNullOrEmpty(registrationClassName))
     registrationType = serviceInstance.GetType();
   else
     registrationType = string.IsNullOrEmpty(registrationClassAssembly) ? plugin.GetPluginType(registrationClassName) :
         Type.GetType(registrationClassName + ", " + registrationClassAssembly);
   if (registrationType == null)
   {
     ServiceRegistration.Get<ILogger>().Warn("ServiceBuilder: Could not instantiate service registration type '{0}' (Assembly: '{1}') in plugin '{2}' (id: '{3}')",
         registrationClassName, registrationClassAssembly, itemData.PluginRuntime.Metadata.Name, itemData.PluginRuntime.Metadata.PluginId);
     return null;
   }
   return new ServiceItem(registrationType, serviceInstance);
 }
Esempio n. 7
0
 public static void CheckParameter(string parameterName, PluginItemMetadata itemData)
 {
   if (!itemData.Attributes.ContainsKey(parameterName))
     throw new PluginItemBuildException(
         "'{0}' item at registration location '{1}' needs to specify the '{2}' parameter",
             itemData.BuilderName, itemData.RegistrationLocation, parameterName);
 }
Esempio n. 8
0
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("Type", itemData);
   BuilderHelper.CheckParameter("Directory", itemData);
   return new PluginResource(
       (PluginResourceType) Enum.Parse(typeof (PluginResourceType), itemData.Attributes["Type"]),
       plugin.Metadata.GetAbsolutePath(itemData.Attributes["Directory"]));
 }
Esempio n. 9
0
 public void RevokeItem(object item, PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BackgroundType type;
   string typeName = GetBackgroundAndType(itemData.Attributes, out type);
   switch (type)
   {
     case BackgroundType.Manager:
       plugin.RevokePluginObject(typeName);
       break;
   }
 }
Esempio n. 10
0
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BackgroundType type;
   string value = GetBackgroundAndType(itemData.Attributes, out type);
   switch (type)
   {
     case BackgroundType.Static:
       return new StaticBackgroundManager(value);
     case BackgroundType.Manager:
       // The cast is necessary here to ensure the returned instance is an IBackgroundManager
       return (IBackgroundManager) plugin.InstantiatePluginObject(value);
     default:
       throw new NotImplementedException(string.Format(
           "Background builder: Background type '{0}' is not implemented", type));
   }
 }
    public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
    {
      BuilderHelper.CheckParameter("ClassName", itemData);
      BuilderHelper.CheckParameter("Filter", itemData);
      // Support for simplified escaping inside XML tag
      string filter = itemData.Attributes["Filter"].Replace("{", "<").Replace("}", ">");
      FilterWrapper wrapper;

      if (_serializer == null)
        _serializer = new XmlSerializer(typeof(FilterWrapper));

      using (var reader = new StringReader(filter))
        wrapper = (FilterWrapper)_serializer.Deserialize(reader);

      return new MediaNavigationFilter(itemData.Attributes["ClassName"], wrapper.Filter);
    }
Esempio n. 12
0
 protected static ConfigGroupMetadata BuildGroup(
   PluginItemMetadata itemData, PluginRuntime plugin)
 {
   string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
   string text = null;
   foreach (KeyValuePair<string, string> attr in itemData.Attributes)
   {
     switch (attr.Key)
     {
       case "Text":
         text = attr.Value;
         break;
       default:
         throw new ArgumentException("'ConfigGroup' builder doesn't define an attribute '" + attr.Key + "'");
     }
   }
   if (text == null)
     throw new ArgumentException("'ConfigGroup' item needs an attribute 'Text'");
   return new ConfigGroupMetadata(location, text);
 }
 protected WorkflowState BuildWorkflowState(PluginItemMetadata itemData)
 {
   IDictionary<string, string> attributes = itemData.Attributes;
   Guid id = Guid.Empty;
   try
   {
     string name;
     string displayLabel;
     bool isTemporary = false;
     string mainScreen = null;
     bool inheritMenu = false;
     Guid? workflowModelId = null;
     if (string.IsNullOrEmpty(itemData.Id))
       throw new ArgumentException(string.Format("WorkflowState: Id must be specified"));
     id = new Guid(itemData.Id);
     if (!attributes.TryGetValue("Name", out name))
       throw new ArgumentException(string.Format("WorkflowState with id '{0}': 'Name' attribute missing", id));
     if (!attributes.TryGetValue("DisplayLabel", out displayLabel))
       throw new ArgumentException(string.Format("WorkflowState with id '{0}': 'DisplayLabel' attribute missing", id));
     string tmpStr;
     if (attributes.TryGetValue("WorkflowModel", out tmpStr))
       workflowModelId = new Guid(tmpStr);
     if (!attributes.TryGetValue("MainScreen", out mainScreen))
     {
       mainScreen = null;
       if (workflowModelId == null)
         throw new ArgumentException(string.Format("WorkflowState '{0}': Either 'WorkflowModel' or 'MainScreen' atrribute must be specified", name));
     }
     if (attributes.TryGetValue("Temporary", out tmpStr) && !bool.TryParse(tmpStr, out isTemporary))
       throw new ArgumentException("'Temporary' attribute has to be of type bool");
     if (attributes.TryGetValue("InheritMenu", out tmpStr) && !bool.TryParse(tmpStr, out inheritMenu))
       throw new ArgumentException("'InheritMenu' attribute has to be of type bool");
     return new WorkflowState(id, name, displayLabel, isTemporary, mainScreen, inheritMenu, false,
         workflowModelId, WorkflowType.Workflow);
   }
   catch (Exception e)
   {
     ServiceRegistration.Get<ILogger>().Error("WorkflowStateBuilder: Workflow state '{0}' cannot be built", e, id);
     return null;
   }
 }
Esempio n. 14
0
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ClassName", itemData);
   BuilderHelper.CheckParameter("MimeType", itemData);
   return new VideoPlayerMimeTypeMapping(plugin.GetPluginType(itemData.Attributes["ClassName"]), itemData.Attributes["MimeType"]);
 }
Esempio n. 15
0
 public bool NeedsPluginActive(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BackgroundType type;
   string value = GetBackgroundAndType(itemData.Attributes, out type);
   if (type == BackgroundType.Static)
     return false;
   if (type == BackgroundType.Manager)
     return true;
   throw new NotImplementedException(string.Format(
       "Background builder: Background type '{0}' is not implemented", type));
 }
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ClassName", itemData);
   return new FanartImageSourceProviderRegistration(plugin.GetPluginType(itemData.Attributes["ClassName"]), itemData.Id);
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new plugin item registration data structure for the specified plugin item metadata
 /// instance.
 /// </summary>
 /// <param name="metaData">The metadata of the plugin item to create this registration
 /// structure for.</param>
 internal PluginItemRegistration(PluginItemMetadata metaData)
 {
     _pluginItemMetadata = metaData;
 }
Esempio n. 18
0
 public void RevokeItem(object item, PluginItemMetadata itemData, PluginRuntime plugin)
 {
   if (item == null)
     return;
   plugin.RevokePluginObject(item.GetType().FullName);
 }
Esempio n. 19
0
 protected static ConfigSettingMetadata BuildCustomSetting(
   PluginItemMetadata itemData, PluginRuntime plugin)
 {
   string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
   string text = null;
   string sort = null;
   string className = null;
   string helpText = null;
   IDictionary<string, string> additionalData = null;
   IDictionary<string, Type> additionalTypes = null;
   ICollection<string> listenTo = null;
   foreach (KeyValuePair<string, string> attr in itemData.Attributes)
   {
     switch (attr.Key)
     {
       case "Text":
         text = attr.Value;
         break;
       case "Sort":
         sort = attr.Value;
         break;
       case "ClassName":
         className = attr.Value;
         break;
       case "HelpText":
         helpText = attr.Value;
         break;
       case "ListenTo":
         listenTo = ParseListenTo(attr.Value);
         break;
       case "AdditionalData":
         additionalData = ParseAdditionalData(attr.Value);
         break;
       case "AdditionalTypes":
         additionalTypes = ParseAdditionalTypes(attr.Value, plugin);
         break;
       default:
         throw new ArgumentException("'ConfigSetting' builder doesn't define an attribute '" + attr.Key + "'");
     }
   }
   if (text == null)
     throw new ArgumentException("'ConfigSetting' item needs an attribute 'Text'");
   ConfigSettingMetadata result = new ConfigSettingMetadata(location, text, sort, className, helpText, listenTo)
     {
         AdditionalData = additionalData,
         AdditionalTypes = additionalTypes
     };
   return result;
 }
 /// <summary>
 /// Creates a new plugin item registration data structure for the specified plugin item metadata
 /// instance.
 /// </summary>
 /// <param name="metaData">The metadata of the plugin item to create this registration
 /// structure for.</param>
 internal PluginItemRegistration(PluginItemMetadata metaData)
 {
   _pluginItemMetadata = metaData;
 }
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("MediaItemAspectTypeId", itemData);
   return new MIATypeRegistration { MediaItemAspectTypeId = new Guid(itemData.Attributes["MediaItemAspectTypeId"]) };
 }
 public void RevokeItem(object item, PluginItemMetadata itemData, PluginRuntime plugin)
 {
   // Noting to do
 }
Esempio n. 23
0
 /// <summary>
 /// Registers the specified plugin item in the plugin tree.
 /// </summary>
 /// <param name="itemMetadata">Metadata structure of the item to register.</param>
 /// <returns><c>true</c>, if the plugin item could be registered, <c>false</c>,
 /// if the item already existed and <see cref="PluginItemMetadata.IsRedundant"/> is specified.</returns>
 /// <exception cref="ArgumentException">If there is already an item registered at the registration
 /// location and the <see cref="PluginItemMetadata.IsRedundant"/> flag is not set.</exception>
 internal bool RegisterItem(PluginItemMetadata itemMetadata)
 {
   lock (_syncObj)
   {
     IRegistryNode node = GetRegistryNode(itemMetadata.RegistrationLocation, true);
     itemMetadata.PluginRuntime = this;
     if (node.Items != null && node.Items.ContainsKey(itemMetadata.Id))
       if (itemMetadata.IsRedundant)
       {
         PluginItemRegistration itemRegistration = (PluginItemRegistration) node.Items[itemMetadata.Id];
         itemRegistration.AdditionalRedundantItemsMetadata.Add(itemMetadata);
         return false;
       }
       else
         throw new ArgumentException(string.Format("At location '{0}', a plugin item with id '{1}' is already registered",
             itemMetadata.RegistrationLocation, itemMetadata.Id));
     PluginItemRegistration resultItemRegistration = new PluginItemRegistration(itemMetadata);
     node.AddItem(itemMetadata.Id, resultItemRegistration);
     _itemRegistrations.Add(itemMetadata, resultItemRegistration);
   }
   return true;
 }
Esempio n. 24
0
 public void RevokeItem(object item, PluginItemMetadata itemData, PluginRuntime plugin)
 {
   if (item == null)
     return;
   ServiceItem si = (ServiceItem) item;
   plugin.RevokePluginObject(si.ServiceInstance.GetType().FullName);
 }
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   if (itemData.BuilderName == "WorkflowState")
     return BuildWorkflowState(itemData);
   if (itemData.BuilderName == "DialogState")
     return BuildDialogState(itemData);
   return null;
 }
Esempio n. 26
0
 protected static ConfigSettingMetadata BuildSetting(
   PluginItemMetadata itemData, PluginRuntime plugin)
 {
   string location = ConfigBaseMetadata.ConcatLocations(itemData.RegistrationLocation, itemData.Id);
   string text = null;
   string className = null;
   string helpText = null;
   ICollection<string> listenTo = null;
   foreach (KeyValuePair<string, string> attr in itemData.Attributes)
   {
     switch (attr.Key)
     {
       case "Text":
         text = attr.Value;
         break;
       case "ClassName":
         className = attr.Value;
         break;
       case "HelpText":
         helpText = attr.Value;
         break;
       case "ListenTo":
         listenTo = ParseListenTo(attr.Value);
         break;
       default:
         throw new ArgumentException("'ConfigSetting' builder doesn't define an attribute '" + attr.Key+ "'");
     }
   }
   if (text == null)
     throw new ArgumentException("'ConfigSetting' item needs an attribute 'Text'");
   return new ConfigSettingMetadata(location, text, className, helpText, listenTo);
 }
 public void RevokeItem(object item, PluginItemMetadata itemData, PluginRuntime plugin)
 {
   // Nothing to do here - the WorkflowManager will listen for workflow state withdrawals
 }
Esempio n. 28
0
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   BuilderHelper.CheckParameter("ClassName", itemData);
   return plugin.InstantiatePluginObject(itemData.Attributes["ClassName"]);
 }
Esempio n. 29
0
 public object BuildItem(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   switch (itemData.BuilderName)
   {
     case "ConfigSection":
       return BuildSection(itemData, plugin);
     case "ConfigGroup":
       return BuildGroup(itemData, plugin);
     case "ConfigSetting":
       return BuildSetting(itemData, plugin);
     case "CustomConfigSetting":
       return BuildCustomSetting(itemData, plugin);
   }
   throw new ArgumentException(string.Format("{0} builder cannot build setting of type '{1}'",
                                             typeof(ConfigBuilder).Name, itemData.BuilderName));
 }
Esempio n. 30
0
 /// <summary>
 /// Unregisters the specified plugin item from the plugin tree.
 /// </summary>
 /// <param name="itemMetadata">Meta data structure of the item to unregister.</param>
 /// <returns>Plugin item registration structure of the item to be unregistered.</returns>
 internal void UnregisterItem(PluginItemMetadata itemMetadata)
 {
   lock (_syncObj)
     try
     {
       IRegistryNode node = GetRegistryNode(itemMetadata.RegistrationLocation, false);
       if (node == null || node.Items == null)
         return;
       if (node.Items.ContainsKey(itemMetadata.Id))
       {
         PluginItemRegistration itemRegistration = (PluginItemRegistration) node.Items[itemMetadata.Id];
         // Check, if there are additional redundant items registered at this position. If yes, we'll use
         // the first of them instead of the old item to be unregistered.
         PluginItemMetadata newItemMetadata = null;
         IEnumerator<PluginItemMetadata> enumerator = itemRegistration.AdditionalRedundantItemsMetadata.GetEnumerator();
         if (enumerator.MoveNext())
         {
           newItemMetadata = enumerator.Current;
           itemRegistration.AdditionalRedundantItemsMetadata.Remove(newItemMetadata);
         }
         node.Items.Remove(itemMetadata.Id);
         if (newItemMetadata != null)
           newItemMetadata.PluginRuntime.RegisterItem(newItemMetadata);
       }
     }
     finally
     {
       _itemRegistrations.Remove(itemMetadata);
     }
 }
 public bool NeedsPluginActive(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   return true;
 }
Esempio n. 32
0
 public bool NeedsPluginActive(PluginItemMetadata itemData, PluginRuntime plugin)
 {
   return itemData.BuilderName != "ConfigSection" && itemData.BuilderName != "ConfigGroup";
 }