示例#1
0
    /// <summary>
    /// Returns extension object
    /// </summary>
    /// <param name="name">Extension name</param>
    /// <returns>Extension</returns>
    static ManagedExtension DataStoreExtension(string name)
    {
        ManagedExtension ex = null;

        BlogEngine.Core.DataStore.ExtensionSettings xs = new BlogEngine.Core.DataStore.ExtensionSettings(name);
        XmlSerializer serializer = new XmlSerializer(typeof(ManagedExtension));
        object        o          = xs.GetSettings();

        if (o != null)
        {
            if (o.GetType().Name == "FileStream")
            {
                Stream stm = (FileStream)o;
                ex = (ManagedExtension)serializer.Deserialize(stm);
                stm.Close();
            }
            else
            {
                if (!string.IsNullOrEmpty((string)o))
                {
                    using (StringReader reader = new StringReader(o.ToString()))
                    {
                        ex = (ManagedExtension)serializer.Deserialize(reader);
                    }
                }
            }
        }
        return(ex);
    }
示例#2
0
    /// <summary>
    /// If extensions not in the cache will load
    /// from the XML file. If file not exists
    /// will load from assembly using reflection
    /// </summary>
    static void LoadExtensions()
    {
        if (HttpRuntime.Cache["Extensions"] == null ||
            (((List <ManagedExtension>)(HttpRuntime.Cache["Extensions"]))).Count == 0)
        {
            ArrayList codeAssemblies = Utils.CodeAssemblies();

            ManagedExtension meta = DataStoreExtension("MetaExtension");
            if (meta == null)
            {
                _extensions.Add(new ManagedExtension("MetaExtension", "1.0", "Meta extension", "BlogEngine.net"));
            }
            else
            {
                if (!_extensions.Contains(meta))
                {
                    _extensions.Add(meta);
                }
            }

            foreach (Assembly a in codeAssemblies)
            {
                Type[] types = a.GetTypes();
                foreach (Type type in types)
                {
                    object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
                    foreach (object attribute in attributes)
                    {
                        ExtensionAttribute xa = (ExtensionAttribute)attribute;
                        // try to load from storage
                        ManagedExtension x = DataStoreExtension(type.Name);
                        // if nothing, crete new extension
                        if (x == null)
                        {
                            x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author);
                            _newExtensions.Add(type.Name);
                            SaveToStorage(x);
                        }
                        else
                        {
                            // update attributes from assembly
                            x.Version     = xa.Version;
                            x.Description = xa.Description;
                            x.Author      = xa.Author;

                            if (x.Priority == 0)
                            {
                                x.Priority = xa.Priority;
                            }
                        }
                        _extensions.Add(x);
                    }
                }
            }

            //SaveToStorage();
            SaveToCache();
        }
    }
示例#3
0
    public static string SettingsLink(string extensionName)
    {
        ManagedExtension x  = ExtensionManager.GetExtension(extensionName);
        StringBuilder    sb = new StringBuilder();

        if (!string.IsNullOrEmpty(x.AdminPage))
        {
            string url = BlogEngine.Core.Utils.AbsoluteWebRoot.AbsoluteUri;
            if (!url.EndsWith("/"))
            {
                url += "/";
            }

            if (x.AdminPage.StartsWith("~/"))
            {
                url += x.AdminPage.Substring(2);
            }
            else if (x.AdminPage.StartsWith("/"))
            {
                url += x.AdminPage.Substring(1);
            }
            else
            {
                url += x.AdminPage;
            }

            sb.Append("<a href='" + url + "'>" + Resources.labels.edit + "</a>");
        }
        else
        {
            if (x.Settings == null)
            {
                sb.Append("&nbsp;");
            }
            else
            {
                if (x.Settings.Count == 0 || (x.Settings.Count == 1 && x.Settings[0] == null) || x.ShowSettings == false)
                {
                    sb.Append("&nbsp;");
                }
                else
                {
                    sb.Append("<a href='?ctrl=params&ext=" + x.Name + "'>" + Resources.labels.edit + "</a>");
                }
            }
        }
        return(sb.ToString());
    }
示例#4
0
    public static string StatusLink(string extensionName)
    {
        ManagedExtension x  = ExtensionManager.GetExtension(extensionName);
        StringBuilder    sb = new StringBuilder();

        if (x.Enabled)
        {
            sb.Append("<span style='background:#ccffcc'><a href='?act=dis&ext=" + x.Name + "' title='" + clickToDisable + x.Name + "' " + jsOnClick + ">" + enabled + "</a></span>");
        }
        else
        {
            sb.Append("<span style='background:#ffcc66'><a href='?act=enb&ext=" + x.Name + "' title='" + clickToEnable + x.Name + "' " + jsOnClick + ">" + disabled + "</a></span>");
        }

        return(sb.ToString());
    }
示例#5
0
    protected void ChangePriority(string filterName, bool up)
    {
        ManagedExtension x = ExtensionManager.GetExtension(filterName);

        if (x != null)
        {
            if (up && x.Priority > 1)
            {
                x.Priority--;
            }
            else
            {
                x.Priority++;
            }

            ExtensionManager.SaveToStorage(x);
        }

        Response.Redirect(Request.RawUrl);
    }
