Exemplo n.º 1
0
        public static void ImportPortlet(PortletInventoryItem portlet, IEnumerable <Node> repoPortlets)
        {
            var nameText    = ResourceManager.Current.GetString(portlet.Portlet.Name);
            var portletName = GetValidName(nameText, false);

            // check if already exists
            if (repoPortlets.Any(c => c.Name == portletName))
            {
                return;
            }

            // create portlet node
            var categoryNode = Node.LoadNode(RepositoryPath.Combine(PortletsFolderPath, GetValidName(portlet.Portlet.Category.Title)));

            if (categoryNode == null)
            {
                return;
            }

            var portletNode = Content.CreateNew("Portlet", categoryNode, portlet.Portlet.GetType().Name);

            portletNode["DisplayName"] = portlet.Portlet.Name;
            portletNode["Description"] = portlet.Portlet.Description;
            portletNode["TypeName"]    = GetPortletTypeName(portlet.Portlet.GetType());
            var imageData = portlet.GetImageFieldData(portletNode.Fields["PortletImage"]);

            if (imageData != null)
            {
                portletNode["PortletImage"] = imageData;
            }
            portletNode.Save();
        }
Exemplo n.º 2
0
        public static List <PortletInventoryItem> GetPortletsFromDll()
        {
            var portlets = new List <PortletInventoryItem>();

            foreach (Assembly privateAssembly in TypeHandler.GetAssemblies())
            {
                AssemblyName asmName = privateAssembly.GetName();
                foreach (Type privateType in privateAssembly.GetTypes())
                {
                    PortletBase wp = null;
                    if (privateType.BaseType != null)
                    {
                        if (privateType.IsSubclassOf(typeof(PortletBase)) && !privateType.IsAbstract && !privateType.IsNotPublic)
                        {
                            object instance = null;
                            try
                            {
                                instance = Activator.CreateInstance(privateType);
                            }
                            catch (Exception e) //logged
                            {
                                Logger.WriteException(e);
                                continue;
                            }
                            wp = (PortletBase)instance;
                        }
                    }
                    if (wp != null)
                    {
                        portlets.Add(PortletInventoryItem.Create(wp, privateAssembly));
                    }
                }
            }
            return(portlets);
        }
Exemplo n.º 3
0
        public static PortletInventoryItem Create(PortletBase portlet, Assembly assembly)
        {
            var portletItem = new PortletInventoryItem();

            portletItem.Portlet = portlet;

            // get resource image
            var imageName   = string.Concat(portlet.GetType().ToString(), ".png");
            var imageStream = assembly.GetManifestResourceStream(imageName);

            if (imageStream != null)
            {
                portletItem.ImageStream = imageStream;
            }

            return(portletItem);
        }