private static void DeleteItemsAndList(SPList list, SPWeb targetWeb)
        {
            StringBuilder deleteBatch = new StringBuilder();
            deleteBatch.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");

            string mask = "<Method><SetList Scope=\"Request\">" + list.ID + "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
            foreach (SPListItem item in list.Items)
            {
                deleteBatch.Append(string.Format(mask, item.ID));
            }
            deleteBatch.Append("</Batch>");
            targetWeb.ProcessBatchData(deleteBatch.ToString());
            list.Delete();
        }
        /// <summary>
        /// Occurs when a Feature is deactivated.
        /// </summary>
        /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"/> object that represents the properties of the event.</param>
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            string _state = default(string);

            try
            {
                {
                    SPSite _site = (SPSite)properties.Feature.Parent;
                    {
                        //This best practice addresses the issue identified by the SharePoint Dispose Checker Tool as SPDisposeCheckID_140.
                        //More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_140
                        SPWeb  _web      = _site.RootWeb;
                        SPList _taskList = _web.Lists[CommonDefinition.SendNotificationWorkflowTasks];
                        _taskList.Delete();
                        SPList _historyList = _web.Lists[CommonDefinition.SendNotificationWorkflowHistory];
                        _historyList.Delete();
                        _web.Update();
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.DataImportLibraryTitle], ImportDictionaries.Definitions.IDGuid);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.ScheduleTemplateListTitle], AddTimeSlots.Definitions.IDGuid);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.ShippingListTitle], ShippingStateMachine.ShippingStateMachine.WorkflowId);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.ShippingListTitle], CreateSealProtocol.CreateSealProtocol.WorkflowId);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.ShippingListTitle], CreateSecurityPO1.CreateSecurityPO1.WorkflowId);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.ShippingListTitle], CreatePO.CreatePO.WorkflowId);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.EscortPOLibraryTitle], SendEmail.SendEmail.WorkflowId);
                        RemoveWorkflowAssociation(_web.Lists[CommonDefinition.FreightPOLibraryTitle], SendEmail.SendEmail.WorkflowId);
                    }
                }
            }
            catch (Exception _ex)
            {
                string _frmt = "FeatureDeactivating failed in the {0} state because of the error {1}";
                throw new ApplicationException(String.Format(_frmt, _state, _ex.Message));
            }
        }
        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;

            using (web = web.Site.OpenWeb())
            {
                SPList list = web.Lists.TryGetList("Nauplius.ADLDS.FBA - StsFarm");
                if (list != null)
                {
                    try
                    {
                        list.Delete();
                    }
                    catch (Exception)
                    { }
                }

                SPList list2 = web.Lists.TryGetList("Nauplius.ADLDS.FBA - WebApplicationSettings");
                if (list2 != null)
                {
                    try
                    {
                        list2.Delete();
                    }
                    catch (Exception)
                    { }
                }
            }
        }
