Ejemplo n.º 1
0
        public virtual void GenerateFiles(DotNetProject project, string namspace, string referenceName)
        {
            // Create the base directory if it does not exists
            FilePath basePath = GetReferencePath(project, referenceName).CanonicalPath;

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            // Remove old files from the service directory
            List <ProjectFile> toRemove = new List <ProjectFile>(project.Files.GetFilesInPath(basePath));

            foreach (ProjectFile f in toRemove)
            {
                project.Files.Remove(f);
            }

            // Generate the wsdl, disco and map files
            string mapSpec = GenerateDescriptionFiles(project, basePath);

            // Generate the proxy class
            string proxySpec = CreateProxyFile(project, basePath, namspace + "." + referenceName, "Reference");

            ProjectFile mapFile = new ProjectFile(mapSpec);

            mapFile.BuildAction = BuildAction.None;
            mapFile.Subtype     = Subtype.Code;
            mapFile.Generator   = ProxyGenerator;
            project.Files.Add(mapFile);

            ProjectFile proxyFile = new ProjectFile(proxySpec);

            proxyFile.BuildAction = BuildAction.Compile;
            proxyFile.Subtype     = Subtype.Code;
            proxyFile.DependsOn   = mapFile.FilePath;
            project.Files.Add(proxyFile);

            mapFile.LastGenOutput = proxyFile.FilePath.FileName;

            item = new WebReferenceItem(engine, project, referenceName, basePath, mapFile);

            // Add references to the project if they do not exist
            ProjectReference gacRef;

            foreach (string refName in GetAssemblyReferences())
            {
                string targetName = project.TargetRuntime.AssemblyContext.GetAssemblyNameForVersion(refName, null, project.TargetFramework);
                //FIXME: warn when we could not find a matching target assembly
                if (targetName != null)
                {
                    gacRef = new ProjectReference(ReferenceType.Gac, targetName);
                    if (!project.References.Contains(gacRef))
                    {
                        project.References.Add(gacRef);
                    }
                }
            }
            WebReferencesService.NotifyWebReferencesChanged(project);
        }
Ejemplo n.º 2
0
 /// <summary>Delete the web reference from the project.</summary>
 public void Delete()
 {
     engine.Delete(this);
     WebReferencesService.NotifyWebReferencesChanged(project);
 }
        public virtual async Task GenerateFiles(DotNetProject project, string namspace, string referenceName)
        {
            //make sure we have a valid value for the namespace
            if (string.IsNullOrEmpty(namspace))
            {
                namspace = project.GetDefaultNamespace(null);
            }

            // Create the base directory if it does not exists
            FilePath basePath = GetReferencePath(project, referenceName).CanonicalPath;

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            // Remove old files from the service directory
            var toRemove = new List <ProjectFile>(project.Files.GetFilesInPath(basePath));

            foreach (ProjectFile f in toRemove)
            {
                project.Files.Remove(f);
            }

            // Generate the wsdl, disco and map files
            string mapSpec = await GenerateDescriptionFiles(project, basePath);

            // Generate the proxy class
            string proxySpec = await CreateProxyFile(project, basePath, namspace + "." + referenceName, "Reference");

            ProjectFile mapFile = project.Files.GetFile(mapSpec);

            if (mapFile == null)
            {
                mapFile = new ProjectFile(mapSpec)
                {
                    BuildAction = BuildAction.None,
                    Subtype     = Subtype.Code,
                    Generator   = ProxyGenerator
                };
                project.Files.Add(mapFile);
            }
            else
            {
                FileService.NotifyFileChanged(mapSpec);
            }

            ProjectFile proxyFile = project.Files.GetFile(proxySpec);

            if (proxyFile == null)
            {
                proxyFile = new ProjectFile(proxySpec)
                {
                    BuildAction = BuildAction.Compile,
                    Subtype     = Subtype.Code,
                    DependsOn   = mapFile.FilePath
                };
                project.Files.Add(proxyFile);
            }
            else
            {
                FileService.NotifyFileChanged(proxySpec);
            }

            mapFile.LastGenOutput = proxyFile.FilePath.FileName;

            item = new WebReferenceItem(engine, project, referenceName, basePath, mapFile);

            // Add references to the project if they do not exist
            ProjectReference packageRef;

            foreach (string refName in GetAssemblyReferences())
            {
                string targetName = project.TargetRuntime.AssemblyContext.GetAssemblyNameForVersion(refName, null, project.TargetFramework);
                //FIXME: warn when we could not find a matching target assembly
                if (targetName != null)
                {
                    packageRef = ProjectReference.CreateAssemblyReference(targetName);
                    if (!project.References.Contains(packageRef))
                    {
                        project.References.Add(packageRef);
                    }
                }
            }
            WebReferencesService.NotifyWebReferencesChanged(project);
        }