/// <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); }
/// <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); }
/// <summary> /// Create a new ServiceContractDsl 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 CreateServiceContractModel(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("ServiceContractDsl.zip", "CSharp"); string modelNameWithExtension = global::System.IO.Path.ChangeExtension(modelName, ".servicecontract"); 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, ServiceContractDslAdapter.AdapterId, System.IO.Path.GetFileNameWithoutExtension(newItem.Name), mar); return mbr; }
/// <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="relativeTo">ModelBusRefrence 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, DslIntegration::ModelBusReference relativeTo, string relativePath = null) { DslIntegration::ModelingAdapter adapter = relativeTo.ModelBus.CreateAdapter(relativeTo) as DslIntegration::ModelingAdapter; if (adapter != null) { string filename = adapter.DocumentHandler.ModelFile; return(CreateDataContractModel(modelName, filename, relativePath)); } else { return(null); } }
/// <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; }
/// <summary> /// Get a view of the given reference /// </summary> /// <param name="reference">Refernce on the view we want to get</param> /// <returns>A ModelBusView of the given reference</returns> public override DslIntegration::ModelBusView GetView(DslIntegration::ModelBusReference reference) { return(new DslIntegrationShell::StandardVsModelingDiagramView(this, reference)); }
/// <summary> /// Constructor from a ModelBusReference, the adapter manager, and the root model element of the ServiceContractDsl model /// </summary> public ServiceContractDslAdapterBase(DslIntegration::ModelBusReference reference, DslIntegrationShell::VsModelingAdapterManager adapterManager, global::Microsoft.Practices.ServiceFactory.ServiceContracts.ServiceContractModel rootModelElement) : base(reference, adapterManager, rootModelElement) { }
/// <summary> /// Create a new CloudCoreArchitectSubProcess 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 CreateSubProcess(string modelName, string relativeToPathName, string relativePath = null) { // Get the Visual Studio services 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; // Get the item corresponding to "relativePathName". global::EnvDTE.ProjectItem item = dte.Solution.FindProjectItem(relativeToPathName); global::EnvDTE.Project project = item.ContainingProject; global::EnvDTE.ProjectItems parent = project.ProjectItems; // Find the sub folder (or create it if necessary) in the case of a relativePath if (relativePath != null) { string[] pathSegments = relativePath.Split(global::System.IO.Path.PathSeparator); for (int i = 0; i < pathSegments.Length; ++i) { global::EnvDTE.ProjectItem folder = parent.OfType<global::EnvDTE.ProjectItem>().FirstOrDefault(projectItem => string.Compare(projectItem.Name, pathSegments[i], true) == 0); if (folder == null) { folder = parent.AddFolder(pathSegments[i]); } parent = folder.ProjectItems; } } // Find the model item template string template = (dte.Solution as global::EnvDTE80.Solution2).GetProjectItemTemplate("CloudCoreArchitectSubProcess.zip", "CSharp"); string modelNameWithExtension = global::System.IO.Path.ChangeExtension(modelName, ".subprocess"); global::EnvDTE.ProjectItem newItem = parent.AddFromTemplate(template, modelNameWithExtension); if (newItem == null) /// Well known behavior for C# and VB project, null is returned, so we need to re-ask for the project item newItem = parent.Item(modelNameWithExtension); DslIntegration::ModelingAdapterReference mar = new DslIntegration::ModelingAdapterReference(null, null, newItem.get_FileNames(1)); DslIntegration::ModelBusReference mbr = new DslIntegration::ModelBusReference(modelBus, CloudCoreArchitectSubProcessAdapter.AdapterId, System.IO.Path.GetFileNameWithoutExtension(newItem.Name), mar); return mbr; }
/// <summary> /// Instantiates a ModelBusAdapter for the DataContractDsl model of given ModelBusReference and Root Model element /// </summary> /// <param name="reference">ModelBusReference of the model</param> /// <param name="rootModelElement">Root element of the model</param> /// <returns>A newly created ModelBusAdapter to manipulate the DSL</returns> protected override DslIntegration::ModelingAdapter CreateModelingAdapterInstance(DslIntegration::ModelBusReference reference, DslModeling::ModelElement rootModelElement) { if (rootModelElement as global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractModel == null) { throw new global::System.ArgumentException("Invalid model root passed"); } return(new DataContractDslAdapter(reference, this, rootModelElement as global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractModel)); }