Ejemplo n.º 4
0
        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            using (web = web.Site.OpenWeb())
            {
                SPList list = web.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - GlobalSettings");
                if (list != null)
                {
                    try
                    {
                        list.Delete();
                    }
                    catch (Exception)
                    { }
                }

                SPList list2 = web.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - WebAppSettings");
                if (list2 != null)
                {
                    try
                    {
                        list2.Delete();
                    }
                    catch (Exception)
                    { }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes the specified list.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="force">if set to <c>true</c> [force].</param>
        internal static void Delete(SPList list, bool force)
        {
            if (list == null)
            {
                throw new SPException("List not found.");
            }

            if (!list.AllowDeletion && force)
            {
                list.AllowDeletion = true;
                list.Update();
            }
            else if (!list.AllowDeletion)
            {
                throw new SPException("List cannot be deleted.  Try using the '-force' parameter to force the delete.");
            }

            try
            {
                list.Delete();
            }
            catch (Exception)
            {
                if (force)
                {
                    using (SPSite site = new SPSite(list.ParentWeb.Site.ID))
                    {
                        Utilities.RunStsAdmOperation(
                            string.Format(" -o forcedeletelist -url \"{0}\"",
                                          site.MakeFullUrl(list.RootFolder.ServerRelativeUrl)), false);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void PerformDelete()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SquadronContext.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        foreach (string title in NameList.CheckedItems)
                        {
                            SPList list = web.Lists[title];

                            try
                            {
                                list.Delete();

                                SquadronContext.WriteMessage(title + " DELETE done.");
                            }
                            catch (Exception ex)
                            {
                                SquadronContext.WriteMessage("DELETE Exception for " + title + " " + ex.ToString());
                            }
                        }
                    }
                }
            });

            SquadronContext.WriteMessage("Performed DELETE operations.");
            RefreshList();
        }
Ejemplo n.º 7
0
        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            SPAdministrationWebApplication adminWebApp = SPAdministrationWebApplication.Local;

            using (SPSite siteCollection = new SPSite(adminWebApp.Sites[0].Url))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    SPList list = site.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - GlobalSettings");
                    if (list != null)
                    {
                        try
                        {
                            list.Delete();
                        }
                        catch (Exception)
                        { }
                    }

                    SPList list2 = site.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - WebAppSettings");
                    if (list2 != null)
                    {
                        try
                        {
                            list2.Delete();
                        }
                        catch (Exception)
                        { }
                    }
                }
            }
        }
        /// <summary>
        /// Deletes the specified list.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="force">if set to <c>true</c> [force].</param>
        internal static void Delete(SPList list, bool force)
        {
            if (list == null)
                throw new SPException("List not found.");

            if (!list.AllowDeletion && force)
            {
                list.AllowDeletion = true;
                list.Update();
            }
            else if (!list.AllowDeletion)
                throw new SPException("List cannot be deleted.  Try using the '-force' parameter to force the delete.");

            try
            {
                list.Delete();
            }
            catch (Exception)
            {
                if (force)
                {
                    using (SPSite site = new SPSite(list.ParentWeb.Site.ID))
                    {
                        Utilities.RunStsAdmOperation(
                            string.Format(" -o forcedeletelist -url \"{0}\"",
                                          site.MakeFullUrl(list.RootFolder.ServerRelativeUrl)), false);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static SPList CopyList(SPList source, SPWeb webDestination, string destinationTitle, bool deleteIfExist)
        {
            SPList destinationList = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(webDestination.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb(webDestination.ID))
                    {
                        web.AllowUnsafeUpdates = true;
                        destinationList        = web.Lists.Cast <SPList>().Where(p => string.Compare(p.Title, destinationTitle) == 0).FirstOrDefault();

                        if (destinationList != null)
                        {
                            if (deleteIfExist)
                            {
                                destinationList.Delete();
                            }
                            else
                            {
                                return;
                            }
                            //throw new Exception("Destination list already exist");
                        }

                        try
                        {
                            Guid newListID  = web.Lists.Add(destinationTitle, string.Empty, SPListTemplateType.GenericList);
                            destinationList = web.Lists[newListID];

                            destinationList.ContentTypesEnabled = true;
                            destinationList.Update();

                            if (destinationList.ContentTypes.Cast <SPContentType>().FirstOrDefault(ct => ct.Name == "Item") != null &&
                                source.ContentTypes.Count > 1)
                            {
                                destinationList.ContentTypes["Item"].Delete();
                                destinationList.Update();
                            }

                            source.CopyAllFieldsToList(destinationList);

                            source.CopyAllContentTypesToList(destinationList);

                            source.CopyAllViewsToList(destinationList);
                        }
                        catch (Exception ex)
                        {
                        }
                        web.AllowUnsafeUpdates = false;
                    }
                }
            }
                                                 );

            return(destinationList);
        }
Ejemplo n.º 10
0
        public static void DeleteList(SPWeb web)
        {
            SPList list = web.Lists.TryGetList(Language.SMUListName);

            if (list != null)
            {
                list.Delete();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Ensure that the list will be deleted.
        /// </summary>
        /// <param name="web"></param>
        /// <param name="listTitle"></param>
        public static void EnsureListCleanup(SPWeb web, string Title)
        {
            SPList list = web.Lists.TryGetList(Title);

            if (list != null)
            {
                list.Delete();
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This method used to delete lists that are created as part of feature activation
        /// </summary>
        /// <param name="url"></param>
        private void deletLists(string url)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPWeb web = new SPSite(url).OpenWeb())
                {
                    SPList list = web.Lists.TryGetList(Settings.featureIdsListName);
                    if (list != null)
                    {
                        list.Delete();
                    }

                    list = web.Lists.TryGetList(Settings.custMessageListName);
                    if (list != null)
                    {
                        list.Delete();
                    }
                }
            });
        }
 private void DealWithList(SPWeb web, string listTitle)
 {
     try
     {
         SPList list = web.Lists[listTitle];
         list.Delete();
     }
     catch (Exception e)
     {
         APPSLogger.Logger(Microsoft.SharePoint.Administration.TraceSeverity.High, string.Format("ACSSOLUTION0007 Exception: {0}", e.ToString()));
     }
 }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb site = properties.Feature.Parent as SPWeb;

            if (site != null)
            {
                SPList list = site.Lists.TryGetList("Footer Links");
                if (list != null)
                {
                    list.Delete();
                }
            }
        }
Ejemplo n.º 15
0
        private void RemoveWorkLib_ExecuteCode(object sender, EventArgs e)
        {
            string batchName = workflowProperties.Item["BatchName"].ToString();

            using (SPSite site = new SPSite(workflowProperties.SiteId))
            {
                using (SPWeb web = site.AllWebs[workflowProperties.WebId])
                {
                    SPList list = web.Lists[batchName];
                    list.Delete();
                }
            }
        }
