private static Dictionary <string, string> GetWebTemplateProperties(ISharePointCommandContext context,
                                                                            WebTemplateInfo nodeInfo)
        {
            SPWebTemplate template = context.Web.GetAvailableWebTemplates((uint)context.Web.Locale.LCID, true)[nodeInfo.Name];

            return(SharePointCommandServices.GetProperties(template));
        }
示例#2
0
        private static void SetDeveloperDashBoardDisplayLevelSetting(ISharePointCommandContext context, string newLevel)
        {
            try
            {
                SPDeveloperDashboardLevel level = ((SPDeveloperDashboardLevel)Enum.Parse(typeof(SPDeveloperDashboardLevel), newLevel));

                SPDeveloperDashboardSettings settings = context.Site.WebApplication.WebService.DeveloperDashboardSettings;

                settings.DisplayLevel = level;

                settings.Update(true);
            }
            catch (ArgumentNullException ex)
            {
                context.Logger.WriteLine(String.Format(Resources.DeveloperDashboardCommands_SetException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }
            catch (ArgumentException ex)
            {
                context.Logger.WriteLine(String.Format(Resources.DeveloperDashboardCommands_SetException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }
            catch (OverflowException ex)
            {
                context.Logger.WriteLine(String.Format(Resources.DeveloperDashboardCommands_SetException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }
        }
        private static WebTemplateInfo[] GetWebTemplates(ISharePointCommandContext context)
        {
            context.Logger.WriteLine(Resources.WebTemplateSharePointCommands_TryingToRetrieveAvailableWebTemplates, LogCategory.Status);

            List <WebTemplateInfo> webTemplateInfos = new List <WebTemplateInfo>();

            try
            {
                SPSite caSite  = null;
                SPWeb  rootWeb = null;

                if (context.Site == null)
                {
                    //Do this as from item templates the site is always null
                    SPAdministrationWebApplication caWebApp = SPAdministrationWebApplication.Local;
                    caSite  = caWebApp.Sites[0];
                    rootWeb = caSite.RootWeb;
                }
                else
                {
                    caSite  = context.Site;
                    rootWeb = context.Web;
                }

                SPWebTemplateCollection webTemplates = caSite.GetWebTemplates((uint)rootWeb.Locale.LCID);

                foreach (SPWebTemplate item in webTemplates)
                {
                    //Check the temaplate is a site defintion and has a display category
                    if (!String.IsNullOrEmpty(item.DisplayCategory) && !item.IsCustomTemplate)
                    {
                        WebTemplateInfo info = new WebTemplateInfo();

                        info.Id               = item.ID;
                        info.ImageUrl         = item.ImageUrl;
                        info.Name             = item.Name;
                        info.Description      = item.Description;
                        info.DisplayCategory  = item.DisplayCategory;
                        info.IsCustomTemplate = item.IsCustomTemplate;
                        info.IsHidden         = item.IsHidden;
                        info.IsRootWebOnly    = item.IsRootWebOnly;
                        info.IsSubWebOnly     = item.IsSubWebOnly;
                        info.Lcid             = item.Lcid;
                        info.Title            = item.Title;
                        info.SetupPath        = typeof(SPWebTemplate).InvokeMember("SetupPath", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty, null, item, null) as string;

                        webTemplateInfos.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.WebTemplateSharePointCommands_RetrievingException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(webTemplateInfos.ToArray());
        }
示例#4
0
        private string GetWebApplicationDefaultPhysicalPath(ISharePointCommandContext context, string url)
        {
            string name = null;

            try
            {
                using (SPSite site = new SPSite(url))
                {
                    SPWebApplication app = site.WebApplication;

                    if (app.IisSettings.ContainsKey(SPUrlZone.Default))
                    {
                        name = app.IisSettings[SPUrlZone.Default].Path.FullName;
                    }
                    else
                    {
                        foreach (SPUrlZone zone in app.IisSettings.Keys)
                        {
                            name = app.IisSettings[zone].Path.FullName;
                            break;
                        }
                    }
                }
            }
            catch
            {
            }

            return(name);
        }
        private static string[] GetWebTemplateCategories(ISharePointCommandContext context)
        {
            context.Logger.WriteLine(Resources.WebTemplateSharePointCommands_TryingToRetrieveAvailableCategories, LogCategory.Status);

            List <string> categories = new List <string>();

            try
            {
                SPWebTemplateCollection webTemplates = context.Web.GetAvailableWebTemplates((uint)context.Web.Locale.LCID, true);

                foreach (SPWebTemplate item in webTemplates)
                {
                    if (!categories.Contains(item.DisplayCategory))
                    {
                        categories.Add(item.DisplayCategory);
                    }
                }
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.WebTemplateSharePointCommands_CategoriesRetrievingException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(categories.ToArray());
        }
        private static FileNodeInfo[] GetThemes(ISharePointCommandContext context)
        {
            List <FileNodeInfo> nodeInfos = new List <FileNodeInfo>();

            try
            {
                context.Logger.WriteLine(Resources.ThemeGallerySharePointCommands_TryingToRetrieveAvailableThemes, LogCategory.Status);

                SPListItemCollection themes = context.Web.GetCatalog(SPListTemplateType.ThemeCatalog).GetItems(
                    new SPQuery
                {
                    ViewXml = "<View />"
                }
                    );
                nodeInfos = themes.ToFileNodeInfo();

                context.Logger.WriteLine(Resources.ThemeGallerySharePointCommands_RetrievingException, LogCategory.Status);
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.ThemeGallerySharePointCommands_RetrievingException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(nodeInfos.ToArray());
        }
示例#7
0
        private static FolderNodeInfo[] GetFolders(ISharePointCommandContext context, FolderNodeInfo folderNodeInfo)
        {
            List <FolderNodeInfo> nodeInfos = new List <FolderNodeInfo>();

            try
            {
                SPList   styleLibrary = context.Web.GetList(Utilities.CombineUrl(context.Web.ServerRelativeUrl, "Style%20Library"));
                SPFolder folder       = styleLibrary.RootFolder;
                if (folderNodeInfo != null)
                {
                    folder = context.Web.GetFolder(folderNodeInfo.Url);
                }

                SPFolderCollection subfolders = folder.SubFolders;
                if (subfolders != null)
                {
                    nodeInfos = subfolders.ToFolderNodeInfo();
                }
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.FileSharePointCommands_RetrieveFoldersException,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(nodeInfos.ToArray());
        }
        private Dictionary <string, string> GetListEventReceiverProperties(ISharePointCommandContext context, EventReceiverInfo eventReceiverInfo)
        {
            SPEventReceiverDefinition   eventReceiver           = null;
            Dictionary <string, string> eventReceiverProperties = new Dictionary <string, string>();

            SPList list = context.Web.Lists[eventReceiverInfo.ListId];

            if (eventReceiverInfo.Id != Guid.Empty)
            {
                eventReceiver = list.EventReceivers[eventReceiverInfo.Id];
            }
            else if (!String.IsNullOrEmpty(eventReceiverInfo.Name))
            {
                eventReceiver = (from SPEventReceiverDefinition er in list.EventReceivers
                                 where er.Name.Equals(eventReceiverInfo.Name)
                                 select er).FirstOrDefault();
            }
            else
            {
                eventReceiver = (from SPEventReceiverDefinition er in list.EventReceivers
                                 where er.Assembly == eventReceiverInfo.Assembly &&
                                 er.Class == eventReceiverInfo.Class &&
                                 (int)er.Type == eventReceiverInfo.EventType
                                 select er).FirstOrDefault();
            }

            if (eventReceiver != null)
            {
                eventReceiverProperties = SharePointCommandServices.GetProperties(eventReceiver);
            }

            return(eventReceiverProperties);
        }
        private static Dictionary <string, string> GetSolutionProperties(ISharePointCommandContext context,
                                                                         FileNodeInfo nodeInfo)
        {
            SPList     solutions = context.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
            SPListItem solution  = solutions.Items[nodeInfo.UniqueId];

            return(SharePointCommandServices.GetProperties(solution));
        }
        private static Dictionary <string, string> GetWebPartProperties(ISharePointCommandContext context,
                                                                        FileNodeInfo nodeInfo)
        {
            SPList     webParts = context.Site.GetCatalog(SPListTemplateType.WebPartCatalog);
            SPListItem webPart  = webParts.Items[nodeInfo.UniqueId];

            return(SharePointCommandServices.GetProperties(webPart));
        }
示例#11
0
        private static Dictionary <string, string> GetThemeProperties(ISharePointCommandContext context,
                                                                      FileNodeInfo nodeInfo)
        {
            SPList     themes = context.Site.GetCatalog(SPListTemplateType.ThemeCatalog);
            SPListItem theme  = themes.Items[nodeInfo.UniqueId];

            return(SharePointCommandServices.GetProperties(theme));
        }
示例#12
0
        public static void UpgradeSolution(ISharePointCommandContext context, SolutionInfo solutionInfo)
        {
            SPSolution solution = SPFarm.Local.Solutions[solutionInfo.Name];

            //Do not use this version as it causes SP to return success prior to timer execution so VS falselt notifies the user it is completed. https://cksdev.codeplex.com/workitem/9027
            //solution.Upgrade(solutionInfo.LocalPath, DateTime.Now);

            solution.Upgrade(solutionInfo.LocalPath);
        }
        private static string GetFullSPRootFolderPath(ISharePointCommandContext context,
                                                      string folderName)
        {
            string sharePointSetupPath = String.Empty;

            sharePointSetupPath = SPUtility.GetVersionedGenericSetupPath(folderName, 15);

            return(sharePointSetupPath);
        }
        public static string GetWebPartDefinition(ISharePointCommandContext context, WebPartNodeInfo nodeInfo)
        {
            SPList     webParts = context.Site.GetCatalog(SPListTemplateType.WebPartCatalog);
            SPListItem webPart  = webParts.Items[nodeInfo.UniqueId];

            using (StreamReader reader = new StreamReader(webPart.File.OpenBinaryStream(SPOpenBinaryOptions.None)))
            {
                return(reader.ReadToEnd());
            }
        }
示例#15
0
        private static bool IsPublishingContentType(ISharePointCommandContext context, string contentTypeName)
        {
            bool isPublishingContentType = false;

            SPContentType contentType = context.Web.ContentTypes[contentTypeName];

            isPublishingContentType = contentType.Id.IsChildOf(ContentTypeId.Page);

            return(isPublishingContentType);
        }
示例#16
0
        private static string GetContentTypeID(ISharePointCommandContext context, string name)
        {
            SPContentType type = context.Web.AvailableContentTypes[name];

            if (type == null)
            {
                context.Logger.WriteLine(String.Format(Resources.ContentTypeSharePointCommands_GetContentTypeIDException, name), LogCategory.Error);
                return(String.Empty);
            }
            return(type.Id.ToString());
        }
        public static Dictionary <string, string> GetProperties(ISharePointCommandContext context, FieldNodeInfo field)
        {
            Dictionary <string, string> properties = null;

            if (field.Id != Guid.Empty)
            {
                properties = SharePointCommandServices.GetProperties(context.Site.RootWeb.Fields[field.Id]);
            }

            return(properties);
        }
        private static string[] GetSiteColumnsGroups(ISharePointCommandContext context)
        {
            SPFieldCollection    fields = context.Site.RootWeb.Fields;
            IEnumerable <string> allSiteColumnsGroups = (from SPField field
                                                         in fields
                                                         select field.Group);

            string[] siteColumnsGroups = allSiteColumnsGroups.Distinct().ToArray();

            return(siteColumnsGroups);
        }
        private void UpgradeSolution(ISharePointCommandContext context, string fullWspPath)
        {
            SPSolution solution = SPFarm.Local.Solutions[Path.GetFileName(fullWspPath)];

            if (solution == null)
            {
                throw new InvalidOperationException("The solution has not been deployed.");
            }

            solution.Upgrade(fullWspPath);
        }
示例#20
0
        private static string[] GetContentTypeGroups(ISharePointCommandContext context)
        {
            SPContentTypeCollection contentTypes         = context.Web.AvailableContentTypes;
            IEnumerable <string>    allContentTypeGroups = (from SPContentType contentType
                                                            in contentTypes
                                                            select contentType.Group);

            string[] contentTypeGroups = allContentTypeGroups.Distinct().ToArray();

            return(contentTypeGroups);
        }
        public static string GetElementDefinition(ISharePointCommandContext context,
                                                  FeatureElementInfo elementInfo)
        {
            SPFeatureDefinition definition = SPFarm.Local.FeatureDefinitions[elementInfo.FeatureID];
            SPElementDefinition element    = definition.GetElementDefinitions(CultureInfo.CurrentCulture)
                                             .OfType <SPElementDefinition>()
                                             .Where(searchElement => searchElement.ElementType == elementInfo.ElementType)
                                             .Where(searchElement => GetNameFromNode(searchElement.XmlDefinition) == elementInfo.Name)
                                             .FirstOrDefault();

            return(element.XmlDefinition.OuterXml);
        }
示例#22
0
        public static string[] GetWebApplicationPhysicalPaths(ISharePointCommandContext context)
        {
            List <string> folders = new List <string>();

            SPWebApplication webApp = context.Site.WebApplication;

            foreach (KeyValuePair <SPUrlZone, SPIisSettings> iisSettingsByZone in webApp.IisSettings)
            {
                folders.Add(iisSettingsByZone.Value.Path.FullName);
            }
            return(folders.ToArray());
        }
示例#23
0
        private static ContentTypeNodeInfo[] GetContentTypesFromGroup(ISharePointCommandContext context, string groupName)
        {
            SPContentTypeCollection contentTypes = context.Web.AvailableContentTypes;

            ContentTypeNodeInfo[] contentTypesFromGroup = (from SPContentType contentType
                                                           in contentTypes
                                                           where contentType.Group == groupName
                                                           select new ContentTypeNodeInfo {
                Name = contentType.Name
            }).ToArray();

            return(contentTypesFromGroup);
        }
        private static string ExportToXml(ISharePointCommandContext context, PublishingPageInfo pageInfo)
        {
            string pageXml = null;

            PublishingWeb  publishingWeb = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPage page          = publishingWeb.GetPublishingPage(pageInfo.ServerRelativeUrl);

            if (page != null)
            {
                pageXml = ExportPublishingPage(page, context.Web, context).ToString();
            }

            return(pageXml);
        }
示例#25
0
        private string[] GetAllApplicationPoolNames(ISharePointCommandContext context)
        {
            List <string> names = new List <string>();

            foreach (SPWebApplication app in SPWebService.ContentService.WebApplications.Union(SPWebService.AdministrationService.WebApplications))
            {
                if (!names.Contains(app.ApplicationPool.Name))
                {
                    names.Add(app.ApplicationPool.Name);
                }
            }

            return(names.ToArray());
        }
        private static Dictionary <string, string> GetProperties(ISharePointCommandContext context, PublishingPageInfo pageInfo)
        {
            Dictionary <string, string> pageProperties = new Dictionary <string, string>();

            PublishingWeb  publishingWeb = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPage page          = publishingWeb.GetPublishingPage(pageInfo.ServerRelativeUrl);

            if (page != null)
            {
                pageProperties = SharePointCommandServices.GetProperties(page);
            }

            return(pageProperties);
        }
示例#27
0
        private string GetApplicationPoolName(ISharePointCommandContext context, string url)
        {
            string applicationPoolName = null;

            try {
                using (SPSite site = new SPSite(url)) {
                    applicationPoolName = site.WebApplication.ApplicationPool.Name;
                }
            }
            catch {
            }

            return(applicationPoolName);
        }
        public static Dictionary <string, string> GetProperties(ISharePointCommandContext context, FieldNodeInfo field)
        {
            Dictionary <string, string> properties = null;

            if (field.ListId == Guid.Empty)
            {
                properties = SharePointCommandServices.GetProperties(context.Web.AvailableContentTypes[field.ContentTypeName].Fields[field.Id]);
            }
            else
            {
                properties = SharePointCommandServices.GetProperties(context.Web.Lists[field.ListId].Fields[field.Id]);
            }

            return(properties);
        }
示例#29
0
        public static void CopyAppBinContent(ISharePointCommandContext context)
        {
            SPServiceInstance localContent = SPWebServiceInstance.LocalContent;

            if ((localContent != null) && (localContent.Status == SPObjectStatus.Online))
            {
                SPWebService.ContentService.ApplyApplicationContentToLocalServer();
            }

            localContent = SPWebServiceInstance.LocalAdministration;
            if ((localContent != null) && (localContent.Status == SPObjectStatus.Online))
            {
                SPWebService.AdministrationService.ApplyApplicationContentToLocalServer();
            }
        }
示例#30
0
        private static Dictionary <string, string> GetFileProperties(ISharePointCommandContext context, FileNodeInfo fileNodeInfo)
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            try
            {
                SPFile file = context.Web.GetFile(fileNodeInfo.ServerRelativeUrl);
                if (file != null)
                {
                    properties = SharePointCommandServices.GetProperties(file.Item);
                }
            }
            catch { }

            return(properties);
        }
        public static string GetListInstanceXml(ISharePointCommandContext context, Guid listId)
        {
            string listInstanceXml = String.Empty;

            context.Logger.WriteLine("Exporting List Instance...", LogCategory.Status);

            SPWeb web = context.Web;
            SPList list = web.Lists[listId];

            XElement xListInstance = new XElement("ListInstance",
                new XAttribute("Title", list.Title),
                new XAttribute("Description", list.Description),
                new XAttribute("Url", list.RootFolder.Url),
                new XAttribute("TemplateType", (int)list.BaseTemplate),
                new XAttribute("FeatureId", list.TemplateFeatureId),
                new XAttribute("OnQuickLaunch", list.OnQuickLaunch.ToString().ToUpper()));

            SPListItemCollection items = list.Items;

            if (items.Count > 0) {
                XElement xData = new XElement("Data");
                XElement xRows = new XElement("Rows");

                foreach (SPListItem item in items) {
                    XElement xRow = new XElement("Row");
                    foreach (SPField field in item.Fields) {
                        try {
                            string fieldValue = null;
                            object fieldValueRaw = null;

                            try {
                                fieldValueRaw = item[field.Id];
                            }
                            catch { }

                            if (fieldValueRaw != null) {
                                if (field.FieldValueType == typeof(DateTime)) {
                                    DateTime dateTime = (DateTime)fieldValueRaw;
                                    fieldValue = dateTime.ToUniversalTime().ToString(context.Web.Locale);
                                }
                                else if (field.FieldValueType == typeof(Boolean)) {
                                    fieldValue = (bool)fieldValueRaw ? "1" : "0";
                                }
                                else {
                                    fieldValue = fieldValueRaw.ToString();
                                }
                            }

                            if (!String.IsNullOrEmpty(fieldValue)) {
                                XElement xField = new XElement("Field",
                                    new XAttribute("Name", field.InternalName),
                                    fieldValue);
                                xRow.Add(xField);
                                context.Logger.WriteLine(String.Format("Exported Field: {0}; Value: {1}", field.InternalName, fieldValue), LogCategory.Verbose);
                            }
                        }
                        catch (Exception ex) {
                            context.Logger.WriteLine(String.Format("Exception while exporting field '{0}': {1}", field.InternalName, ex.StackTrace), LogCategory.Error);
                        }
                    }

                    xRows.Add(xRow);
                }

                xData.Add(xRows);
                xListInstance.Add(xData);
            }

            listInstanceXml = xListInstance.ToString();

            context.Logger.WriteLine("List Instance successfully exported", LogCategory.Status);

            return listInstanceXml;
        }