コード例 #1
0
        public static bool IsSolutionInstalled(StorePackage package, SPWeb targetWeb)
        {
            bool isInstalled = false;

            if (package.SolutionType == SolutionType.Farm)
            {
                try
                {
                    Assembly         a         = Assembly.Load(pakcageInstallerAssemblies[SolutionType.Farm].Name.FullName);
                    PackageInstaller installer = (PackageInstaller)a.CreateInstance(pakcageInstallerAssemblies[SolutionType.Farm].Class);
                    isInstalled = installer.IsSolutionInstalled(package, targetWeb);
                }
                catch
                {
                    throw;
                }
            }
            else if (package.SolutionType == SolutionType.Sandbox)
            {
                try
                {
                    Assembly         a         = Assembly.Load(pakcageInstallerAssemblies[SolutionType.Sandbox].Name.FullName);
                    PackageInstaller installer = (PackageInstaller)a.CreateInstance(pakcageInstallerAssemblies[SolutionType.Sandbox].Class);
                    isInstalled = installer.IsSolutionInstalled(package, targetWeb);
                }
                catch
                {
                    throw;
                }
            }
            return(isInstalled);
        }
コード例 #2
0
        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());
            }
        }
コード例 #3
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...
                    }
                }
            }
        }
コード例 #4
0
        public override Dictionary <Guid, StorePackage> GetPackages(StoreContext context)
        {
            Dictionary <Guid, StorePackage> packages = new Dictionary <Guid, StorePackage>();
            WebClient wc = new WebClient();
            string    repositoryURLResolved = GetResolvedRepositoryURL(context.Web);

            wc.UseDefaultCredentials = true;
            wc.Encoding = Encoding.UTF8;

            byte[] content = wc.DownloadData(repositoryURLResolved);

            string utfString = Encoding.UTF8.GetString(content);

            string repositoryXML = wc.DownloadString(repositoryURLResolved);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(repositoryXML);

            foreach (XmlNode packageNode in doc.GetElementsByTagName("Package"))
            {
                StorePackage package = new StorePackage();

                string       title           = packageNode["Title"].InnerText;
                string       description     = packageNode["Description"].InnerText;
                string       id              = packageNode.Attributes["ID"].InnerText;
                string       authorname      = packageNode["AuthorName"].InnerText;
                string       authorURL       = packageNode["AuthorURL"].InnerText;
                string       readmeURL       = packageNode["ReadMeURL"].InnerText;
                string       packageURL      = packageNode["PackageURL"].InnerText;
                string       packageFileName = packageNode["SolutionFileName"].InnerText;
                string       setupFeatureID  = packageNode["SetupFeatureID"].InnerText;
                SolutionType type            = (SolutionType)Enum.Parse(typeof(SolutionType), packageNode["SolutionType"].InnerText);


                package.Title            = title;
                package.ID               = id;
                package.Description      = description;
                package.AuthorName       = authorname;
                package.AuthorURL        = authorURL;
                package.ReadMeURL        = readmeURL;
                package.PackageURL       = packageURL;
                package.SetupFeatureID   = setupFeatureID;
                package.SolutionFileName = packageFileName;
                package.SolutionType     = type;

                packages.Add(new Guid(id), package);
            }

            return(packages);
        }
コード例 #5
0
        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
                    }
                }
            }
        }
コード例 #6
0
        public override bool IsSolutionInstalled(StorePackage package, SPWeb targetWeb)
        {
            bool isInstalled = false;

            if (package.SolutionType == SolutionType.Farm)
            {
                SPSolutionCollection allSolutions = SPFarm.Local.Solutions;
                foreach (var solution in allSolutions)
                {
                    if (!isInstalled)
                    {
                        if (solution.SolutionFile.Name.IndexOf(package.SolutionFileName, StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            isInstalled = true;
                        }
                    }
                }
            }
            return(isInstalled);
        }
コード例 #7
0
        public override bool IsSolutionInstalled(StorePackage package, SPWeb targetWeb)
        {
            bool    isInstalled = false;
            Version spVersion   = SPFarm.Local.BuildVersion;

            if (spVersion > new Version("14.0.0.0") && package.SolutionType == SolutionType.Sandbox)
            {
                SPSite targetSite = targetWeb.Site;

                SPUserSolutionCollection allSolutions = targetSite.Solutions;

                foreach (SPUserSolution solution in allSolutions)
                {
                    if (!isInstalled)
                    {
                        if (solution.Name.IndexOf(package.SolutionFileName, StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            isInstalled = true;
                        }
                    }
                }
            }
            return(isInstalled);
        }
コード例 #8
0
 public virtual bool IsSolutionInstalled(StorePackage package, SPWeb targetWeb)
 {
     throw new SPException("Solution installation detection is not implemented for this type of solution");
 }