Ejemplo n.º 16
0
 public void DeleteList(string listName)
 {
     //Check to see if list already exists
     try
     {
         SPList targetList = oSPSite.RootWeb.Lists[listName];
         targetList.Delete();
     }
     catch (ArgumentException)
     {
         //The list does not exist, thus you can create it
     }
 }
Ejemplo n.º 17
0
        // Triggers when the activity is executed.
        protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
        {
            try
            {
                // Get a reference to the SharePoint site.
                SPSite site = new SPSite("http://" + System.Environment.MachineName);
                SPWeb  web  = site.OpenWeb("/");

                // Reference the original Announcements list.
                SPList aList = web.GetList("/Lists/Announcements");

                // If the Announcements Backup list already exists, delete it.
                try
                {
                    SPList bList = web.GetList("/Lists/Announcements Backup");
                    bList.Delete();
                }
                catch
                { }

                // Create a new backup Announcements list and reference it.
                Guid   newAnnID = web.Lists.Add("Announcements Backup", "A backup Announcements list.", SPListTemplateType.Announcements);
                SPList bakList  = web.Lists[newAnnID];

                // Copy announcements from original to backup Announcements list.
                foreach (SPListItem item in aList.Items)
                {
                    SPListItem newAnnItem = bakList.Items.Add();
                    foreach (SPField field in aList.Fields)
                    {
                        if (!field.ReadOnlyField)
                        {
                            newAnnItem[field.Id] = item[field.Id];
                        }
                    }
                    newAnnItem.Update();
                }

                // Put the Backup Announcements list on the QuickLaunch bar.
                bakList.OnQuickLaunch = true;
                bakList.Update();
            }

            catch (Exception errx)
            {
                System.Diagnostics.Debug.WriteLine("Error: " + errx.ToString());
            }

            return(base.Execute(executionContext));
        }
Ejemplo n.º 18
0
        private Guid EnsureListExists(ref SPWeb web)
        {
            SPList list = null;

            try
            {
                list = web.Lists.TryGetList(ListName);
            }
            catch { /* expected: list doesn't exist */ }

            if (RecreateListOnUpgrade && list != null)
            {
                list.Delete();
                web.Update();
                list = null;
            }

            if (list == null)
            {
                Guid listId;
                if (ListTemplateType != SPListTemplateType.InvalidType)
                {
                    listId = web.Lists.Add(ListName,
                                           string.Empty,
                                           ListTemplateType);
                }
                else
                {
                    listId = web.Lists.Add(ListName,
                                           string.Empty,
                                           AlternateListTemplate.listTargetUrlSuffix,
                                           AlternateListTemplate.FeatureId,
                                           AlternateListTemplate.ListTemplateId,
                                           AlternateListTemplate.DocumentTempateId);
                }
                // Write the changes to database
                web.Update();

                return(listId);
            }
            else
            {
                return(list.ID);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a SharePoint list (based on the Generic List template).
        /// </summary>
        /// <param name="spWeb">The target Web site for the list.</param>
        /// <param name="listTitle">The title of the list.</param>
        /// <param name="listDescription">A description for the list.</param>
        /// <param name="columns">A Dictionary object containing field names and types.</param>
        /// <param name="replaceExistingList">Indicates whether to overwrite an existing list of the same name on the site.</param>
        /// <returns>A GUID for the created (or existing) list.</returns>
        internal Guid CreateCustomList(SPWeb spWeb, string listTitle, string listDescription, Dictionary <string, SPFieldType> columns, bool replaceExistingList)
        {
            SPList list = spWeb.Lists.TryGetList(listTitle);

            if (list != null)
            {
                if (replaceExistingList == true)
                {
                    try
                    {
                        list.Delete();
                    }
                    catch
                    {
                        return(Guid.Empty);
                    }
                }
                else
                {
                    return(list.ID);
                }
            }

            try
            {
                Guid listId = spWeb.Lists.Add(listTitle, listDescription, SPListTemplateType.GenericList);
                list = spWeb.Lists[listId];
                SPView view = list.DefaultView;

                foreach (string key in columns.Keys)
                {
                    list.Fields.Add(key, columns[key], false);
                    view.ViewFields.Add(key);
                }

                list.Update();
                view.Update();

                return(listId);
            }
            catch
            {
                return(Guid.Empty);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a list template with the specified name. The list template created contains content type(s) associated with the specified type.
        /// </summary>
        /// <param name="type">A type that derives from <see cref="SPModel"/>.</param>
        /// <param name="targetWeb">Site object.</param>
        /// <param name="title">Name of list template.</param>
        public static void ProvisionAsTemplate(Type type, SPWeb targetWeb, string title)
        {
            SPList list = Provision(type, targetWeb, String.Concat("ListTemplate_", Path.GetRandomFileName().Replace(".", ""))).First();

            using (list.ParentWeb.GetAllowUnsafeUpdatesScope()) {
                string filename         = String.Concat(title, ".stp");
                SPFile previousTemplate = list.ParentWeb.Site.RootWeb.GetFile("_catalogs/lt/" + filename);
                if (previousTemplate.Exists)
                {
                    previousTemplate.Delete();
                }
                list.SaveAsTemplate(filename, title, String.Empty, false);
            }
            try {
                Thread.Sleep(5000);
                list.Delete();
            } catch { }
        }
Ejemplo n.º 21
0
        public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);

            var ct       = properties.ListItem.ContentType;
            var setting  = ct.GetCustomSettings <AutoCreationSettings>(AIAPortalFeatures.Infrastructure);
            var listItem = properties.ListItem;

            if (setting == null || !setting.RunOnCreated || !setting.EnableCreateList)
            {
                return;
            }
            if (setting.EnableCreateList)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    var url = listItem[setting.UrlFieldName].ToString();

                    //sync SPList title
                    using (SPSite site = new SPSite(properties.SiteId))
                    {
                        using (SPWeb web = site.OpenWeb(properties.Web.ID))
                        {
                            try
                            {
                                web.AllowUnsafeUpdates = true;
                                //delete List
                                SPList destList = web.Lists.TryGetList(listItem.Title);
                                if (destList != null)
                                {
                                    destList.Delete();
                                }
                            }
                            catch { }
                            finally
                            {
                                web.AllowUnsafeUpdates = false;
                            }
                        }
                    }
                });
            }
        }