示例#6
0
    /// <summary>
    /// If extensions not in the cache will load
    /// from the XML file. If file not exists
    /// will load from assembly using reflection
    /// </summary>
    static void LoadExtensions()
    {
        if (HttpContext.Current.Cache["Extensions"] == null)
        {
            ArrayList codeAssemblies = Utils.CodeAssemblies();
            foreach (Assembly a in codeAssemblies)
            {
                Type[] types = a.GetTypes();
                foreach (Type type in types)
                {
                    object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
                    foreach (object attribute in attributes)
                    {
                        ExtensionAttribute xa = (ExtensionAttribute)attribute;
                        // try to load from storage
                        ManagedExtension x = DataStoreExtension(type.Name);
                        // if nothing, crete new extension
                        if (x == null)
                        {
                            x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author);
                            _newExtensions.Add(type.Name);
                            SaveToStorage(x);
                        }
                        else
                        {
                            // update attributes from assembly
                            x.Version     = xa.Version;
                            x.Description = xa.Description;
                            x.Author      = xa.Author;
                            x.Priority    = xa.Priority;
                        }
                        _extensions.Add(x);
                    }
                }
            }

            //SaveToStorage();
            SaveToCache();
        }
    }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            _pageLocation = GetPageLocation();

            if (_pageLocation == PageStyle.Front)
            {
                _rotatorExtension       = ExtensionManager.GetExtension("FeaturedPostsRotator");
                _rotatorExtensionImages = ExtensionManager.GetSettings("FeaturedPostsRotator", "FeaturedPostsImages");
                _rotatorSettings        = ExtensionManager.GetSettings("FeaturedPostsRotator");
                _html = GetImagesHtmlList();

                HttpContext context = HttpContext.Current;
                if (context.CurrentHandler is Page == false)
                {
                    return;
                }
                _page = (Page)context.CurrentHandler;

                AddStylesheetToPage(_page);
            }
        }
示例#8
0
 /// <summary>
 /// Save individual extension to storage
 /// </summary>
 /// <param name="ext">Extension</param>
 /// <returns>True if saved</returns>
 public static bool SaveToStorage(ManagedExtension ext)
 {
     BlogEngine.Core.DataStore.ExtensionSettings xs = new BlogEngine.Core.DataStore.ExtensionSettings(ext.Name);
     xs.SaveSettings(ext);
     return(true);
 }
示例#9
0
 /// <summary>
 /// Adds extension to ext. collection in the manager
 /// </summary>
 /// <param name="type">Extension type</param>
 /// <param name="attribute">Extension attribute</param>
 public static void AddExtension(Type type, object attribute)
 {
     ExtensionAttribute xa = (ExtensionAttribute)attribute;
     ManagedExtension x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author);
     _extensions.Add(x);
 }
示例#10
0
文件: Manager.cs 项目: bpanjavan/Blog
    /// <summary>
    /// If extensions not in the cache will load
    /// from the XML file. If file not exists
    /// will load from assembly using reflection
    /// </summary>
    static void LoadExtensions()
    {
        if (HttpContext.Current.Cache["Extensions"] == null)
        {
          ArrayList codeAssemblies = Utils.CodeAssemblies();
          foreach (Assembly a in codeAssemblies)
          {
        Type[] types = a.GetTypes();
        foreach (Type type in types)
        {
          object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
          foreach (object attribute in attributes)
          {
            ExtensionAttribute xa = (ExtensionAttribute)attribute;
            // try to load from storage
            ManagedExtension x = DataStoreExtension(type.Name);
            // if nothing, crete new extension
            if (x == null)
            {
              x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author);
              _newExtensions.Add(type.Name);
              SaveToStorage(x);
            }
            else
            {
              // update attributes from assembly
              x.Version = xa.Version;
              x.Description = xa.Description;
              x.Author = xa.Author;
            }
            _extensions.Add(x);
          }
        }
          }

          //SaveToStorage();
          SaveToCache();
        }
    }
示例#11
0
文件: Manager.cs 项目: bpanjavan/Blog
 /// <summary>
 /// Save individual extension to storage
 /// </summary>
 /// <param name="ext">Extension</param>
 /// <returns>True if saved</returns>
 public static bool SaveToStorage(ManagedExtension ext)
 {
     BlogEngine.Core.DataStore.ExtensionSettings xs = new BlogEngine.Core.DataStore.ExtensionSettings(ext.Name);
     xs.SaveSettings(ext);
     return true;
 }
    /// <summary>
    /// If extensions not in the cache will load
    /// from the XML file. If file not exists
    /// will load from assembly using reflection
    /// </summary>
    static void LoadExtensions()
    {
        if (HttpRuntime.Cache["Extensions"] == null
        || (((List<ManagedExtension>)(HttpRuntime.Cache["Extensions"]))).Count == 0)
        {
          ArrayList codeAssemblies = Utils.CodeAssemblies();

        ManagedExtension meta = DataStoreExtension("MetaExtension");
        if(meta == null)
        {
            _extensions.Add(new ManagedExtension("MetaExtension", "1.0", "Meta extension", "TrainEngine.net"));
        }
        else
        {
            if(!_extensions.Contains(meta))
            {
                _extensions.Add(meta);
            }
        }

          foreach (Assembly a in codeAssemblies)
          {
        Type[] types = a.GetTypes();
        foreach (Type type in types)
        {
          object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false);
          foreach (object attribute in attributes)
          {
            ExtensionAttribute xa = (ExtensionAttribute)attribute;
            // try to load from storage
            ManagedExtension x = DataStoreExtension(type.Name);
            // if nothing, crete new extension
            if (x == null)
            {
              x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author);
              _newExtensions.Add(type.Name);
              SaveToStorage(x);
            }
            else
            {
              // update attributes from assembly
              x.Version = xa.Version;
              x.Description = xa.Description;
              x.Author = xa.Author;

              if(x.Priority == 0)
                x.Priority = xa.Priority;
            }
            _extensions.Add(x);
          }
        }
          }

          //SaveToStorage();
          SaveToCache();
        }
    }