/// <summary>
        /// Installs the plugin associated with the ID
        /// </summary>
        /// <param name="ID">The identifier.</param>
        /// <returns>Returns true if it is installed successfully, false otherwise</returns>
        public bool InstallPlugin(string ID)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(ID), "ID");
            var User = HttpContext.Current.Chain(x => x.User).Chain(x => x.Identity).Chain(x => x.Name, "");

            Utilities.IO.Log.Get().LogMessage("Plugin {0} is being installed by {1}", MessageType.Debug, ID, User);
            var TempPlugin = PluginList.Get(ID);

            if (TempPlugin != null)
            {
                UninstallPlugin(ID);
            }
            foreach (IPackageRepository Repo in PackageRepositories)
            {
                var Package = Repo.FindPackage(ID);
                if (Package != null)
                {
                    new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/packages/" + Package.Id + "." + Package.Version.ToString() + "/lib").Create();
                    new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/packages/" + Package.Id + "." + Package.Version.ToString() + "/content").Create();
                    new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/packages/" + Package.Id + "." + Package.Version.ToString() + "/tools").Create();
                    var Manager = new PackageManager(Repo,
                                                     new DefaultPackagePathResolver(Repo.Source),
                                                     new PhysicalFileSystem(new DirectoryInfo(HttpContext.Current != null ?
                                                                                              HttpContext.Current.Server.MapPath("~/App_Data/packages") :
                                                                                              "./App_Data/packages").FullName));
                    Manager.InstallPackage(Package, false, true);
                    PluginList.Add(new Plugin(Package));
                    Package.DependencySets.ForEach(x => x.Dependencies.ForEach(y => InstallPlugin(y.Id)));
                    PluginList.Save();
                    break;
                }
            }
            Utilities.IO.Log.Get().LogMessage("Plugin {0} has been installed by {1}", MessageType.Debug, ID, User);
            return(true);
        }
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 public void Initialize()
 {
     Delete(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/plugins/Loaded/"));
     new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/plugins/Loaded").Create();
     PluginList = PluginList.Load();
     if (PluginList.Plugins == null)
     {
         PluginList.Plugins = new List <Plugin>();
     }
     foreach (Plugin TempPlugin in PluginList.Plugins)
     {
         TempPlugin.Initialize();
     }
     PluginsInstalled = AppDomain.CurrentDomain.GetAssemblies().Objects <IPlugin>();
     foreach (IPlugin TempPlugin in PluginsInstalled)
     {
         Bootstrapper.AddAssembly(TempPlugin.GetType().Assembly);
         foreach (IPackageRepository Repo in PackageRepositories)
         {
             var Package = Repo.FindPackage(TempPlugin.PluginData.PluginID);
             if (Package != null)
             {
                 var TempPluginData = PluginList.Get(Package.Id);
                 TempPluginData.OnlineVersion = Package.Version.ToString();
             }
         }
     }
     PluginList.Save();
 }
        /// <summary>
        /// Uninstalls the plugin associated with the ID
        /// </summary>
        /// <param name="ID">The identifier.</param>
        /// <returns>Returns true if it is uninstalled successfully, false otherwise</returns>
        public bool UninstallPlugin(string ID)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(ID), "ID");
            var TempPlugin = PluginList.Get(ID);

            if (TempPlugin == null)
            {
                return(true);
            }
            var User = HttpContext.Current.Chain(x => x.User).Chain(x => x.Identity).Chain(x => x.Name, "");

            Utilities.IO.Log.Get().LogMessage("Plugin {0} is being uninstalled by {1}", MessageType.Debug, ID, User);
            TempPlugin.Delete();
            Utilities.IO.Log.Get().LogMessage("Plugin {0} has been uninstalled by {1}", MessageType.Debug, ID, User);
            PluginList.Remove(TempPlugin);
            PluginList.Save();
            return(true);
        }
        /// <summary>
        /// Updates the plugin associated with the ID
        /// </summary>
        /// <param name="ID">The identifier.</param>
        /// <returns>Returns true if it is updated successfully, false otherwise</returns>
        public bool UpdatePlugin(string ID)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(ID), "ID");
            var TempPlugin = PluginList.Get(ID);

            if (TempPlugin == null)
            {
                return(true);
            }
            var  User   = HttpContext.Current.Chain(x => x.User).Chain(x => x.Identity).Chain(x => x.Name, "");
            bool Result = false;

            Utilities.IO.Log.Get().LogMessage("Plugin {0} is being updated by {1}", MessageType.Debug, ID, User);
            foreach (IPackageRepository Repo in PackageRepositories)
            {
                var Package = Repo.FindPackage(ID);
                if (Package != null)
                {
                    TempPlugin = PluginList.Get(ID);
                    if (TempPlugin != null)
                    {
                        TempPlugin.OnlineVersion = Package.Version.ToString();
                        TempPlugin.Save();
                        if (TempPlugin.UpdateAvailable)
                        {
                            Result = UninstallPlugin(ID);
                        }
                        if (Result)
                        {
                            Result = InstallPlugin(ID);
                        }
                    }
                    break;
                }
            }
            return(Result);
        }