Ejemplo n.º 22
0
 public void DeleteListWebSite(string listName)
 {
     using (SPSite site = new SPSite(_URL))
     {
         using (SPWeb oSWeb = site.OpenWeb())
         {
             //Check to see if list already exists
             try
             {
                 SPList targetList = site.OpenWeb().Lists[listName];
                 targetList.Delete();
             }
             catch (ArgumentException)
             {
                 //The list does not exist, thus you can create it
             }
         }
     }
 }
        public void DeleteList(String strListName)
        {
            SPList objSPList = null;
            SPWeb  objSPWeb  = null;

            try
            {
                objSPWeb = this.CurrentWeb;
                if (IsListExisting(strListName))
                {
                    objSPWeb.AllowUnsafeUpdates = true;
                    objSPList = objSPWeb.Lists.TryGetList(strListName);
                    objSPList.Delete();
                }
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
Ejemplo n.º 24
0
        void SetUpDropBox(Guid id)
        {
            // Library is created, now need to set it up
            dropBoxList = web.Lists[id];
            bool okToContinue = false;

            try
            {
                AddFields();

                // Set up versioning
                dropBoxList.EnableVersioning = true;
                dropBoxList.Update();

                // Reached point at which list is usable, so any errors from now, just log but continue.
                okToContinue = true;

                ChangeToInternationalNames();

                ClearPermissions();
                CreateNoPermissionsFolder(dropBoxList);
                ModifyDefaultView();
            }
            catch (SPException e)
            {
                store.LogError(culture.Resources.DropBoxListCreateFailure, e);
                if (okToContinue == false)
                {
                    // Error creating list - delete it
                    dropBoxList.Delete();
                    web.AllProperties[DropBox.PropertyKey] = null;
                    dropBoxList = null;
                    throw new SafeToDisplayException(string.Format(SlkCulture.GetCulture(), culture.Resources.DropBoxListCreateFailure, e.Message));
                }
            }
            catch (Exception e)
            {
                store.LogError(culture.Resources.DropBoxListCreateFailure, e);
                throw;
            }
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            using (SPWeb web = GetWeb(properties))
            {
                web.AllowUnsafeUpdates = true;
                /* Delete any fields here */

                SPList workMatterDocumentsLibrary = web.Lists.TryGetList(Resource.WorkMatterDocumentsLibrary);
                if (workMatterDocumentsLibrary != null && workMatterDocumentsLibrary.ItemCount == 0)
                {
                    workMatterDocumentsLibrary.Delete();
                    SPContentType workMatterDocumentContentType = web.ContentTypes[Resource.WorkMatterDocumentContentType];
                    web.ContentTypes.Delete(workMatterDocumentContentType.Id);
                }

                SPList vendorDocumentsLibrary = web.Lists.TryGetList(Resource.VendorDocumentsLibrary);
                if (vendorDocumentsLibrary != null && vendorDocumentsLibrary.ItemCount == 0)
                {
                    vendorDocumentsLibrary.Delete();
                    SPContentType vendorDocumentContentType = web.ContentTypes[Resource.VendorDocumentContentType];
                    web.ContentTypes.Delete(vendorDocumentContentType.Id);
                }

                SPList configurationList = web.Lists.TryGetList(Resource.ConfigurationList);
                if (configurationList != null && configurationList.ItemCount == 0)
                {
                    configurationList.Delete();
                }

                SPList categoryList = web.Lists.TryGetList(Resource.CategoryList);
                if (categoryList != null && categoryList.ItemCount == 0)
                {
                    categoryList.Delete();
                }

                web.AllowUnsafeUpdates = false;
                web.Update();
            }
        }
Ejemplo n.º 26
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication adminWebApplication = properties.Feature.Parent as SPWebApplication;

            foreach (SPJobDefinition job in adminWebApplication.JobDefinitions)
            {
                if (job.Name == tJobName)
                {
                    job.Delete();
                }
            }

            using (SPWeb web = adminWebApplication.Sites[0].OpenWeb())
            {
                SPList list = web.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - GlobalSettings");
                if (list != null)
                {
                    try
                    {
                        list.Delete();
                    }
                    catch (Exception)
                    { }
                }

                SPList list2 = web.Lists.TryGetList("Nauplius.ADLDS.UserProfiles - WebAppSettings");
                if (list2 != null)
                {
                    try
                    {
                        list2.Delete();
                    }
                    catch (Exception)
                    { }
                }
            }
        }
Ejemplo n.º 27
0
        public override bool Perform()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    using (var spSite = new SPSite(Web.Site.ID))
                    {
                        using (SPWeb spWeb = spSite.OpenWeb(Web.ID))
                        {
                            if (!spWeb.IsRootWeb)
                            {
                                LogMessage(spWeb.Title + " is not a root web.", MessageKind.SKIPPED, 2);
                                return;
                            }

                            LogMessage("Downloading new " + SETTINGS_LIST + " list", 2);

                            var catalog =
                                (SPDocumentLibrary)Web.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog);

                            const string TEMPLATE_NAME = SETTINGS_LIST + " [5.5]";

                            using (var webClient = new WebClient())
                            {
                                byte[] bytes =
                                    webClient.DownloadData(_storeUrl + "/Upgrade/" + SETTINGS_LIST.ToLower() + ".stp");
                                SPFile file = catalog.RootFolder.Files.Add(SETTINGS_LIST.Replace(" ", "_") + "_55.stp",
                                                                           bytes, true);
                                SPListItem li = file.GetListItem();
                                li["Title"]   = TEMPLATE_NAME;
                                li.SystemUpdate();
                            }

                            SPList list = Web.Lists.TryGetList(SETTINGS_LIST);
                            if (list != null)
                            {
                                LogMessage("Deleting old " + SETTINGS_LIST + " list", 2);

                                if (!list.AllowDeletion)
                                {
                                    list.AllowDeletion = true;
                                    list.Update();
                                }

                                list.Delete();

                                LogMessage(null, MessageKind.SUCCESS, 4);
                            }

                            LogMessage("Creating the " + SETTINGS_LIST + " list", 2);

                            SPListTemplateCollection listTemplates = spSite.GetCustomListTemplates(spWeb);
                            SPListTemplate template = listTemplates[TEMPLATE_NAME];

                            spWeb.Lists.Add(SETTINGS_LIST, string.Empty, template);

                            SPList spList        = spWeb.Lists[SETTINGS_LIST];
                            spList.Title         = SETTINGS_LIST;
                            spList.Hidden        = true;
                            spList.AllowDeletion = false;
                            spList.Update();

                            LogMessage(null, MessageKind.SUCCESS, 4);

                            SPList appList            = spWeb.Lists["Installed Applications"];
                            SPListItemCollection apps = appList.Items;
                            var tsAppExists           = apps.Cast <SPListItem>().Any(app => app.Title.Equals("Timesheets"));

                            if (tsAppExists)
                            {
                                return;
                            }

                            LogMessage("The Timesheets app is not installed", 2);
                            LogMessage("Removing the Timesheets link from the navigation", 3);

                            SPList settingsList = spWeb.Lists[SETTINGS_LIST];
                            SPListItem tsItem   = settingsList.GetItemById(90);
                            tsItem.Delete();
                            settingsList.Update();

                            LogMessage(null, MessageKind.SUCCESS, 4);
                        }
                    }
                });
            }
            catch (Exception e)
            {
                LogMessage(e.Message, MessageKind.FAILURE, 2);
            }
            finally
            {
                try
                {
                    CacheStore.Current.RemoveSafely(Web.Url, new CacheStoreCategory(Web).Navigation);
                }
                catch { }
            }

            return(true);
        }
