Exemple #1
0
        public override void AddPackage(AddPackageContext context, Boolean autoActivate)
        {
            SPWeb        targetWeb  = context.TargetWeb;
            SPSite       targetSite = targetWeb.Site;
            StorePackage package    = context.StorePackage;

            SPList solutionsList = targetSite.GetCatalog(SPListTemplateType.SolutionCatalog);

            bool currentWebUnsafeSettings = context.SPContext.Web.AllowUnsafeUpdates;
            bool currentSettings          = targetWeb.AllowUnsafeUpdates;

            targetWeb.AllowUnsafeUpdates             = true;
            context.SPContext.Web.AllowUnsafeUpdates = true;
            SPFile file = solutionsList.RootFolder.Files.Add(context.StorePackage.SolutionFileName, File.ReadAllBytes(context.SolutionFilePath));

            SPUserSolution solution = targetSite.Solutions.Add(file.Item.ID);

            targetWeb.AllowUnsafeUpdates             = currentSettings;
            context.SPContext.Web.AllowUnsafeUpdates = currentWebUnsafeSettings;

            if (!string.IsNullOrEmpty(package.SetupFeatureID))
            {
                if (autoActivate)
                {
                    try
                    {
                        SPSINStorePackageUtilities.AddPendingActivationFeature(context.TargetWeb, new Guid(package.SetupFeatureID));
                    }
                    catch
                    {
                        // Cannot add automatic activation...
                    }
                }
            }
        }
        public override void AddPackage(AddPackageContext context, Boolean autoActivate)
        {
            StorePackage package = context.StorePackage;

            try
            {
                Collection <SPWebApplication> webApps = new Collection <SPWebApplication>();
                webApps.Add(context.TargetWeb.Site.WebApplication);

                bool previousUnsafeUpdatesContextWeb = context.SPContext.Web.AllowUnsafeUpdates;
                context.SPContext.Web.AllowUnsafeUpdates = true;
                SPSolution solution = SPFarm.Local.Solutions.Add(context.SolutionFilePath);
                solution.Deploy(DateTime.Now, true, webApps, true);

                if (!string.IsNullOrEmpty(package.SetupFeatureID))
                {
                    if (autoActivate)
                    {
                        SPSINStorePackageUtilities.AddPendingActivationFeature(context.TargetWeb, new Guid(package.SetupFeatureID));
                    }
                }
                context.SPContext.Web.AllowUnsafeUpdates = previousUnsafeUpdatesContextWeb;
            }
            catch (Exception exc)
            {
                throw new SPException(exc.ToString());
            }
        }
 public static void AddFarmSolution(AddPackageContext context, Boolean autoActivate)
 {
     try
     {
         Assembly         a         = Assembly.Load(pakcageInstallerAssemblies[SolutionType.Farm].Name.FullName);
         PackageInstaller installer = (PackageInstaller)a.CreateInstance(pakcageInstallerAssemblies[SolutionType.Farm].Class);
         installer.AddPackage(context, autoActivate);
     }
     catch
     {
         throw;
     }
 }
        internal static void InstallPackageInWeb(StorePackage package, string targetWebURL)
        {
            SPContext context = SPContext.Current;

            using (SPSite site = new SPSite(targetWebURL))
            {
                using (SPWeb activationWeb = site.OpenWeb())
                {
                    WebClient wc               = new WebClient();
                    string    tempFileName     = Path.GetTempFileName();
                    string    solutionFileName = package.SolutionFileName;
                    tempFileName             = tempFileName.Replace(Path.GetFileName(tempFileName), solutionFileName);
                    wc.UseDefaultCredentials = true;
                    wc.DownloadFile(package.PackageURL, tempFileName);

                    AddPackageContext packageContext = new AddPackageContext();
                    packageContext.HttpContext      = HttpContext.Current;
                    packageContext.SolutionFilePath = tempFileName;
                    packageContext.SPContext        = SPContext.Current;
                    packageContext.StorePackage     = package;
                    packageContext.TargetWeb        = activationWeb;


                    if (package.SolutionType == SolutionType.Farm)
                    {
                        if (SPSINStorePackageUtilities.CanAddFarmSolutions(context, activationWeb))
                        {
                            SPSINStorePackageUtilities.AddFarmSolution(packageContext);
                        }
                    }
                    else if (package.SolutionType == SolutionType.Sandbox)
                    {
                        if (SPSINStorePackageUtilities.CanAddSandboxSolutions(SPContext.Current, activationWeb))
                        {
                            SPSINStorePackageUtilities.AddSandboxSolution(packageContext);
                        }
                    }
                    else
                    {
                        // use App type loader
                    }
                }
            }
        }
 public static void AddFarmSolution(AddPackageContext context)
 {
     AddFarmSolution(context, true);
 }
 public static void AddSandboxSolution(AddPackageContext context)
 {
     AddSandboxSolution(context, true);
 }
 public override bool CanAddPackage(AddPackageContext context)
 {
     return(false);
 }
Exemple #8
0
 public override bool CanAddPackage(AddPackageContext context)
 {
     return(base.CanAddPackage(context));
 }
 public virtual bool CanAddPackage(AddPackageContext context)
 {
     throw new SPException("Solution installation ability detection is not implemented for this type of solution");
 }
 public virtual void AddPackage(AddPackageContext context, Boolean autoActivate)
 {
     throw new SPException("Solution installation is not implemented for this type of solution");
 }
Exemple #11
0
 public virtual bool CanAddPackage(AddPackageContext context)
 {
     throw new SPException("Not implemented");
 }