void Run(string [] args) { co.ProcessArgs(args); if (co.Usage) { co.DoUsage(); return; } if (co.Version) { co.DoVersion(); return; } if (co.Help || co.RemainingArguments.Count == 0) { co.DoHelp(); return; } if (!co.NoLogo) { co.ShowBanner(); } CodeCompileUnit ccu = new CodeCompileUnit(); CodeNamespace cns = new CodeNamespace(co.Namespace); ccu.Namespaces.Add(cns); generator = new ServiceContractGenerator(ccu); generator.Options = GetGenerationOption(); generator.Options |= ServiceContractGenerationOptions.ChannelInterface; code_provider = GetCodeProvider(); MetadataSet metadata = null; // For now only assemblyPath is supported. foreach (string arg in co.RemainingArguments) { if (!File.Exists(arg)) { Uri uri = null; if (Uri.TryCreate(arg, UriKind.Absolute, out uri)) { metadata = ResolveWithDisco(arg); if (metadata == null) { metadata = ResolveWithWSMex(arg); } continue; } } else { FileInfo fi = new FileInfo(arg); switch (fi.Extension) { case ".exe": case ".dll": GenerateContractType(fi.FullName); break; default: throw new NotSupportedException("Not supported file extension: " + fi.Extension); } } } if (metadata != null) { List <IWsdlImportExtension> list = new List <IWsdlImportExtension> (); list.Add(new TransportBindingElementImporter()); //list.Add (new DataContractSerializerMessageContractImporter ()); list.Add(new XmlSerializerMessageContractImporter()); //WsdlImporter importer = new WsdlImporter (metadata, null, list); WsdlImporter importer = new WsdlImporter(metadata); ServiceEndpointCollection endpoints = importer.ImportAllEndpoints(); Collection <ContractDescription> contracts = new Collection <ContractDescription> (); if (endpoints.Count > 0) { foreach (var se in endpoints) { contracts.Add(se.Contract); } } else { foreach (var cd in importer.ImportAllContracts()) { contracts.Add(cd); } } Console.WriteLine("Generating files.."); // FIXME: could better become IWsdlExportExtension foreach (ContractDescription cd in contracts) { if (co.GenerateMoonlightProxy) { var moonctx = new MoonlightChannelBaseContext(); cd.Behaviors.Add(new MoonlightChannelBaseContractExtension(moonctx, co.GenerateMonoTouchProxy)); foreach (var od in cd.Operations) { od.Behaviors.Add(new MoonlightChannelBaseOperationExtension(moonctx, co.GenerateMonoTouchProxy)); } generator.GenerateServiceContractType(cd); moonctx.Fixup(); } else { generator.GenerateServiceContractType(cd); } } } /*if (cns.Types.Count == 0) { * Console.Error.WriteLine ("Argument assemblies have no types."); * Environment.Exit (1); * }*/ //FIXME: Generate .config Console.WriteLine(GetOutputFilename()); using (TextWriter w = File.CreateText(GetOutputFilename())) { code_provider.GenerateCodeFromCompileUnit(ccu, w, null); } }
public MoonlightChannelBaseContractExtension (MoonlightChannelBaseContext mlContext, bool generateSync) { ml_context = mlContext; generate_sync = generateSync; }
public MoonlightChannelBaseContractExtension(MoonlightChannelBaseContext mlContext, bool generateSync) { ml_context = mlContext; generate_sync = generateSync; }
protected override string CreateProxyFile (DotNetProject dotNetProject, FilePath basePath, string proxyNamespace, string referenceName) { var ccu = new CodeCompileUnit (); var cns = new CodeNamespace (proxyNamespace); ccu.Namespaces.Add (cns); bool targetMoonlight = dotNetProject.TargetFramework.Id.Identifier == ("Silverlight"); bool targetMonoTouch = dotNetProject.TargetFramework.Id.Identifier == ("MonoTouch"); bool targetMonoDroid = dotNetProject.TargetFramework.Id.Identifier == ("MonoDroid"); bool targetCoreClr = targetMoonlight || targetMonoDroid || targetMonoTouch; bool generateSyncMethods = targetMonoDroid | targetMonoTouch; var generator = new ServiceContractGenerator (ccu); generator.Options = ServiceContractGenerationOptions.ChannelInterface | ServiceContractGenerationOptions.ClientClass; if (refGroup.ClientOptions.GenerateAsynchronousMethods || targetCoreClr) generator.Options |= ServiceContractGenerationOptions.AsynchronousMethods; if (refGroup.ClientOptions.GenerateEventBasedAsynchronousMethods) generator.Options |= ServiceContractGenerationOptions.EventBasedAsynchronousMethods; #if NET_4_5 if (refGroup.ClientOptions.GenerateTaskBasedAsynchronousMethod) generator.Options |= ServiceContractGenerationOptions.TaskBasedAsynchronousMethod; #endif if (refGroup.ClientOptions.GenerateInternalTypes) generator.Options |= ServiceContractGenerationOptions.InternalTypes; if (refGroup.ClientOptions.GenerateMessageContracts) generator.Options |= ServiceContractGenerationOptions.TypedMessages; // if (targetMoonlight || targetMonoTouch) // generator.Options |= ServiceContractGenerationOptions.EventBasedAsynchronousMethods; MetadataSet mset; mset = protocol != null ? ToMetadataSet (protocol) : metadata; CodeDomProvider code_provider = GetProvider (dotNetProject); var list = new List<IWsdlImportExtension> (); list.Add (new TransportBindingElementImporter ()); list.Add (new XmlSerializerMessageContractImporter ()); var importer = new WsdlImporter (mset); try { ConfigureImporter (importer); } catch { } Collection<ContractDescription> contracts = importer.ImportAllContracts (); foreach (ContractDescription cd in contracts) { cd.Namespace = proxyNamespace; if (targetCoreClr) { var moonctx = new MoonlightChannelBaseContext (); cd.Behaviors.Add (new MoonlightChannelBaseContractExtension (moonctx, generateSyncMethods)); foreach (var od in cd.Operations) od.Behaviors.Add (new MoonlightChannelBaseOperationExtension (moonctx, generateSyncMethods)); generator.GenerateServiceContractType (cd); moonctx.Fixup (); } else generator.GenerateServiceContractType (cd); } string fileSpec = Path.Combine (basePath, referenceName + "." + code_provider.FileExtension); using (TextWriter w = File.CreateText (fileSpec)) { code_provider.GenerateCodeFromCompileUnit (ccu, w, null); } return fileSpec; }
void Run (string [] args) { co.ProcessArgs (args); if (co.Usage) { co.DoUsage (); return; } if (co.Version) { co.DoVersion (); return; } if (co.Help || co.RemainingArguments.Count == 0) { co.DoHelp (); return; } if (!co.NoLogo) co.ShowBanner (); CodeCompileUnit ccu = new CodeCompileUnit (); CodeNamespace cns = new CodeNamespace (co.Namespace); ccu.Namespaces.Add (cns); generator = new ServiceContractGenerator (ccu); generator.Options = GetGenerationOption (); generator.Options |=ServiceContractGenerationOptions.ChannelInterface; code_provider = GetCodeProvider (); MetadataSet metadata = null; // For now only assemblyPath is supported. foreach (string arg in co.RemainingArguments) { if (!File.Exists (arg)) { Uri uri = null; if (Uri.TryCreate (arg, UriKind.Absolute, out uri)) { metadata = ResolveWithDisco (arg); if (metadata == null) metadata = ResolveWithWSMex (arg); continue; } } else { FileInfo fi = new FileInfo (arg); switch (fi.Extension) { case ".exe": case ".dll": GenerateContractType (fi.FullName); break; default: throw new NotSupportedException ("Not supported file extension: " + fi.Extension); } } } if (metadata != null) { List<IWsdlImportExtension> list = new List<IWsdlImportExtension> (); list.Add (new TransportBindingElementImporter ()); //list.Add (new DataContractSerializerMessageContractImporter ()); list.Add (new XmlSerializerMessageContractImporter ()); //WsdlImporter importer = new WsdlImporter (metadata, null, list); WsdlImporter importer = new WsdlImporter (metadata); ServiceEndpointCollection endpoints = importer.ImportAllEndpoints (); Collection<ContractDescription> contracts = new Collection<ContractDescription> (); if (endpoints.Count > 0) { foreach (var se in endpoints) contracts.Add (se.Contract); } else { foreach (var cd in importer.ImportAllContracts ()) contracts.Add (cd); } Console.WriteLine ("Generating files.."); // FIXME: could better become IWsdlExportExtension foreach (ContractDescription cd in contracts) { if (co.GenerateMoonlightProxy) { var moonctx = new MoonlightChannelBaseContext (); cd.Behaviors.Add (new MoonlightChannelBaseContractExtension (moonctx, co.GenerateMonoTouchProxy)); foreach (var od in cd.Operations) od.Behaviors.Add (new MoonlightChannelBaseOperationExtension (moonctx, co.GenerateMonoTouchProxy)); generator.GenerateServiceContractType (cd); moonctx.Fixup (); } else generator.GenerateServiceContractType (cd); } } /*if (cns.Types.Count == 0) { Console.Error.WriteLine ("Argument assemblies have no types."); Environment.Exit (1); }*/ //FIXME: Generate .config Console.WriteLine (GetOutputFilename ()); using (TextWriter w = File.CreateText (GetOutputFilename ())) { code_provider.GenerateCodeFromCompileUnit (ccu, w, null); } }
public MoonlightChannelBaseContractExtension(MoonlightChannelBaseContext mlContext) { ml_context = mlContext; }
public MoonlightChannelBaseOperationExtension(MoonlightChannelBaseContext mlContext) { ml_context = mlContext; }
public MoonlightChannelBaseContractExtension (MoonlightChannelBaseContext mlContext) { ml_context = mlContext; }
public MoonlightChannelBaseOperationExtension (MoonlightChannelBaseContext mlContext) { ml_context = mlContext; }
protected override string CreateProxyFile (DotNetProject dotNetProject, FilePath basePath, string proxyNamespace, string referenceName) { CodeCompileUnit ccu = new CodeCompileUnit (); CodeNamespace cns = new CodeNamespace (proxyNamespace); ccu.Namespaces.Add (cns); bool targetMoonlight = dotNetProject.TargetFramework.Id.StartsWith ("SL"); bool targetMonoTouch = dotNetProject.TargetFramework.Id.StartsWith ("IPhone"); ServiceContractGenerator generator = new ServiceContractGenerator (ccu); generator.Options = ServiceContractGenerationOptions.ChannelInterface | ServiceContractGenerationOptions.ClientClass; if (refGroup.ClientOptions.GenerateAsynchronousMethods) generator.Options |= ServiceContractGenerationOptions.AsynchronousMethods; if (refGroup.ClientOptions.GenerateInternalTypes) generator.Options |= ServiceContractGenerationOptions.InternalTypes; if (refGroup.ClientOptions.GenerateMessageContracts) generator.Options |= ServiceContractGenerationOptions.TypedMessages; // if (targetMoonlight || targetMonoTouch) // generator.Options |= ServiceContractGenerationOptions.EventBasedAsynchronousMethods; MetadataSet mset; if (protocol != null) mset = ToMetadataSet (protocol); else mset = metadata; CodeDomProvider code_provider = GetProvider (dotNetProject); List<IWsdlImportExtension> list = new List<IWsdlImportExtension> (); list.Add (new TransportBindingElementImporter ()); list.Add (new XmlSerializerMessageContractImporter ()); WsdlImporter importer = new WsdlImporter (mset); Collection<ContractDescription> contracts = importer.ImportAllContracts (); foreach (ContractDescription cd in contracts) { cd.Namespace = proxyNamespace; if (targetMoonlight || targetMonoTouch) { var moonctx = new MoonlightChannelBaseContext (); cd.Behaviors.Add (new MoonlightChannelBaseContractExtension (moonctx, targetMonoTouch)); foreach (var od in cd.Operations) od.Behaviors.Add (new MoonlightChannelBaseOperationExtension (moonctx, targetMonoTouch)); generator.GenerateServiceContractType (cd); moonctx.Fixup (); } else generator.GenerateServiceContractType (cd); } string fileSpec = Path.Combine (basePath, referenceName + "." + code_provider.FileExtension); using (TextWriter w = File.CreateText (fileSpec)) { code_provider.GenerateCodeFromCompileUnit (ccu, w, null); } return fileSpec; }