Ejemplo n.º 28
0
 public void Delete()
 {
     m_list.Delete();
 }
Ejemplo n.º 29
0
        public override bool Perform()
        {
            storeurl = CoreFunctions.getFarmSetting("workenginestore");

            solutions = (SPDocumentLibrary)base.SPWeb.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog);

            LogMessage("Activating List Features");

            SPSite.Features.Add(new Guid("e08e676e-81fb-497e-9590-9d1c2673b85c"), true);


            //==============================================================
            LogMessage("Removing old settings list");

            try
            {
                SPList settings = SPWeb.Lists.TryGetList("EPM Live Settings");

                if (settings != null)
                {
                    settings.Delete();
                }
            }
            catch (Exception ex)
            {
                LogMessage("", ex.Message, 3);
            }

            //==============================================================

            LogMessage("Downloading and Installing List Templates");

            DownloadAndInstallList("Departments", "Departments", "Departments");
            DownloadAndInstallList("HolidaySchedules", "HolidaySchedules", "Holiday Schedules");
            DownloadAndInstallList("Holidays", "Holidays", "Holidays");

            if (base.bIsPfe)
            {
                DownloadAndInstallList("EPM Live Settings", "pfe epm live settings", "EPM Live Settings");
            }
            else
            {
                DownloadAndInstallList("EPM Live Settings", "epm live settings", "EPM Live Settings");
            }

            DownloadAndInstallList("Roles", "Roles", "Roles");
            DownloadAndInstallList("WorkHours", "WorkHours", "Work Hours");
            DownloadAndInstallList("Time Off", "TimeOff", "Time Off");
            //==============================================================


            LogMessage("Checking Holidays Lookup");

            SPList oHolidays         = SPWeb.Lists.TryGetList("Holidays");
            SPList oHolidaySchedules = SPWeb.Lists.TryGetList("Holiday Schedules");
            SPList oResourcePool     = SPWeb.Lists.TryGetList("Resources");

            if (oHolidays == null)
            {
                LogMessage("", "Holidays list missing", 3);
            }
            else if (oHolidaySchedules == null)
            {
                LogMessage("", "Holiday Schedules list missing", 3);
            }
            else
            {
                SPField oField = null;
                try
                {
                    oField = oHolidays.Fields.GetFieldByInternalName("HolidaySchedule");
                }
                catch { }

                if (oField == null)
                {
                    LogMessage("\tCreating Holidays Lookup");

                    oField       = oHolidays.Fields.GetFieldByInternalName(oHolidays.Fields.AddLookup("HolidaySchedule", oHolidaySchedules.ID, true));
                    oField.Title = "Holiday Schedule";
                    oField.Update();

                    var spFieldLookup = (SPFieldLookup)oField;
                    spFieldLookup.LookupField = "Title";
                    spFieldLookup.Update();
                }
                else
                {
                    LogMessage("\tUpdating Holidays Lookup");

                    SPFieldLookup oLookup = (SPFieldLookup)oField;
                    if (new Guid(oLookup.LookupList) != oHolidaySchedules.ID)
                    {
                        oField.Delete();
                        oHolidays.Update();
                        oField       = oHolidays.Fields.GetFieldByInternalName(oHolidays.Fields.AddLookup("HolidaySchedule", oHolidaySchedules.ID, true));
                        oField.Title = "Holiday Schedule";
                        oField.Update();

                        var spFieldLookup = (SPFieldLookup)oField;
                        spFieldLookup.LookupField = "Title";
                        spFieldLookup.Update();
                    }
                }

                oHolidays.Update();
            }

            //Fixing Department Lookup

            SPList oDepartments = SPWeb.Lists.TryGetList("Departments");

            if (oDepartments == null)
            {
                LogMessage("", "Departments list missing", 3);
            }
            else
            {
                LogMessage("Departments list lookups");

                try
                {
                    SPFieldLookup lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("RBS");
                    if (new Guid(lookup.LookupList) != oDepartments.ID)
                    {
                        bool bSealed = lookup.Sealed;
                        if (bSealed)
                        {
                            lookup.Sealed = false;
                            lookup.Update();
                        }
                        lookup.AllowDeletion = true;
                        lookup.Update();
                        lookup.Delete();

                        oDepartments.Fields.AddLookup("RBS", oDepartments.ID, false);

                        lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("RBS");



                        lookup.LookupField = "DisplayName";
                        lookup.Title       = "Parent Department";
                        lookup.Update();

                        if (bSealed)
                        {
                            lookup.Sealed = true;
                            lookup.Update();
                        }

                        LogMessage("\tField RBS");
                    }
                }
                catch (Exception ex)
                {
                    LogMessage("", "Field RBS: " + ex.Message, 3);
                }

                try
                {
                    SPFieldLookup lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Managers");
                    if (new Guid(lookup.LookupList) != oResourcePool.ID)
                    {
                        bool bSealed = lookup.Sealed;
                        if (bSealed)
                        {
                            lookup.Sealed = false;
                            lookup.Update();
                        }
                        lookup.AllowDeletion = true;
                        lookup.Update();
                        lookup.Delete();

                        oDepartments.Fields.AddLookup("Managers", oResourcePool.ID, true);

                        lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Managers");



                        lookup.LookupField = "Title";
                        lookup.Update();

                        if (bSealed)
                        {
                            lookup.Sealed = true;
                            lookup.Update();
                        }

                        LogMessage("\tField Managers");
                    }
                }
                catch (Exception ex)
                {
                    LogMessage("", "Field Managers: " + ex.Message, 3);
                }

                try
                {
                    SPFieldLookup lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Executives");
                    if (new Guid(lookup.LookupList) != oResourcePool.ID)
                    {
                        bool bSealed = lookup.Sealed;
                        if (bSealed)
                        {
                            lookup.Sealed = false;
                            lookup.Update();
                        }
                        lookup.AllowDeletion = true;
                        lookup.Update();
                        lookup.Delete();

                        oDepartments.Fields.AddLookup("Executives", oResourcePool.ID, false);

                        lookup = (SPFieldLookup)oDepartments.Fields.GetFieldByInternalName("Executives");

                        lookup.LookupField = "Title";
                        lookup.Update();

                        if (bSealed)
                        {
                            lookup.Sealed = true;
                            lookup.Update();
                        }

                        LogMessage("\tField Executives");
                    }
                }
                catch (Exception ex)
                {
                    LogMessage("", "Field Executives: " + ex.Message, 3);
                }
            }


            LogMessage("Processing Time Off Temp Data");

            SPList oNonWork = SPWeb.Lists.TryGetList("Non Work");
            SPList oTimeOff = SPWeb.Lists.TryGetList("Time Off");

            if (oNonWork == null)
            {
                LogMessage("", "Non Work list missing", 3);
            }
            else if (oTimeOff == null)
            {
                LogMessage("", "Time Off list missing", 3);
            }
            else
            {
                if (!oTimeOff.Fields.ContainsFieldWithInternalName("TempType"))
                {
                    oTimeOff.Fields.Add("TempType", SPFieldType.Text, false);
                    oTimeOff.Update();

                    try
                    {
                        SPField oField = oTimeOff.Fields.GetFieldByInternalName("TempType");
                        oField.ShowInDisplayForm = false;
                        oField.ShowInEditForm    = false;
                        oField.ShowInNewForm     = false;
                        oField.Update();
                    }
                    catch { }
                }

                SPField oTimeOffType = null;
                try
                {
                    oTimeOffType = oTimeOff.Fields.GetFieldByInternalName("TimeOffType");
                }
                catch { }

                if (oTimeOffType != null && oTimeOffType.Type == SPFieldType.Choice)
                {
                    LogMessage("\tProcessing Temp Items");

                    foreach (SPListItem li in oTimeOff.Items)
                    {
                        try
                        {
                            li["TempType"] = li[oTimeOffType.Id].ToString();
                            li.Update();
                        }
                        catch (Exception ex)
                        {
                            LogMessage("\t", li.Title + ": " + ex.Message, 3);
                        }
                    }
                }

                SPField oWorkDetail = null;
                try
                {
                    oWorkDetail = oTimeOff.Fields.GetFieldByInternalName("WorkDetail");
                }
                catch { }

                if (oWorkDetail == null)
                {
                    try
                    {
                        oTimeOff.Fields.AddFieldAsXml(@"<Field Type=""DaysHoursBreakdownField"" DisplayName=""WorkDetail"" Required=""FALSE"" EnforceUniqueValues=""FALSE"" StaticName=""WorkDetail"" Name=""WorkDetail"" ><Customization><ArrayOfProperty><Property><Name>StartDateField</Name><Value xmlns:q1=""http://www.w3.org/2001/XMLSchema"" p4:type=""q1:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">StartDate</Value></Property><Property><Name>FinishDateField</Name><Value xmlns:q2=""http://www.w3.org/2001/XMLSchema"" p4:type=""q2:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">DueDate</Value></Property><Property><Name>HoursField</Name><Value xmlns:q3=""http://www.w3.org/2001/XMLSchema"" p4:type=""q3:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Work</Value></Property><Property><Name>HolidaySchedulesField</Name><Value xmlns:q4=""http://www.w3.org/2001/XMLSchema"" p4:type=""q4:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">HolidaySchedule</Value></Property><Property><Name>ResourcePoolList</Name><Value xmlns:q5=""http://www.w3.org/2001/XMLSchema"" p4:type=""q5:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Resources</Value></Property><Property><Name>WorkHoursList</Name><Value xmlns:q6=""http://www.w3.org/2001/XMLSchema"" p4:type=""q6:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Work Hours</Value></Property><Property><Name>HolidaysList</Name><Value xmlns:q7=""http://www.w3.org/2001/XMLSchema"" p4:type=""q7:string"" xmlns:p4=""http://www.w3.org/2001/XMLSchema-instance"">Holidays</Value></Property></ArrayOfProperty></Customization></Field>");
                        SPField oField = oTimeOff.Fields.GetFieldByInternalName("WorkDetail");
                        oField.Title = "Work Detail";
                        oField.Update();

                        LogMessage("\tAdd Work Detail Field");
                    }
                    catch (Exception ex)
                    {
                        LogMessage("", "Add Work Detail: " + ex.Message, 3);
                    }
                }
            }

            try
            {
                if (!oResourcePool.Fields.ContainsFieldWithInternalName("EXTID"))
                {
                    oResourcePool.Fields.Add("EXTID", SPFieldType.Text, false);
                    SPField oField = oResourcePool.Fields.GetFieldByInternalName("EXTID");
                    oField.Hidden = true;
                    oField.Update();

                    LogMessage("Add EXTID Field to Resources");
                }
            }
            catch (Exception ex)
            {
                LogMessage("", "Add EXTID Field to Resources: " + ex.Message, 3);
            }

            //Process dept event

            LogMessage("Processing Department Events");

            try
            {
                bool badding   = false;
                bool bupdating = false;
                bool bdeleted  = false;

                string sClass    = "EPMLiveCore.DepartmentEvent";
                string sAssembly = "EPM Live Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5";

                foreach (SPEventReceiverDefinition e in oDepartments.EventReceivers)
                {
                    if (e.Assembly == sAssembly && e.Class == sClass)
                    {
                        if (e.Type == SPEventReceiverType.ItemAdding)
                        {
                            badding = true;
                        }
                        else if (e.Type == SPEventReceiverType.ItemUpdating)
                        {
                            bupdating = true;
                        }
                        else if (e.Type == SPEventReceiverType.ItemDeleted)
                        {
                            bdeleted = true;
                        }
                    }
                }

                if (!badding)
                {
                    oDepartments.EventReceivers.Add(SPEventReceiverType.ItemAdding, sAssembly, sClass);
                    oDepartments.Update();
                }

                if (!bupdating)
                {
                    oDepartments.EventReceivers.Add(SPEventReceiverType.ItemUpdating, sAssembly, sClass);
                    oDepartments.Update();
                }
                if (!bdeleted)
                {
                    oDepartments.EventReceivers.Add(SPEventReceiverType.ItemDeleted, sAssembly, sClass);
                    oDepartments.Delete();
                }
            }
            catch (Exception ex)
            {
                LogMessage("", ex.Message, 3);
            }

            LogMessage("Mapping Reporting lists.");

            var       reportData = new ReportData(SPSite.ID);
            DataTable dbMappings = reportData.GetDbMappings();

            if (!dbMappings.Select(string.Format("SiteId = '{0}'", SPSite.ID)).Any())
            {
                LogMessage("", "Reporting is not configured.", 2);
            }
            else
            {
                try
                {
                    var reportBiz = new ReportBiz(SPSite.ID, SPSite.WebApplication.Id);

                    reportBiz.GetDatabaseMappings();

                    foreach (var list in new[] { "Work Hours", "Holiday Schedules", "Holidays", "Time Off" })
                    {
                        try
                        {
                            LogMessage("Mapping " + list + " list to Reporting.");

                            SPList spList = SPWeb.Lists[list];

                            ListBiz listBiz = reportBiz.CreateListBiz(spList.ID);

                            if (string.IsNullOrEmpty(listBiz.ListName))
                            {
                                reportBiz.CreateListBiz(spList.ID);
                                LogMessage("", "Mapped successfully.", 1);
                            }
                            else
                            {
                                LogMessage("", "Already mapped.", 2);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogMessage("", ex.Message, 3);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogMessage("", ex.Message, 3);
                }
            }

            return(true);
        }
        public void Teardown(ref SPWeb web)
        {
            var types = Entities;

            //provision lists
            foreach (var iListDefinition in types)
            {
                try
                {
                    SPList list = web.Lists[iListDefinition.ListName];
                    list.Delete();
                    web.Update();
                }
                catch { }
                try
                {
                    SPContentType cType = web.ContentTypes[iListDefinition.Name];
                    if (cType != null)
                    {
                        cType.Delete();
                        web.Update();
                    }
                }
                catch { }
                try
                {
                    SPContentType cType = web.ContentTypes[iListDefinition.ContentTypeId];
                    if (cType != null)
                    {
                        cType.Delete();
                        web.Update();
                    }
                }
                catch { }
                foreach (var iColumn in iListDefinition.Columns)
                {
                    try
                    {
                        SPField field = web.Fields[iColumn.DisplayName];
                        field.Delete();
                    }
                    catch { }
                }
                web.Update();
            }

            List <SPField> deletables = new List <SPField>();

            foreach (SPField iField in web.Fields)
            {
                if (iField.Group == GroupName)
                {
                    deletables.Add(iField);
                }
            }
            foreach (var iField in deletables)
            {
                try
                {
                    iField.Delete();
                }
                catch { }
            }
            web.Update();
        }