public UserSolutionNode(SPUserSolutionCollection parten, SPUserSolution solution) { this.Tag = solution; this.SPParent = parten; this.Setup(); }
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 SPUserSolutionInstance(ObjectInstance prototype, SPUserSolution userSolution) : this(prototype) { if (userSolution == null) { throw new ArgumentNullException("userSolution"); } m_userSolution = userSolution; }
private static void addfile(string file, SPWeb web, string path, int counter) { FileStream fstream = File.OpenRead(path); byte[] content = new byte[fstream.Length]; fstream.Read(content, 0, (int)fstream.Length); fstream.Close(); web.Files.Add(((web.ServerRelativeUrl == "/") ? "" : web.ServerRelativeUrl) + "/_catalogs/solutions/" + file + ".wsp", content); SPUserSolution solution = web.Site.Solutions.Add(counter); EnsureSiteCollectionFeaturesActivated(solution, web.Site); }
static List <SPFeatureDefinition> GetFeatureDefinitionsInSolution(SPUserSolution solution, SPSite site) { List <SPFeatureDefinition> list = new List <SPFeatureDefinition>(); foreach (SPFeatureDefinition definition in site.FeatureDefinitions) { if (definition.SolutionId.Equals(solution.SolutionId)) { list.Add(definition); } } return(list); }
static void EnsureSiteCollectionFeaturesActivated(SPUserSolution solution, SPSite site) { SPUserSolutionCollection solutions = site.Solutions; List <SPFeatureDefinition> oListofFeatures = GetFeatureDefinitionsInSolution(solution, site); foreach (SPFeatureDefinition def in oListofFeatures) { if (((def.Scope == SPFeatureScope.Site) && def.ActivateOnDefault) && (site.Features[def.Id] == null)) { site.Features.Add(def.Id, false, SPFeatureDefinitionScope.Site); //site.Features.Add(def.Id); } } }
internal void RetracSolution(Guid _usGuid) { try { Tracing.TraceEvent.TraceVerbose(90, "RetracSolution", String.Format("The solution {0} will be deleted from the SolutionCatalog", _usGuid)); SPUserSolution _us = SiteCollection.Solutions[_usGuid]; SiteCollection.Solutions.Remove(_us); SPDocumentLibrary solutionGallery = (SPDocumentLibrary)SiteCollection.GetCatalog(SPListTemplateType.SolutionCatalog); foreach (SPListItem _li in solutionGallery.Items) { if (_li.File.Name == _us.Name) { solutionGallery.Items.DeleteItemById(_li.ID); Tracing.TraceEvent.TraceInformation(90, "RetracSolution", String.Format("The solution {0} has been deleted from the SolutionCatalog", _us.Name)); return; } } Tracing.TraceEvent.TraceWarning(90, "RetracSolution", String.Format("The solution {0} has not been found in the SolutionCatalog", _us.Name)); } catch (Exception ex) { throw new ApplicationException(String.Format(Resources.LastOperationFailed, ex.Message)); } }
internal static void DoInstallation(Package.InstallationStateData installationStateData, BackgroundWorker _wrkr, DoWorkEventArgs e, FileInfo packageContentLocation) { SPSecurity.RunWithElevatedPrivileges(delegate() { if (_wrkr.CancellationPending) { e.Cancel = true; e.Result = false; return; } try { string _format = "Trying to create or reuse the site collection at {0}, configured site template {1}, LCID {2}."; _wrkr.ReportProgress(1, String.Format(_format, installationStateData.SiteCollectionURL, installationStateData.SiteTemplate, installationStateData.LCID)); using (SiteCollectionHelper m_SiteCollectionHelper = SiteCollectionHelper.GetSPSite( FarmHelpers.WebApplication, installationStateData.SiteCollectionURL, installationStateData.Title, installationStateData.Description, installationStateData.LCID, null, installationStateData.OwnerLogin, installationStateData.OwnerName, installationStateData.OwnerEmail)) { installationStateData.SiteCollectionCreated = true; _wrkr.ReportProgress(1, "Site collection is created"); if (m_SiteCollectionHelper.NewTemplateRequired) { _wrkr.ReportProgress(1, "Applying new template - select required from dialog."); s_EndOFUIAction.Reset(); SPWebTemplateCollection _cllctn = m_SiteCollectionHelper.GetWebTemplates(installationStateData.LCID); _wrkr.ReportProgress(1, new SPWebTeplateEventArgs(_cllctn, GetTemplate, 1, "Getting Site template")); //GetTemplate( FarmHelpers.WebApplication.Sites[ _urlSite ], installationStateData ); s_EndOFUIAction.WaitOne(); _wrkr.ReportProgress(1, String.Format("Applying new template {0}", WebTemplateDialog.SPWebTemplateToString(installationStateData.SPWebTemplate))); m_SiteCollectionHelper.ApplayTemplate(installationStateData.SPWebTemplate); } _format = "The site template is configured to Name: {0}/ Id: {1}."; _wrkr.ReportProgress(1, String.Format(_format, m_SiteCollectionHelper.SiteTemplate, m_SiteCollectionHelper.SiteTemplateID)); using (PackageContent _PackageContent = new PackageContent(packageContentLocation)) { foreach (Solution _sltn in installationStateData.SolutionsToInstall.Values) { FileInfo _fi = _sltn.SolutionFileInfo(_PackageContent.ContentLocation); _wrkr.ReportProgress(1, String.Format("Deploying solution: {0}", _fi.Name)); switch (_sltn.FeatureDefinitionScope) { case FeatureDefinitionScope.Farm: TimeSpan _timeout = new TimeSpan(0, 0, Properties.Settings.Default.SolutionDeploymentTimeOut); string _waitingForCompletion = String.Format("Waiting for completion .... It could take up to {0} s. ", _timeout); _wrkr.ReportProgress(1, _waitingForCompletion); SPSolution _sol = null; if (_sltn.Global) { _sol = FarmHelpers.DeploySolution(_fi, _timeout); } else { _sol = FarmHelpers.DeploySolution(_fi, FarmHelpers.WebApplication, _timeout); } _sltn.SolutionGuid = _sol.Id; _wrkr.ReportProgress(1, String.Format("Solution deployed Name={0}, Deployed={1}, DeploymentState={2}, DisplayName={3} Status={4}", _sol.Name, _sol.Deployed, _sol.DeploymentState, _sol.DisplayName, _sol.Status)); break; case FeatureDefinitionScope.Site: SPUserSolution _solution = null; _solution = m_SiteCollectionHelper.DeploySolution(_fi); _sltn.SolutionGuid = _solution.SolutionId; _wrkr.ReportProgress(1, String.Format("Solution deployed: {0}", _solution.Name)); break; case FeatureDefinitionScope.None: default: throw new ApplicationException("Wrong FeatureDefinitionScope in the configuration file"); } _sltn.Deployed = true; foreach (Feature _fix in _sltn.Fetures) { bool _repeat; do { _repeat = false; try { if (!_fix.AutoActivate) { _wrkr.ReportProgress(1, String.Format("Skipping activation of the feature: {0} at: {1} because tha activation is set false", _fix.FetureGuid, m_SiteCollectionHelper.SiteCollection.Url)); break; } _wrkr.ReportProgress(1, String.Format("Activating Feature: {0} at: {1}", _fix.FetureGuid, m_SiteCollectionHelper.SiteCollection.Url)); SPFeature _ffeature = m_SiteCollectionHelper.ActivateFeature(_fix.FetureGuid, _sltn.SPFeatureDefinitionScope); _wrkr.ReportProgress(1, String.Format("Feature activated : {0}", _ffeature.Definition.DisplayName)); _fix.DisplayName = _ffeature.Definition.DisplayName; _fix.Version = _ffeature.Version.ToString(); _fix.SPScope = _ffeature.Definition.Scope; } catch (Exception ex) { string _msg = String.Format(Properties.Resources.FeatureActivationFailureMBox, ex.Message); Tracing.TraceEvent.TraceError(516, "SetUpData.Install", _msg); switch (MessageBox.Show(_msg, "Install ActivateFeature", MessageBoxButton.YesNoCancel, MessageBoxImage.Error, MessageBoxResult.No)) { case MessageBoxResult.Cancel: throw ex; case MessageBoxResult.Yes: _repeat = true; break; default: break; } } } while (_repeat); }//foreach (Feature _fix in _sltn.Fetures) _sltn.Activated = true; } } //foreach (Solution _sltn //TODO installationStateData.Save(); _wrkr.ReportProgress(1, "Product installation successfully completed"); } } catch (Exception ex) { //TODO //try //{ // installationStateData.Save(); //} //catch ( Exception _SaveEx ) //{ // InstallationListBox.AddMessage( _SaveEx.Message ); //} string _msg = String.Format(Properties.Resources.LastOperationFailedWithError, ex.Message); _wrkr.ReportProgress(1, _msg); throw ex; } }); }
public static bool IsActivated(this SPUserSolution solution) { return(solution.Status == SPUserSolutionStatus.Activated); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { SPUtility.ValidateFormDigest(); var siteId = SPContext.Current.Site.ID; var web = SPContext.Current.Web; var webId = web.ID; var safeServerRelativeUrl = web.SafeServerRelativeUrl(); SPSecurity.RunWithElevatedPrivileges(() => { using (var spSite = new SPSite(siteId)) { using (var spWeb = spSite.OpenWeb(webId)) { string templateName = string.Format("{0}.wsp", Path.GetFileName(safeServerRelativeUrl)); bool includeContent = true; SPUserSolution currentTemplate = (from SPUserSolution s in spWeb.Site.Solutions let name = s.Name where name.Equals(templateName) select s).FirstOrDefault(); if (currentTemplate != null) { spWeb.Site.Solutions.Remove(currentTemplate); SPList solGallery = spWeb.Site.RootWeb.Site.GetCatalog(SPListTemplateType.SolutionCatalog); foreach (SPListItem item in solGallery.Items.Cast <SPListItem>().Where(item => item.File.Name.Equals(templateName))) { solGallery.Items.DeleteItemById(item.ID); break; } } SPList spList = spWeb.Site.RootWeb.Lists.TryGetList("Template Gallery"); if (spList != null) { SPListItem listItem = (from SPListItem spListItem in spList.Items let spFieldUrlValue = new SPFieldUrlValue(spListItem["URL"].ToString()) where new Uri(spFieldUrlValue.Url).AbsolutePath.ToLower().Equals(spWeb.ServerRelativeUrl.ToLower()) select spListItem).FirstOrDefault(); if (listItem != null) { bool.TryParse(listItem["IncludeContent"].ToString(), out includeContent); } } spWeb.SaveAsTemplate(templateName, spWeb.Title, spWeb.Description, includeContent); } } }); Result = "SUCCESS"; } catch (Exception exception) { Result = exception.Message; } }
public SPUserSolutionEntity(SPUserSolution solution) { _underlyingObject = solution; }