Ejemplo n.º 1
0
        public void FileNames_IndexOneRequested_ReturnsFullPathToProjectItem()
        {
            CreateProjectItems(@"d:\projects\MyProject\MyProject.csproj");
            msbuildProject.AddFile(@"src\program.cs");
            global::EnvDTE.ProjectItem directoryItem = projectItems.Item("src");

            string fileName = directoryItem.get_FileNames(1);

            Assert.AreEqual(@"d:\projects\MyProject\src", fileName);
        }
        /// <summary>
        /// Create a new DataContractDsl model and return a modelbus reference to it
        /// </summary>
        /// <param name="modelName">Name of the model to create (with or without the extension)</param>
        /// <param name="relativeToPathName">pathName on a model relative to which to create the new model</param>
        /// <param name="relativePath">Path relative to the <paramref name="relativeTo"/> model. If <c>null</c>, the new
        /// model is created at the same location as the <paramref name="relativeTo"/> model</param>
        public static DslIntegration::ModelBusReference CreateDataContractModel(string modelName, string relativeToPathName, string relativePath = null)
        {
            global::EnvDTE.DTE        dte      = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(global::EnvDTE.DTE)) as global::EnvDTE.DTE;
            DslIntegration::IModelBus modelBus = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DslIntegration::SModelBus)) as DslIntegration::IModelBus;

            global::EnvDTE.ProjectItem item    = dte.Solution.FindProjectItem(relativeToPathName);
            global::EnvDTE.Project     project = item.ContainingProject;

            string template = (dte.Solution as global::EnvDTE80.Solution2).GetProjectItemTemplate("DataContractDsl.zip", "CSharp");

            string modelNameWithExtension = global::System.IO.Path.ChangeExtension(modelName, ".datacontract");

            global::EnvDTE.ProjectItem newItem = project.ProjectItems.AddFromTemplate(template, modelNameWithExtension);
            if (newItem == null) /// Well known bug
            {
                newItem = project.ProjectItems.Item(modelNameWithExtension);
            }

            DslIntegration::ModelingAdapterReference mar = new DslIntegration::ModelingAdapterReference(null, null, newItem.get_FileNames(1));

            DslIntegration::ModelBusReference mbr = new DslIntegration::ModelBusReference(modelBus,
                                                                                          DataContractDslAdapter.AdapterId,
                                                                                          System.IO.Path.GetFileNameWithoutExtension(newItem.Name),
                                                                                          mar);

            return(mbr);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a reference on a model described by the parameters
        /// </summary>
        /// <param name="modelLocatorInfo">The default implementation (which can be overriden)
        /// supports models described as ProjectItems, and
        /// model file path whether or not in the project/solution</param>
        /// <returns>true if this adapter </returns>
        public override DslIntegration::ModelBusReference CreateReference(params object[] modelLocatorInfo)
        {
            // Infer the project item from the parameters
            global::EnvDTE.ProjectItem item = GetProjectItem(modelLocatorInfo);

            if (item == null)
            {
                return(null);
            }

            // Create the part of the reference which depends on the Adapter
            DslIntegration::ModelingAdapterReference mar = new DslIntegration::ModelingAdapterReference(null, null, item.get_FileNames(1));

            // And aggregate it with the adapter manager's part
            DslIntegration::ModelBusReference mbr = new DslIntegration::ModelBusReference(
                this.ModelBus, DataContractDslAdapter.AdapterId,
                global::System.IO.Path.GetFileNameWithoutExtension(item.Name),
                mar);

            return(mbr);
        }