/// <summary>
        /// Imports the type of the content.
        /// </summary>
        /// <param name="contentTypeInfo">The content type info.</param>
        public static void ImportContentType(ContentTypeInfo contentTypeInfo)
        {
            if (contentTypeInfo != null)
            {
                //Create the encoding definition
                XDeclaration declaration = new XDeclaration("1.0", Encoding.UTF8.WebName, null);

                XNamespace sharepointToolsNamespace = @"http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel";
                XNamespace sharepointNamespace      = @"http://schemas.microsoft.com/sharepoint/";

                XElement elementsFileContents = XElement.Parse(BuildElements(contentTypeInfo, declaration, sharepointNamespace));

                EnvDTE.Project activeProject = DTEManager.ActiveProject;

                if (activeProject != null)
                {
                    ISharePointProjectService projectService          = DTEManager.ProjectService;
                    ISharePointProject        activeSharePointProject = DTEManager.ActiveSharePointProject;

                    if (activeSharePointProject != null)
                    {
                        ISharePointProjectItem contentTypeProjectItem = activeSharePointProject.ProjectItems.Add(contentTypeInfo.Name, "Microsoft.VisualStudio.SharePoint.ContentType");
                        System.IO.File.WriteAllText(Path.Combine(contentTypeProjectItem.FullPath, "Elements.xml"), elementsFileContents.ToString().Replace("xmlns=\"\"", String.Empty));

                        ISharePointProjectItemFile elementsXml = contentTypeProjectItem.Files.AddFromFile("Elements.xml");
                        elementsXml.DeploymentType = DeploymentType.ElementManifest;
                        elementsXml.DeploymentPath = String.Format(@"{0}\", contentTypeInfo.Name);

                        contentTypeProjectItem.DefaultFile = elementsXml;
                    }
                }
            }
        }
Esempio n. 2
0
        private void ProjectItemNameChanged(object sender, NameChangedEventArgs e)
        {
            ISharePointProjectItem projectItem = (ISharePointProjectItem)sender;
            string message = String.Format("The name of the {0} item changed to: {1}",
                                           e.OldName, projectItem.Name);

            projectService.Logger.WriteLine(message, LogCategory.Message);
        }
        //</Snippet3>

        void MenuItemExtension_Click(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem projectItem = (ISharePointProjectItem)e.Owner;

            projectItem.Project.ProjectService.Logger.WriteLine(
                String.Format("This message was written from a shortcut menu for {0}.", projectItem.Name),
                LogCategory.Status);
        }
Esempio n. 4
0
        void projectItemType_ProjectItemAdded(object sender, SharePointProjectItemEventArgs e)
        {
            ISharePointProjectItem projectItem = (ISharePointProjectItem)sender;
            string message = String.Format("An Event Handler project item named {0} was added to the {1} project.",
                                           projectItem.Name, projectItem.Project.Name);

            projectItem.Project.ProjectService.Logger.WriteLine(message, LogCategory.Message);
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SPMetalDefinitionProperties"/> class.
 /// </summary>
 /// <param name="definition">The definition.</param>
 /// <param name="owner">The owner.</param>
 /// <param name="properties">The CKSProperties.</param>
 public SPMetalDefinitionProperties(SPMetalDefinitionTypeProvider definition,
                                    ISharePointProjectItem owner,
                                    IDictionary <string, string> properties)
 {
     _owner      = owner;
     _properties = properties;
     _definition = definition;
 }
Esempio n. 6
0
        private void MenuItemClick(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem projectItem = (ISharePointProjectItem)e.Owner;
            string message = String.Format("You clicked the menu on the {0} item. " +
                                           "You could perform some related task here, such as displaying a designer " +
                                           "for the custom action.", projectItem.Name);

            System.Windows.Forms.MessageBox.Show(message, "Contoso Custom Action");
        }
        /// <summary>
        /// Handles the Click event of the removeFromAllReferencesMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.SharePoint.MenuItemEventArgs"/> instance containing the event data.</param>
        void removeFromAllReferencesMenuItem_Click(object sender,
                                                   MenuItemEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to remove this project item from all Features and Packages?", "Remove from all Features and Packages", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                ISharePointProjectItem spi = e.Owner as ISharePointProjectItem;

                if (spi != null)
                {
                    ISharePointProjectLogger logger = spi.Project.ProjectService.Logger;
                    logger.ClearErrorList();
                    logger.ActivateOutputWindow();
                    logger.WriteLine(String.Format("Removing SharePoint Project Item '{0}' from Packages and Features...", spi.Name), LogCategory.Status);

                    var projects = spi.Project.ProjectService.Projects;

                    foreach (var project in projects)
                    {
                        ISharePointProjectItem spiInPackage = null;
                        foreach (ISharePointProjectItem s in project.Package.ProjectItems)
                        {
                            if (s.Id == spi.Id)
                            {
                                spiInPackage = s;
                                break;
                            }
                        }

                        if (spiInPackage != null)
                        {
                            project.Package.ProjectItems.Remove(spiInPackage);
                            logger.WriteLine(String.Format("SharePoint Project Item '{0}' removed from Package '{1}'", spi.Name, project.Package.Model.Name), LogCategory.Message, project.Package.PackageFile.FullPath, 1, 1);
                        }

                        foreach (var feature in project.Features)
                        {
                            ISharePointProjectItem spiInFeature = null;
                            foreach (var s in feature.ProjectItems)
                            {
                                if (s.Id == spi.Id)
                                {
                                    spiInFeature = s;
                                    break;
                                }
                            }

                            if (spiInFeature != null)
                            {
                                feature.ProjectItems.Remove(spiInFeature);
                                logger.WriteLine(String.Format("SharePoint Project Item '{0}' removed from Feature '{1}'", spi.Name, feature.Model.Title), LogCategory.Message, feature.FeatureFile.FullPath, 1, 1);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Forces the regenerate the SPMetal designer file.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="properties">The properties for the SPMetal definition.</param>
        internal void ForceRegenerate(ISharePointProjectItem owner, SPMetalDefinitionProperties properties)
        {
            owner.Annotations.Remove <SPMetalDefinitionProperties>();
            owner.Annotations.Add <SPMetalDefinitionProperties>(properties);

            ProjectItem   dteItem = owner.Project.ProjectService.Convert <ISharePointProjectItemFile, ProjectItem>(owner.DefaultFile);
            VSProjectItem vp      = (VSProjectItem)dteItem.Object;

            vp.RunCustomTool();
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FeaturesViewerForm"/> class.
        /// </summary>
        /// <param name="spi">The spi.</param>
        public FeaturesViewerForm(ISharePointProjectItem spi)
        {
            if (spi == null)
            {
                throw new ArgumentNullException("spi");
            }

            InitializeComponent();
            LoadProjects(spi.Project);
            LoadFeatures(spi);
            FilterFeaturesList();
        }
Esempio n. 10
0
        /// <summary>
        /// Imports the field.
        /// </summary>
        /// <param name="fieldNode">The field node.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static void ImportField(IExplorerNode fieldNode)
        {
            if (fieldNode == null)
            {
                throw new ArgumentNullException("fieldNode");
            }

            Microsoft.VisualStudio.SharePoint.Explorer.Extensions.IFieldNodeInfo nodeInfo = fieldNode.Annotations.GetValue <Microsoft.VisualStudio.SharePoint.Explorer.Extensions.IFieldNodeInfo>();
            if (nodeInfo != null)
            {
                FieldNodeInfo fieldNodeInfo = new FieldNodeInfo
                {
                    ContentTypeName = nodeInfo.ContentTypeName,
                    Id       = nodeInfo.Id,
                    IsHidden = nodeInfo.IsHidden,
                    ListId   = nodeInfo.ListId,
                    Title    = nodeInfo.Title
                };
                Dictionary <string, string> fieldProperties = null;

                if (String.IsNullOrEmpty(fieldNodeInfo.ContentTypeName) && fieldNodeInfo.ListId == Guid.Empty)
                {
                    fieldProperties = fieldNode.Context.SharePointConnection.ExecuteCommand <FieldNodeInfo, Dictionary <string, string> >(SiteColumnsSharePointCommandIds.GetProperties, fieldNodeInfo);
                }
                else
                {
                    fieldProperties = fieldNode.Context.SharePointConnection.ExecuteCommand <FieldNodeInfo, Dictionary <string, string> >(FieldSharePointCommandIds.GetProperties, fieldNodeInfo);
                }

                if (fieldProperties != null)
                {
                    XNamespace xn        = XNamespace.Get("http://schemas.microsoft.com/sharepoint/");
                    XElement   xElements = new XElement(xn + "Elements",
                                                        XElement.Parse(fieldProperties["SchemaXml"]));

                    EnvDTE.Project activeProject = DTEManager.ActiveProject;
                    if (activeProject != null)
                    {
                        ISharePointProjectService projectService          = fieldNode.ServiceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService;
                        ISharePointProject        activeSharePointProject = projectService.Projects[activeProject.FullName];
                        if (activeSharePointProject != null)
                        {
                            ISharePointProjectItem fieldProjectItem = activeSharePointProject.ProjectItems.Add(fieldProperties["InternalName"], "Microsoft.VisualStudio.SharePoint.Field");
                            System.IO.File.WriteAllText(Path.Combine(fieldProjectItem.FullPath, "Elements.xml"), xElements.ToString().Replace("xmlns=\"\"", String.Empty));
                            ISharePointProjectItemFile elementsXml = fieldProjectItem.Files.AddFromFile("Elements.xml");
                            elementsXml.DeploymentType   = DeploymentType.ElementManifest;
                            elementsXml.DeploymentPath   = String.Format(@"{0}\", fieldProperties["InternalName"]);
                            fieldProjectItem.DefaultFile = elementsXml;
                        }
                    }
                }
            }
        }
Esempio n. 11
0
 public void ValidateProjectItem(
     IFeatureValidationContext context,
     ISharePointProjectItem projectItem)
 {
     if (projectItem.Name == "")
     {
         context.RuleViolations.Add(
             "CustomFeatureValidationRule001",
             ValidationRuleViolationSeverity.Warning,
             "SharePoint project items must have a name.");
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Determines if this SPI is included inside a feature that is packaged in any project in the solution.
        /// </summary>
        /// <param name="item">The ISharePointProjectItem being extended.</param>
        /// <param name="service">The sharepoint project service.</param>
        /// <returns>Returns true if this SPI is included inside a feature that is packaged in any project in the solution.</returns>
        public static bool IsPartOfAnyPackagedProjectFeature(this ISharePointProjectItem item, ISharePointProjectService service)
        {
            foreach (ISharePointProject project in service.Projects)
            {
                if (item.IsPartOfPackagedProjectFeature(project))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 13
0
        /// <summary>
        /// Gets all features in the given project whether packaged or not that contain this SPI.
        /// </summary>
        /// <param name="item">The ISharePointProjectItem being extended.</param>
        /// <param name="project">The current project.</param>
        /// <returns>Returns all features in the given project.</returns>
        public static List <ISharePointProjectFeature> ParentFeaturesInProject(this ISharePointProjectItem item, ISharePointProject project)
        {
            List <ISharePointProjectFeature> features = new List <ISharePointProjectFeature>();

            features.AddRange(
                from feature
                in project.Features
                where feature.ProjectItems.Contains(item)
                select feature
                );
            return(features);
        }
        void ImportListInstanceExplorerExtension_Click(object sender, MenuItemEventArgs e)
        {
            IExplorerNode listNode = e.Owner as IExplorerNode;

            if (listNode != null)
            {
                try {
                    IListNodeInfo listInfo = listNode.Annotations.GetValue <IListNodeInfo>();

                    string     listInstanceContents = listNode.Context.SharePointConnection.ExecuteCommand <Guid, string>(CommandIds.GetListInstanceXmlCommandId, listInfo.Id);
                    XNamespace xn             = "http://schemas.microsoft.com/sharepoint/";
                    string     moduleContents = new XElement(xn + "Elements",
                                                             XElement.Parse(listInstanceContents)).ToString().Replace(" xmlns=\"\"", String.Empty);

                    EnvDTE.Project activeProject = Utils.GetActiveProject();
                    if (activeProject != null)
                    {
                        ISharePointProjectService projectService          = listNode.ServiceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService;
                        ISharePointProject        activeSharePointProject = projectService.Projects[activeProject.FullName];
                        if (activeSharePointProject != null)
                        {
                            string spiName = listInfo.Title;
                            ISharePointProjectItem listInstanceProjectItem = null;
                            bool itemCreated = false;
                            int  counter     = 0;

                            do
                            {
                                try {
                                    listInstanceProjectItem = activeSharePointProject.ProjectItems.Add(spiName, "Microsoft.VisualStudio.SharePoint.ListInstance");
                                    itemCreated             = true;
                                }
                                catch (ArgumentException) {
                                    spiName = String.Format("{0}{1}", listInfo.Title, ++counter);
                                }
                            }while (!itemCreated);

                            string elementsXmlFullPath = Path.Combine(listInstanceProjectItem.FullPath, "Elements.xml");
                            System.IO.File.WriteAllText(elementsXmlFullPath, moduleContents);
                            ISharePointProjectItemFile elementsXml = listInstanceProjectItem.Files.AddFromFile("Elements.xml");
                            elementsXml.DeploymentType          = DeploymentType.ElementManifest;
                            elementsXml.DeploymentPath          = String.Format(@"{0}\", spiName);
                            listInstanceProjectItem.DefaultFile = elementsXml;

                            Utils.OpenFile(Path.Combine(elementsXmlFullPath));
                        }
                    }
                }
                catch (Exception ex) {
                    listNode.Context.ShowMessageBox(String.Format("The following exception occured while exporting List Instance: {0}", ex.Message), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the findAllReferencesMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.SharePoint.MenuItemEventArgs"/> instance containing the event data.</param>
        void findAllReferencesMenuItem_Click(object sender,
                                             MenuItemEventArgs e)
        {
            ISharePointProjectItem spi = e.Owner as ISharePointProjectItem;

            if (spi != null)
            {
                ISharePointProjectLogger logger = spi.Project.ProjectService.Logger;
                logger.ClearErrorList();
                logger.ActivateOutputWindow();
                logger.WriteLine(String.Format("Searching for references to SharePoint Project Item '{0}'...", spi.Name), LogCategory.Status);

                bool referencesFound = false;

                foreach (var project in spi.Project.ProjectService.Projects)
                {
                    if (SupportsDeploymentScope(spi.ProjectItemType.SupportedDeploymentScopes, SupportedDeploymentScopes.Package))
                    {
                        if ((from ISharePointProjectItem s
                             in project.Package.ProjectItems
                             where s.Id == spi.Id
                             select s).Any())
                        {
                            referencesFound = true;
                            spi.Project.ProjectService.Logger.WriteLine(String.Format("Found reference to SharePoint Project Item '{0}' in Package '{1}' ({2})", spi.Name, project.Package.Model.Name, project.Name), LogCategory.Message, project.Package.PackageFile.FullPath, 1, 1);
                        }
                    }

                    if (CanBeDeployedUsingFeature(spi.ProjectItemType.SupportedDeploymentScopes))
                    {
                        var spiInFeatures = from ISharePointProjectFeature f
                                            in project.Features
                                            where (from ISharePointProjectItem s
                                                   in f.ProjectItems
                                                   where s.Id == spi.Id
                                                   select s).Any()
                                            select f;

                        foreach (var feature in spiInFeatures)
                        {
                            referencesFound = true;
                            spi.Project.ProjectService.Logger.WriteLine(String.Format("Found reference to SharePoint Project Item '{0}' in Feature '{1}' ({2})", spi.Name, feature.Model.Title, feature.Project.Name), LogCategory.Message, feature.FeatureFile.FullPath, 1, 1);
                        }
                    }
                }

                if (!referencesFound)
                {
                    logger.WriteLine(String.Format("No references to SharePoint Project Item '{0}' found", spi.Name), LogCategory.Status);
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Retrieves all projects in the solution where this SPI is packaged.
        /// </summary>
        /// <param name="item">The ISharePointProjectItem being extended.</param>
        /// <param name="service">The sharepoint project service.</param>
        /// <returns>Returns all projects in the solution where this SPI is packaged.</returns>
        public static IEnumerable <ISharePointProject> GetProjectsWhereInPackage(this ISharePointProjectItem item, ISharePointProjectService service)
        {
            List <ISharePointProject> pkgProjects = new List <ISharePointProject>();

            foreach (ISharePointProject project in service.Projects)
            {
                if (item.IsPartOfProjectPackage(project))
                {
                    pkgProjects.Add(project);
                }
            }

            return(pkgProjects);
        }
        private void SetDeploymentPath(DTE dte, Project project, ProjectItem CreatedProjectItem, SPFileType sPFileType, string evaluatedDeploymentPath)
        {
            //set to content
            if ((sPFileType != SPFileType.CustomCode))
            {
                CreatedProjectItem.Properties.Item("BuildAction").Value = 2;
            }

            //ok, file is placed, but we need set the deployment path
            ISharePointProjectService projectService    = Helpers2.GetSharePointProjectService(dte);
            ISharePointProject        sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(project);

            sharePointProject.Synchronize();

            if (CreatedProjectItem.Collection.Parent is ProjectItem)
            {
                ProjectItem parentItem = CreatedProjectItem.Collection.Parent as ProjectItem;
                string      name       = parentItem.Name;

                //is the parent element a feature?
                try
                {
                    ISharePointProjectFeature parentIsFeature = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectFeature>(parentItem);
                    if (parentIsFeature != null)
                    {
                        ISharePointProjectItem addedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItem>(CreatedProjectItem);
                        if (addedSharePointItem != null)
                        {
                            parentIsFeature.ProjectItems.Add(addedSharePointItem);
                        }
                    }
                }
                catch { }
            }

            try
            {
                //sometimes property deploymentpath is readonly
                //1. new added items need to be validated before
                ISharePointProjectItemFile newaddedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItemFile>(CreatedProjectItem);
                newaddedSharePointItem.DeploymentType = Helpers2.GetDeploymentTypeFromFileType(this.DeploymentType);
                if (!string.IsNullOrEmpty(evaluatedDeploymentPath))
                {
                    newaddedSharePointItem.DeploymentPath = evaluatedDeploymentPath;
                }
            }
            catch { }
        }
Esempio n. 18
0
        /// <summary>
        /// Loads the features.
        /// </summary>
        /// <param name="spi">The spi.</param>
        private void LoadFeatures(ISharePointProjectItem spi)
        {
            allFeatures = new List <ISharePointProjectFeature>();

            foreach (var p in spi.Project.ProjectService.Projects)
            {
                foreach (var f in p.Features)
                {
                    if (f.Model != null &&
                        FeatureSupportsSpiScope(f.Model.Scope, spi.ProjectItemType.SupportedDeploymentScopes))
                    {
                        allFeatures.Add(f);
                    }
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the addToSpecificFeature control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.VisualStudio.SharePoint.MenuItemEventArgs"/> instance containing the event data.</param>
        void addToSpecificFeature_Click(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem spi = e.Owner as ISharePointProjectItem;

            if (spi != null)
            {
                using (FeaturesViewerForm form = new FeaturesViewerForm(spi))
                {
                    if (form.ShowDialog() == DialogResult.OK && form.SelectedFeature != null)
                    {
                        form.SelectedFeature.ProjectItems.Add(spi);
                        ISharePointProjectLogger logger = spi.Project.ProjectService.Logger;
                        logger.ClearErrorList();
                        logger.ActivateOutputWindow();
                        logger.WriteLine(String.Format("SharePoint Project Item '{0}' successfully added to Feature '{1}'", spi.Name, form.SelectedFeature.Model.Title), LogCategory.Message, form.SelectedFeature.FullPath, 1, 1);
                    }
                }
            }
        }
Esempio n. 20
0
        // Gets the ISharePointProjectItemFile object for the BDC model file.
        private ISharePointProjectItemFile GetModelFile(ISharePointProjectItem projectItem)
        {
            string modelFileName;

            if (projectItem.FeatureProperties.TryGetValue(ModelFileNameString, out modelFileName))
            {
                modelFileName = Path.GetFileName(modelFileName);
                return((from file in projectItem.Files
                        where string.Compare(file.Name, modelFileName, StringComparison.OrdinalIgnoreCase) == 0
                        select file).FirstOrDefault());
            }
            else
            {
                // if we can't find the ModelFileName through the FeatureProperties,
                // get the first file that has a '.bdcm' extension
                return((from file in projectItem.Files
                        where file.Name.EndsWith(EXTENSION_BDCM, StringComparison.OrdinalIgnoreCase)
                        select file).FirstOrDefault());
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Handles the ProjectItemInitialized event of the spiType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SharePointProjectItemEventArgs" /> instance containing the event data.</param>
        private void spiType_ProjectItemInitialized(object sender, SharePointProjectItemEventArgs e)
        {
            if (recentlyAddedItem == e.ProjectItem.Id)
            {
                recentlyAddedItem = Guid.Empty;
                ISharePointProjectItem spi = e.ProjectItem;
                IEnumerable <ISharePointProjectFeature> source = from ISharePointProjectFeature feature
                                                                 in spi.Project.Features
                                                                 where feature.ProjectItems.Contains(spi)
                                                                 select feature;

                if ((source != null) && (source.Count() > 0))
                {
                    foreach (ISharePointProjectFeature feature in source)
                    {
                        feature.ProjectItems.Remove(spi);
                    }
                }
            }
        }
Esempio n. 22
0
        // Generates an external data list for each Entity in the BDC model. This event handler is called
        // when the developer clicks the shortcut menu item that the extension adds to the BDC project item.
        private void GenerateExternalDataLists_Execute(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem     projectItem = (ISharePointProjectItem)e.Owner;
            ISharePointProjectItemFile bdcmFile    = GetModelFile(projectItem);

            XDocument       doc             = XDocument.Load(bdcmFile.FullPath);
            List <XElement> skippedEntities = new List <XElement>();

            // Try to generate an external data list for each entity defined in the BDC model file.
            foreach (XElement entity in doc.Root.Elements(BdcNamespace + "LobSystems").Elements(
                         BdcNamespace + "LobSystem").Elements(BdcNamespace + "Entities").Elements(BdcNamespace + "Entity"))
            {
                if (!GenerateExternalDataList(projectItem, entity))
                {
                    skippedEntities.Add(entity);
                }
            }

            // Report skipped entities.
            if (skippedEntities.Count != 0)
            {
                StringBuilder entityNameList = null;
                skippedEntities.ForEach(delegate(XElement entity)
                {
                    if (entityNameList == null)
                    {
                        entityNameList = new StringBuilder();
                    }
                    else
                    {
                        entityNameList.AppendLine(",");
                    }
                    entityNameList.Append(entity.Attribute("Name").Value);
                });

                string message = string.Format("The following Entities were skipped because either a LobSystemInstance, " +
                                               "SpecificFinder, or Finder was not found for them. \r\n{0}", entityNameList);
                projectItem.Project.ProjectService.Logger.WriteLine(message, LogCategory.Warning);
            }
        }
Esempio n. 23
0
        // Tries to generate an external data list for the specified BDC model project item and entity.
        private bool GenerateExternalDataList(ISharePointProjectItem projectItem, XElement entity)
        {
            string lobSystemInstanceName = GetLobSystemInstanceName(entity);
            string specificFinderName    = GetSpecificFinderName(entity);
            string finderName            = GetFinderName(entity);
            string entityName            = entity.Attribute("Name").Value;

            if (string.IsNullOrEmpty(lobSystemInstanceName) || string.IsNullOrEmpty(specificFinderName) ||
                string.IsNullOrEmpty(finderName))
            {
                return(false);
            }

            string newExternalDataListName             = entityName + "DataList";
            ISharePointProjectItem existingProjectItem = (from ISharePointProjectItem existingItem in projectItem.Project.ProjectItems
                                                          where existingItem.Name == newExternalDataListName
                                                          select existingItem).FirstOrDefault();

            // Add a new list instance and populate it with data from the BDC model.
            if (existingProjectItem == null)
            {
                ISharePointProjectItem newExternalDataList = projectItem.Project.ProjectItems.Add(newExternalDataListName,
                                                                                                  "Microsoft.VisualStudio.SharePoint.ListInstance");

                string newExternalDataListString = externalDataListContent;
                newExternalDataListString = newExternalDataListString.Replace("$EntityName$", entityName);
                newExternalDataListString = newExternalDataListString.Replace("$LobSystemInstance$", lobSystemInstanceName);
                newExternalDataListString = newExternalDataListString.Replace("$EntityNamespace$", entity.Attribute("Namespace").Value);
                newExternalDataListString = newExternalDataListString.Replace("$SpecificFinder$", specificFinderName);
                newExternalDataListString = newExternalDataListString.Replace("$Finder$", finderName);

                string elementsXmlPath = Path.Combine(newExternalDataList.FullPath, "Elements.xml");
                File.WriteAllText(elementsXmlPath, newExternalDataListString);
                ISharePointProjectItemFile elementsFile = newExternalDataList.Files.AddFromFile(elementsXmlPath);
                elementsFile.DeploymentType = DeploymentType.ElementManifest;
            }

            return(true);
        }
Esempio n. 24
0
        public override void Execute()
        {
            DTE service = (DTE)this.GetService(typeof(DTE));

            try
            {
                if (projectItem != null)
                {
                    Helpers.LogMessage(service, this, "*********** SharePointService Properties ********************");
                    try
                    {
                        ISharePointProjectService projectService    = Helpers2.GetSharePointProjectService(service);
                        ISharePointProject        sharePointProject = projectService.Convert <Project, ISharePointProject>(project);

                        try
                        {   //is it a feature
                            ISharePointProjectFeature sharePointFeature = projectService.Convert <ProjectItem, ISharePointProjectFeature>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a feature
                            ISharePointProjectItem sharePointItem = projectService.Convert <ProjectItem, ISharePointProjectItem>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a feature
                            ISharePointProjectItemFile sharePointItemFile = projectService.Convert <ProjectItem, ISharePointProjectItemFile>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a mapped folder
                            IMappedFolder sharePointMappedFolder = projectService.Convert <ProjectItem, IMappedFolder>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a mapped folder
                            ISharePointProjectPackage sharePointProjectPackage = projectService.Convert <ProjectItem, ISharePointProjectPackage>(projectItem);
                        }
                        catch { }
                    }
                    catch {}

                    //codelements
                    Helpers.LogMessage(service, this, "*********** EnvDTE CodeElements ********************");

                    foreach (CodeElement codeElement in projectItem.FileCodeModel.CodeElements)
                    {
                        try
                        {
                            Helpers.LogMessage(service, this, "codeElement.FullName: " + codeElement.FullName);
                            Helpers.LogMessage(service, this, "codeElement.Type: " + codeElement.GetType().ToString());
                            Helpers.LogMessage(service, this, "codeElement.Kind: " + codeElement.Kind.ToString());
                        }
                        catch {}
                    }

                    Helpers.LogMessage(service, this, "*********** EnvDTE Properties ********************");
                    for (int i = 0; i < projectItem.Properties.Count; i++)
                    {
                        try
                        {
                            string name  = projectItem.Properties.Item(i).Name;
                            string value = "";
                            try
                            {
                                value = projectItem.Properties.Item(i).Value.ToString();
                            }
                            catch (Exception)
                            {
                            }
                            Helpers.LogMessage(service, this, name + "=" + value);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else if (project != null)
                {
                    for (int i = 0; i < project.Properties.Count; i++)
                    {
                        try
                        {
                            string name  = project.Properties.Item(i).Name;
                            string value = "";
                            try
                            {
                                value = project.Properties.Item(i).Value.ToString();
                            }
                            catch (Exception)
                            {
                            }
                            Helpers.LogMessage(service, this, name + "=" + value);

                            if (project.Properties.Item(i).Collection.Count > 0)
                            {
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Helpers.LogMessage(service, this, ex.ToString());
            }
        }
 internal SiteColumnProperties(ISharePointProjectItem projectItem)
 {
     this.projectItem = projectItem;
 }
Esempio n. 26
0
 internal CustomActionProperties(ISharePointProjectItem projectItem)
 {
     this.projectItem = projectItem;
 }
Esempio n. 27
0
 /// <summary>
 /// Create a new instance of the SharePointProjectItemArtefact object.
 /// </summary>
 /// <param name="item"></param>
 public SharePointProjectItemArtefact(ISharePointProjectItem item)
 {
     this.item = item;
 }
Esempio n. 28
0
 internal CustomActionProperties(ISharePointProjectItem projectItem)
 {
     this.projectItem = projectItem;
 }
        /// <summary>
        /// Returns all SharePoint artefacts for a given ProjectItem.  Multiple items may be returned, for example, if the
        /// selection is a folder.  Note that this list is not pruned in the event of multiple selections from the same sub-tree.
        /// </summary>
        /// <param name="projectService"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static List <QuickCopyableSharePointArtefact> ResolveProjectItemToArtefacts(ISharePointProjectService projectService, ProjectItem item)
        {
            // Ensure we have a SharePoint service.
            if (projectService == null)
            {
                return(null);
            }

            // Prepare list for return.
            List <QuickCopyableSharePointArtefact> artefacts = new List <QuickCopyableSharePointArtefact>();

            // See if this item is a SPI file.
            try
            {
                ISharePointProjectItemFile spFile = projectService.Convert <ProjectItem, ISharePointProjectItemFile>(item);
                if (spFile != null)
                {
                    if (spFile.DeploymentType != DeploymentType.NoDeployment)
                    {
                        artefacts.Add(new SharePointProjectItemFileArtefact(spFile));
                        return(artefacts);
                    }
                }
            }
            catch { }

            // See if this item is an SPI.
            try
            {
                ISharePointProjectItem spItem = projectService.Convert <ProjectItem, ISharePointProjectItem>(item);
                if (spItem != null)
                {
                    artefacts.Add(new SharePointProjectItemArtefact(spItem));
                    return(artefacts);
                }
            }
            catch { }

            // See if this item is a Feature.
            try
            {
                ISharePointProjectFeature spFeature = projectService.Convert <ProjectItem, ISharePointProjectFeature>(item);
                if (spFeature != null)
                {
                    artefacts.Add(new SharePointProjectFeatureArtefact(spFeature));
                    return(artefacts);
                }
            }
            catch { }

            // See if we have a Folder, and recursively find SharePoint items.
            try
            {
                if (item.ProjectItems.Count > 0)
                {
                    for (int i = 1; i <= item.ProjectItems.Count; i++)
                    {
                        ProjectItem childItem = item.ProjectItems.Item(i);
                        artefacts.AddRange(ResolveProjectItemToArtefacts(projectService, childItem));
                    }
                }
            }
            catch { }

            // TODO: Also, these items are potential types for conversion.
            // ISharePointProjectFeatureResourceFile
            // ISharePointProjectPackage

            return(artefacts);
        }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FullTrustProxyProperties"/> class.
 /// </summary>
 /// <param name="proxy">The proxy.</param>
 /// <param name="projectItem">The project item.</param>
 public FullTrustProxyProperties(FullTrustProxyTypeProvider proxy, ISharePointProjectItem projectItem)
 {
     Proxy       = proxy;
     ProjectItem = projectItem;
 }
Esempio n. 31
0
        /// <summary>
        /// returns the relative path of the item in the final sharepoint folder
        /// </summary>
        /// <param name="dte"></param>
        /// <param name="selectedItem"></param>
        /// <returns></returns>
        public static string GetDeploymentPathOfItem(DTE dte, ProjectItem selectedItem)
        {
            //1. trying to use VS 2010
            try
            {
                ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(dte);


                try
                {
                    ISharePointProjectItemFile selectedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItemFile>(selectedItem);
                    string path = selectedSharePointItem.DeploymentRoot + selectedSharePointItem.DeploymentPath + selectedSharePointItem.Name; //= {SharePointRoot}\\Template\\
                    if (path.StartsWith("{SharePointRoot}"))
                    {
                        path = path.Replace("{SharePointRoot}", "");
                    }
                    if (path.Contains("{FeatureName}"))
                    {
                        //ok, element is part of a feature, need to find the feature where the element is located
                        string parentFeatureName = "";
                        ISharePointProjectItem sharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItem>(selectedItem);
                        if (sharePointItem == null)
                        {
                            if (selectedItem.Collection.Parent is ProjectItem)
                            {
                                sharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItem>(selectedItem.Collection.Parent as ProjectItem);
                            }
                        }
                        foreach (ISharePointProject project in projectService.Projects)
                        {
                            foreach (ISharePointProjectFeature feature in project.Features)
                            {
                                if (feature.ProjectItems.Contains(sharePointItem))
                                {
                                    parentFeatureName = feature.Name;
                                }
                            }
                        }
                        path = path.Replace("{FeatureName}", parentFeatureName);
                    }
                    return(path);
                }
                catch { }
            }
            catch { }

            //ok, we have HIVE format!
            //structure could be 12, 14, oder SharePointRoot
            string projectfolder    = Path.GetDirectoryName(Helpers.GetFullPathOfProjectItem(selectedItem.ContainingProject));
            string itemFullPath     = Helpers.GetFullPathOfProjectItem(selectedItem);
            string itemRelativePath = itemFullPath.Substring(projectfolder.Length + 1);

            if (itemRelativePath.StartsWith("12"))
            {
                return(itemRelativePath.Substring(2));
            }
            else if (itemRelativePath.StartsWith("14"))
            {
                return(itemRelativePath.Substring(2));
            }
            else if (itemRelativePath.StartsWith("15"))
            {
                return(itemRelativePath.Substring(2));
            }
            else if (itemRelativePath.StartsWith("SharePointRoot", StringComparison.InvariantCultureIgnoreCase))
            {
                return(itemRelativePath.Substring(14));
            }

            return("");
        }