Exemplo n.º 1
0
        /// <summary>
        /// Convert to a file node info object.
        /// </summary>
        /// <param name="listItems">The list item collection.</param>
        /// <returns>The file node info's.</returns>
        internal static List <FileNodeInfo> ToFileNodeInfo(this SPListItemCollection listItems)
        {
            List <FileNodeInfo> nodeInfos = new List <FileNodeInfo>();

            foreach (SPListItem listItem in listItems)
            {
                if (listItem.File != null)
                {
                    FileNodeInfo nodeInfo = new FileNodeInfo();

                    nodeInfo.Id                = listItem.ID;
                    nodeInfo.Name              = listItem.File.Name;
                    nodeInfo.UniqueId          = listItem.UniqueId;
                    nodeInfo.FileType          = listItem[SPBuiltInFieldId.File_x0020_Type] as String;
                    nodeInfo.ServerRelativeUrl = listItem.File.ServerRelativeUrl;
                    try
                    {
                        nodeInfo.Title = listItem.Title;
                    }
                    catch (ArgumentException)
                    {
                        nodeInfo.Title = listItem.File.Title;
                    }
                    nodeInfo.IsCheckedOut = listItem.File.Level == SPFileLevel.Checkout;

                    nodeInfos.Add(nodeInfo);
                }
            }

            return(nodeInfos);
        }
        /// <summary>
        /// Nodes the menu items requested.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ExplorerNodeMenuItemsRequestedEventArgs" /> instance containing the event data.</param>
        protected virtual void NodeMenuItemsRequested(object sender, ExplorerNodeMenuItemsRequestedEventArgs e)
        {
            IExplorerNode fileNode = e.Node;
            FileNodeInfo  file     = fileNode.Annotations.GetValue <FileNodeInfo>();

            IMenuItem openFileMenuItem = e.MenuItems.Add(CKSProperties.FileNodeTypeProvider_OpenFile);

            openFileMenuItem.Click += OpenFileMenuItemClick;

            IMenuItem checkOutFileMenuItem = e.MenuItems.Add(CKSProperties.FileNodeTypeProvider_CheckOutFile);

            checkOutFileMenuItem.Click    += CheckOutFileMenuItemClick;
            checkOutFileMenuItem.IsEnabled = file.IsCheckedOut == false;

            IMenuItem checkInFileMenuItem = e.MenuItems.Add(CKSProperties.FileNodeTypeProvider_CheckInFile);

            checkInFileMenuItem.Click    += CheckInFileMenuItemClick;
            checkInFileMenuItem.IsEnabled = file.IsCheckedOut == true;

            IMenuItem discardCheckOutFileMenuItem = e.MenuItems.Add(CKSProperties.FileNodeTypeProvider_DiscardCheckOut);

            discardCheckOutFileMenuItem.Click    += DiscardCheckOutFileMenuItemClick;
            discardCheckOutFileMenuItem.IsEnabled = file.IsCheckedOut == true;

            IMenuItem saveFileMenuItem = e.MenuItems.Add(CKSProperties.FileNodeTypeProvider_SaveFile);

            saveFileMenuItem.Click += SaveFileMenuItemClick;
        }
        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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieves properties that are displayed in the Properties window when
        /// a theme node is selected.
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The ExplorerNodePropertiesRequestedEventArgs object</param>
        protected override void NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
        {
            IExplorerNode themeNode = e.Node;
            FileNodeInfo  theme     = themeNode.Annotations.GetValue <FileNodeInfo>();
            Dictionary <string, string> masterPageProperties = themeNode.Context.SharePointConnection.ExecuteCommand <FileNodeInfo, Dictionary <string, string> >(ThemeSharePointCommandIds.GetThemeProperties, theme);
            object propertySource = themeNode.Context.CreatePropertySourceObject(masterPageProperties);

            e.PropertySources.Add(propertySource);
        }
        /// <summary>
        /// Nodes the properties requested.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ExplorerNodePropertiesRequestedEventArgs" /> instance containing the event data.</param>
        protected override void NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
        {
            IExplorerNode pageLayoutNode           = e.Node;
            FileNodeInfo  pageLayout               = pageLayoutNode.Annotations.GetValue <FileNodeInfo>();
            Dictionary <string, string> properties = pageLayoutNode.Context.SharePointConnection.ExecuteCommand <FileNodeInfo, Dictionary <string, string> >(MasterPageGallerySharePointCommandIds.GetMasterPagesOrPageLayoutPropertiesCommand, pageLayout);
            object propertySource = pageLayoutNode.Context.CreatePropertySourceObject(properties);

            e.PropertySources.Add(propertySource);
        }
        /// <summary>
        /// Nodes the properties requested.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ExplorerNodePropertiesRequestedEventArgs" /> instance containing the event data.</param>
        protected virtual void NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
        {
            IExplorerNode fileNode = e.Node;
            FileNodeInfo  file     = fileNode.Annotations.GetValue <FileNodeInfo>();
            Dictionary <string, string> fileProperties = fileNode.Context.SharePointConnection.ExecuteCommand <FileNodeInfo, Dictionary <string, string> >(FileSharePointCommandIds.GetFilePropertiesCommand, file);
            object propertySource = fileNode.Context.CreatePropertySourceObject(fileProperties);

            e.PropertySources.Add(propertySource);
        }
        /// <summary>
        /// Retrieves properties that are displayed in the Properties window when
        /// a solution node is selected.
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The ExplorerNodePropertiesRequestedEventArgs object</param>
        private void NodePropertiesRequested(object sender, ExplorerNodePropertiesRequestedEventArgs e)
        {
            IExplorerNode solutionNode = e.Node;
            FileNodeInfo  solution     = solutionNode.Annotations.GetValue <FileNodeInfo>();
            Dictionary <string, string> solutionProperties = solutionNode.Context.SharePointConnection.ExecuteCommand <FileNodeInfo, Dictionary <string, string> >(SolutionSharePointCommandIds.GetSolutionProperties, solution);
            object propertySource = solutionNode.Context.CreatePropertySourceObject(solutionProperties);

            e.PropertySources.Add(propertySource);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Export the thmx file.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The MenuItemEventArgs object.</param>
        void ThemeNodeTypeProvider_ExportClick(object sender, MenuItemEventArgs e)
        {
            IMenuItem menuItem = sender as IMenuItem;

            IExplorerNode owner = (IExplorerNode)e.Owner;

            FileNodeInfo info = owner.Annotations.GetValue <FileNodeInfo>();

            if (info != null)
            {
                ProcessUtilities utils = new ProcessUtilities();
                utils.ExecuteBrowserUrlProcess(new Uri(owner.Context.SiteUrl + info.ServerRelativeUrl.TrimStart(@"/".ToCharArray())));
            }
        }
        /// <summary>
        /// Preview the web part on the site.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The MenuItemEventArgs object.</param>
        void WebPartNodeTypeProvider_PreviewClick(object sender, MenuItemEventArgs e)
        {
            IMenuItem menuItem = sender as IMenuItem;

            IExplorerNode owner = (IExplorerNode)e.Owner;

            FileNodeInfo info = owner.Annotations.GetValue <FileNodeInfo>();

            if (info != null)
            {
                ProcessUtilities utils = new ProcessUtilities();
                utils.ExecuteBrowserUrlProcess(new Uri(owner.Context.SiteUrl + String.Format(CKSProperties.WebPartNodeTypeProvider_PreviewUrlMask, info.Id.ToString())));
            }
        }
Exemplo n.º 12
0
        private static string GetFileContents(ISharePointCommandContext context, FileNodeInfo fileNodeInfo)
        {
            string fileContents = null;

            try
            {
                SPFile f = context.Web.GetFile(fileNodeInfo.ServerRelativeUrl);
                fileContents = Encoding.UTF8.GetString(f.OpenBinary());
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.FileSharePointCommands_GetContentsException,
                                                       fileNodeInfo.ServerRelativeUrl,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(fileContents);
        }
Exemplo n.º 13
0
        private static bool SaveFile(ISharePointCommandContext context, FileNodeInfo fileNodeInfo)
        {
            bool result = false;

            try
            {
                SPFile f = context.Web.GetFile(fileNodeInfo.ServerRelativeUrl);
                f.SaveBinary(Encoding.UTF8.GetBytes(fileNodeInfo.Contents));
                result = true;
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.FileSharePointCommands_SaveException,
                                                       fileNodeInfo.ServerRelativeUrl,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(result);
        }
Exemplo n.º 14
0
        internal static List <FileNodeInfo> ToFileNodeInfo(this SPFileCollection files)
        {
            List <FileNodeInfo> nodeInfos = new List <FileNodeInfo>();

            foreach (SPFile file in files)
            {
                FileNodeInfo nodeInfo = new FileNodeInfo
                {
                    Id                = file.Item.ID,
                    Name              = file.Name,
                    UniqueId          = file.Item.UniqueId,
                    FileType          = file.Item[SPBuiltInFieldId.File_x0020_Type] as string,
                    ServerRelativeUrl = file.ServerRelativeUrl,
                    Title             = file.Item.Title,
                    IsCheckedOut      = file.Level == SPFileLevel.Checkout
                };
                nodeInfos.Add(nodeInfo);
            }

            return(nodeInfos);
        }
Exemplo n.º 15
0
        private static bool CheckInFile(ISharePointCommandContext context, FileNodeInfo fileNodeInfo)
        {
            bool result = false;

            try
            {
                SPFile f = context.Web.GetFile(fileNodeInfo.ServerRelativeUrl);
                f.CheckIn(String.Empty);
                result = true;
            }
            catch (Exception ex)
            {
                context.Logger.WriteLine(String.Format(Resources.FileSharePointCommands_CheckInException,
                                                       fileNodeInfo.ServerRelativeUrl,
                                                       ex.Message,
                                                       Environment.NewLine,
                                                       ex.StackTrace), LogCategory.Error);
            }

            return(result);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        private static Dictionary <string, string> GetMasterPageOrPageLayoutProperties(ISharePointCommandContext context, FileNodeInfo fileNodeInfo)
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            try
            {
                SPList     masterPageGallery      = context.Web.GetCatalog(SPListTemplateType.MasterPageCatalog);
                SPListItem masterPageOrPageLayout = masterPageGallery.Items[fileNodeInfo.UniqueId];

                properties = SharePointCommandServices.GetProperties(masterPageOrPageLayout);
            }
            catch { }

            return(properties);
        }
        /// <summary>
        /// Sets the explorer node icon.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="fileNode">The file node.</param>
        private static void SetExplorerNodeIcon(FileNodeInfo file, IExplorerNode fileNode)
        {
            string extension = Path.GetExtension(file.Name.ToLower()).TrimStart('.');

            if (file.IsCheckedOut)
            {
                switch (extension)
                {
                case "css":
                    fileNode.Icon = CKSProperties.co_iccss.ToBitmap();
                    break;

                case "gif":
                case "jpg":
                case "jpeg":
                    fileNode.Icon = CKSProperties.co_icjpg.ToBitmap();
                    break;

                case "js":
                    fileNode.Icon = CKSProperties.co_icjs.ToBitmap();
                    break;

                case "png":
                    fileNode.Icon = CKSProperties.co_icpng.ToBitmap();
                    break;

                case "xsl":
                    fileNode.Icon = CKSProperties.co_icxsl.ToBitmap();
                    break;

                case "xaml":
                    fileNode.Icon = CKSProperties.co_icxaml.ToBitmap();
                    break;

                default:
                    fileNode.Icon = CKSProperties.co_icgen.ToBitmap();
                    break;
                }
            }
            else
            {
                switch (extension)
                {
                case "css":
                    fileNode.Icon = CKSProperties.iccss.ToBitmap();
                    break;

                case "gif":
                case "jpg":
                case "jpeg":
                    fileNode.Icon = CKSProperties.icjpg.ToBitmap();
                    break;

                case "js":
                    fileNode.Icon = CKSProperties.icjs.ToBitmap();
                    break;

                case "png":
                    fileNode.Icon = CKSProperties.icpng.ToBitmap();
                    break;

                case "xsl":
                    fileNode.Icon = CKSProperties.icxsl.ToBitmap();
                    break;

                case "xaml":
                    fileNode.Icon = CKSProperties.icxaml.ToBitmap();
                    break;

                default:
                    fileNode.Icon = CKSProperties.icgen.ToBitmap();
                    break;
                }
            }
        }