Beispiel #1
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite sourceSite = new SPSite(__Context.Web.Site.ID, __Context.Site.UserToken))
                {
                    using (SPWeb sourceWeb = sourceSite.OpenWeb(this.__Context.Web.ID))
                    {
                        //replace any workflow variables
                        string destinationUrlProcessed = Helper.ProcessStringField(DestinationListURL, executionContext.Activity, __Context);

                        using (SPSite destSite = new SPSite(destinationUrlProcessed, __Context.Site.UserToken))
                        {
                            using (SPWeb destWeb = destSite.OpenWeb())
                            {
                                SPList destinationList = null;

                                //each list, even a non document library list has at least a root folder.
                                SPFolder destFolder = destWeb.GetFolder(destinationUrlProcessed);

                                if (!destFolder.Exists)
                                {
                                    throw new ApplicationException(string.Format("List at {0} does not exist!", DestinationListURL));
                                }

                                destinationList = destWeb.Lists[destFolder.ParentListId];

                                SPList sourceList = sourceWeb.Lists[new Guid(SourceListID)];

                                SPListItem sourceItem = sourceList.Items.GetItemById(SourceListItemID);

                                ItemCopier.ListItemCopyOptions options = new ItemCopier.ListItemCopyOptions();

                                options.IncludeAttachments = true;

                                options.OperationType = ItemCopier.OperationType.Copy;

                                options.Overwrite = true;

                                options.DestinationFolder = destFolder;

                                using (ItemCopier myCopier = new ItemCopier(sourceItem, destinationList, options))
                                {
                                    myCopier.UpdateItem(DestinationItemID);

                                    string message = "Item Updated item at" + DestinationListURL + "; ID: " + DestinationItemID + "; with data from list:" + SourceListID + "; item:" + SourceListItemID;
                                    WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #2
0
 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     try
     {
         using (SPSite site = new SPSite(SiteURL, __Context.Web.CurrentUser.UserToken))
         {
             string message;
             if (string.IsNullOrEmpty(PortalURL) || string.IsNullOrEmpty(PortalTitle))
             {
                 site.PortalUrl  = "";
                 site.PortalName = "";
                 message         = "Site: " + SiteURL + "; portal connection reset";
             }
             else
             {
                 site.PortalUrl  = GetValidPortalURL();
                 site.PortalName = PortalTitle;
                 message         = "Site: " + SiteURL + "; attached to portal " + PortalTitle + " url (" + PortalURL + ")";
             }
             WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
         }
     }
     catch (Exception ex)
     {
         WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
         return(ActivityExecutionStatus.Faulting);
     }
     return(ActivityExecutionStatus.Closed);
 }
Beispiel #3
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite site = new SPSite(SiteURL, __Context.Web.CurrentUser.UserToken))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        if (string.IsNullOrEmpty(NewTitle))
                        {
                            NewTitle = "";
                        }

                        string oldTitle = web.Title;
                        web.Title = NewTitle;
                        web.Update();

                        string message = "Site: " + SiteURL + "; renamed from " + oldTitle + " to " + NewTitle;
                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #4
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite site = new SPSite(WebURL, __Context.Web.CurrentUser.UserToken))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPGroup siteGroup = GetSiteGroup(web);
                        if (siteGroup == null)
                        {
                            throw new Exception("Site Group, " + SiteGroupName + ", does not exists in Site " + WebURL);
                        }

                        SetSiteGroupAssociation(web, siteGroup);
                        SetupQuickLaunch(web, siteGroup);
                        SetGroupPermissions(web, siteGroup);

                        string message = "Site Group " + SiteGroupName + " associated to site " + WebURL;
                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #5
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                //replace any workflow variables
                string listURL = Helper.ProcessStringField(ListURL, executionContext.Activity, __Context);

                using (SPSite listSite = new SPSite(listURL, __Context.Site.UserToken))
                {
                    using (SPWeb listWeb = listSite.OpenWeb())
                    {
                        //each list, even a non document library list has at least a root folder.
                        SPFolder listFolder = listWeb.GetFolder(listURL);

                        if (!listFolder.Exists)
                        {
                            throw new ApplicationException(string.Format("List at {0} does not exist!", ListURL));
                        }

                        SPList list = listWeb.Lists[listFolder.ParentListId];

                        list.GetItemById(ItemID).Recycle();

                        string message = "Item with ID: " + ItemID + "; deleted from: " + ListURL;
                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #6
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            TemplateID = string.Empty;
            try
            {
                using (SPSite currentSite = new SPSite(__Context.Web.Site.ID, __Context.Web.CurrentUser.UserToken))
                {
                    TemplateID = LookupTemplateIDInGallery(currentSite);
                    if (string.IsNullOrEmpty(TemplateID))
                    {
                        TemplateID = LookupTemplateIDInDefinitions(currentSite);

                        if (string.IsNullOrEmpty(TemplateID))
                        {
                            string message = "Failed to locate templateID for template named " + TemplateName + " LCID " + LCID + " in site " + currentSite.Url;
                            WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.WorkflowError, "Failure", UserID, message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }

            if (string.IsNullOrEmpty(TemplateID))
            {
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #7
0
 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     try
     {
         using (SPSite site = new SPSite(SiteURL, __Context.Web.CurrentUser.UserToken))
         {
             using (SPWeb web = site.OpenWeb())
             {
                 string message;
                 if (web.Properties.ContainsKey(Key))
                 {
                     web.Properties[Key] = Value;
                     message             = "Site, " + SiteURL + ", property " + Key + " updated with value " + Value;
                 }
                 else
                 {
                     web.Properties.Add(Key, Value);
                     message = "Site, " + SiteURL + ", property " + Key + " added new with value " + Value;
                 }
                 web.Properties.Update();
                 WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
             }
         }
     }
     catch (Exception ex)
     {
         WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
         return(ActivityExecutionStatus.Faulting);
     }
     return(ActivityExecutionStatus.Closed);
 }
Beispiel #8
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite targetSite = new SPSite(WebURL, __Context.Site.UserToken))
                {
                    using (SPWeb targetWeb = targetSite.OpenWeb())
                    {
                        targetWeb.MasterUrl       = MasterUrl;
                        targetWeb.CustomMasterUrl = CustomMasterUrl;

                        if (string.IsNullOrEmpty(AlternateCssUrl))
                        {
                            AlternateCssUrl = "";
                        }
                        targetWeb.AlternateCssUrl = AlternateCssUrl;
                        targetWeb.Update();
                    }

                    string message = "Web Masterpage settings updated.  MasterURL:" + MasterUrl + " CustomMasterURL:" + CustomMasterUrl + " AlternateCSSUrl:" + AlternateCssUrl;
                    WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #9
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                Guid featureDefinitionID = GetFeatureID();
                if (featureDefinitionID == Guid.Empty)
                {
                    throw new ApplicationException("Feature titled " + FeatureTitle + " not defined in scope " + FeatureScope.ToString());
                }

                using (SPSite targetSite = new SPSite(WebURL, __Context.Site.UserToken))
                {
                    if (GetTargetScope() == SPFeatureScope.Site)
                    {
                        targetSite.Features.Add(featureDefinitionID, true);
                    }
                    else if (GetTargetScope() == SPFeatureScope.Web)
                    {
                        using (SPWeb targetWeb = targetSite.OpenWeb())
                        {
                            targetWeb.Features.Add(featureDefinitionID, true);
                        }
                    }

                    string message = GetTargetScope().ToString() + " feature, " + FeatureTitle + "(" + featureDefinitionID.ToString() + "), activated at " + WebURL;
                    WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #10
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                string secondaryLogin       = GetEmptyAsNull(SecondaryOwnerLogin);
                string secondaryDisplayName = GetEmptyAsNull(SecondaryOwnerDisplayName);
                string secondaryEmail       = GetEmptyAsNull(SecondaryOwnerEmail);
                string templateID           = GetEmptyAsNull(TemplateID);
                string description          = GetNullAsEmpty(SiteDescription);
                string title = GetNullAsEmpty(SiteTitle);


                SPSiteCollection sites = GetSitesCollection();
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    if (IsolateInNewContentDB)
                    {
                        using (SPSite site = sites.Add(SiteURL, title, description, LCID, templateID, PrimaryOwnerLogin, PrimaryOwnerDisplayName, PrimaryOwnerEmail, secondaryLogin, secondaryDisplayName, secondaryEmail, DBServer, NewContentDBName, null, null))
                        {
                            CapContentDB(site);
                            Result = site.Url;
                        }
                    }
                    else
                    {
                        using (SPSite site = sites.Add(SiteURL, title, description, LCID, templateID, PrimaryOwnerLogin, PrimaryOwnerDisplayName, PrimaryOwnerEmail, secondaryLogin, secondaryDisplayName, secondaryEmail))
                        {
                            Result = site.Url;
                        }
                    }

                    string message = "Provisioning Site Collection " + SiteTitle + " at " + SiteURL;
                    WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                });
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #11
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite site = new SPSite(WebURL, __Context.Web.CurrentUser.UserToken))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        if (SiteGroupExists(web, GroupName))
                        {
                            throw new Exception("Site Group, " + GroupName + ", Already Exists in Site " + WebURL);
                        }

                        web.SiteGroups.Add(GroupName, web.CurrentUser, web.CurrentUser, GroupDescription);
                        SPGroup group = GetSiteGroup(web, GroupName);

                        if (group == null)
                        {
                            throw new Exception("Failed to Create site group, " + GroupName + ", in Site " + WebURL);
                        }

                        SetGroupOwner(group);

                        group.Users.Remove(web.CurrentUser.LoginName);
                        AddGroupMembers(group);

                        string message = "Created Group " + GroupName + " in site " + WebURL;
                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #12
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite site = new SPSite(WebURL, __Context.Web.CurrentUser.UserToken))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        string[] templateIDs = TemplateIDs.Split(';');
                        Collection <SPWebTemplate> templateList = new Collection <SPWebTemplate>();
                        foreach (string templateid in templateIDs)
                        {
                            SPWebTemplate template = LookupTemplate(site, templateid);
                            if (template != null)
                            {
                                templateList.Add(template);
                            }
                            else
                            {
                                throw new Exception("Could not locate template, " + templateid + ", in site, " + WebURL + ".");
                            }
                        }
                        web.SetAvailableWebTemplates(templateList, LCID);
                        web.Update();

                        string message = "Web: " + WebURL + " templates restricted to: " + TemplateIDs;
                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #13
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                // SPSecurity.RunWithElevatedPrivileges(delegate()
                //{
                string parentSiteURL = GetParentSiteURL();
                using (SPSite parentSite = new SPSite(parentSiteURL, __Context.Web.CurrentUser.UserToken))
                {
                    using (SPWeb parentWeb = parentSite.OpenWeb())
                    {
                        SPUser user2 = parentWeb.CurrentUser;

                        string webRelativeURL = SiteURL.Substring(parentWeb.Url.Length + 1);
                        if (String.IsNullOrEmpty(SiteDescription))
                        {
                            SiteDescription = "";
                        }

                        SPWeb subsite = parentWeb.Webs.Add(webRelativeURL, SiteTitle, SiteDescription, LCID, TemplateID, UseUniquePermissions, ConvertIfExists);
                        subsite.Navigation.UseShared = true;

                        Result = subsite.Url;

                        string message = "Provisioning " + SiteTitle + " at " + SiteURL;
                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                    }
                }
                //});
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }
Beispiel #14
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            try
            {
                using (SPSite sourceSite = new SPSite(__Context.Web.Site.ID, __Context.Site.UserToken))
                {
                    using (SPWeb sourceWeb = sourceSite.OpenWeb(this.__Context.Web.ID))
                    {
                        SPList sourceList = sourceWeb.Lists[new Guid(ListID)];

                        //replace any workflow variables
                        string destinationUrls = Helper.ProcessStringField(DestinationListUrl, executionContext.Activity, __Context);

                        ColumnHelper.EnsurePublishColumns(sourceList, destinationUrls);

                        SPListItem    sourceItem          = sourceList.Items.GetItemById(ListItemID);
                        StringBuilder resultLinks         = new StringBuilder();
                        string[]      destinationListUrls = destinationUrls.Trim().Trim(';').Split(';');
                        foreach (string destinationUrl in destinationListUrls)
                        {
                            SPFolder destFolder = ListHelper.GetSPFolderFromURL(destinationUrl);

                            if (!destFolder.Exists)
                            {
                                throw new ApplicationException(string.Format("List at {0} does not exist!", destinationUrl));
                            }

                            SPList destinationList = ListHelper.GetSPListFromURL(destinationUrl, __Context.Site.UserToken);

                            ItemCopier.ListItemCopyOptions options = new ItemCopier.ListItemCopyOptions();
                            options.IncludeAttachments = true;
                            options.OperationType      = ItemCopier.OperationType.Copy;
                            options.Overwrite          = true;
                            options.DestinationFolder  = destFolder;
                            options.LinkToOriginal     = true;

                            using (ItemCopier myCopier = new ItemCopier(sourceItem, destinationList, options))
                            {
                                int itemID = GetExistingID(destinationList, destinationUrl);
                                if (itemID > 0)
                                {
                                    myCopier.UpdateItem(itemID);
                                    string message = "Published item updated from List: " + ListID + "; item: " + ListItemID + "; to url:" + DestinationListUrl + "; new id: " + itemID;
                                    WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                                }
                                else
                                {
                                    itemID = myCopier.Copy();
                                    using (SPWeb destWeb = destinationList.ParentWeb)
                                    {
                                        string newURL = destWeb.Url + "/" + destinationList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?id=" + itemID + " ; ";
                                        resultLinks.Append(newURL.ToLower());

                                        string message = "New Item Published from List: " + ListID + "; item: " + ListItemID + "; to url:" + newURL;
                                        WorkflowHistoryLogger.LogMessage(executionContext, SPWorkflowHistoryEventType.None, "Complete", UserID, message);
                                    }
                                }
                            }
                        }
                        string currentLinks = (string)sourceItem[ColumnHelper.PublishedToInternalColumnName];
                        sourceItem[ColumnHelper.PublishedToInternalColumnName] = resultLinks.ToString() + currentLinks;
                        sourceItem.SystemUpdate();
                    }
                }
            }
            catch (Exception ex)
            {
                WorkflowHistoryLogger.LogError(executionContext, UserID, ex);
                return(ActivityExecutionStatus.Faulting);
            }
            return(ActivityExecutionStatus.Closed);
        }