/// <summary>
        /// Initializes a new instance of the DefaultCodeBuilder class.
        /// </summary>
        /// <param name="dependencyInjector">The dependency injector.</param>
        /// <param name="language">The programming language to use for generating code.</param>
        public DefaultCodeBuilder(
            IDependencyInjector dependencyInjector,
            IProgrammingLanguageStrategy language)
        {
            this.Log = Logger.Null;

            this.injector = dependencyInjector;
            this.language = language;
            this.namespaceImports = new List<string>();
            this.referenceAssemblies = new List<string>();
            this.externalProperties = new Dictionary<string, ExternalProperty>();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the DefaultCodeBuilder class.
        /// </summary>
        /// <param name="dependencyInjector">The dependency injector.</param>
        /// <param name="language">The programming language to use for generating code.</param>
        public DefaultCodeBuilder(
            IDependencyInjector dependencyInjector,
            IProgrammingLanguageStrategy language)
        {
            this.Log = Logger.Null;

            this.injector            = dependencyInjector;
            this.language            = language;
            this.namespaceImports    = new List <string>();
            this.referenceAssemblies = new List <string>();
            this.externalProperties  = new Dictionary <string, ExternalProperty>();
        }
        /// <summary>
        /// Generates the client-side proxy classes then calls the given callback
        /// </summary>
        /// <param name="continuation">The async continuation to report completion on</param>
        /// <param name="serviceRoot">The root uri of the service</param>
        /// <param name="model">The model for the service</param>
        /// <param name="language">The language to generate code in</param>
        /// <param name="onCompletion">The action to invoke with the generated code</param>
        public void GenerateClientCode(IAsyncContinuation continuation, Uri serviceRoot, EntityModelSchema model, IProgrammingLanguageStrategy language, Action<string> onCompletion)
        {
            ExceptionUtilities.CheckArgumentNotNull(continuation, "continuation");
            ExceptionUtilities.CheckArgumentNotNull(serviceRoot, "serviceRoot");
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckArgumentNotNull(language, "language");
            ExceptionUtilities.CheckArgumentNotNull(onCompletion, "onCompletion");

            var compileUnit = new CodeCompileUnit();
            this.GenerateObjectLayer(compileUnit, model);
            this.GenerateContextType(compileUnit, model);

            string clientCode = language.CreateCodeGenerator().GenerateCodeFromCompileUnit(compileUnit);

            onCompletion(clientCode);
            continuation.Continue();
        }
        /// <summary>
        /// Gets the reference assemblies needed to compile a client for the given model and language
        /// </summary>
        /// <param name="model">The model being generated</param>
        /// <param name="language">The current language</param>
        /// <returns>The list of reference assemblies</returns>
        internal static IEnumerable <string> GetClientReferenceAssemblies(EntityModelSchema model, IProgrammingLanguageStrategy language)
        {
            bool isVB = language.LanguageName == "VB";
            IEnumerable <string> languageSpecificReferences = isVB ? referenceAssemblies.Where(l => l != "mscorlib.dll") : referenceAssemblies;

            if (model.HasSpatialFeatures())
            {
                languageSpecificReferences = languageSpecificReferences.Concat(DataFxAssemblyRef.File.SpatialCore);
            }

            return(languageSpecificReferences);
        }
        internal static IEnumerable<string> GetAssembliesToReference(EntityModelSchema model, IProgrammingLanguageStrategy language)
        {
            if (language.LanguageName != "VB")
            {
                yield return "mscorlib.dll";
            }

            yield return "System.dll";
            yield return "System.Core.dll";
#if SILVERLIGHT && !WIN8
            yield return DataFxAssemblyRef.File.DataServicesSilverlightClient;
#else
            yield return DataFxAssemblyRef.File.DataServicesClient;
#endif
            yield return DataFxAssemblyRef.File.ODataLib;
            yield return DataFxAssemblyRef.File.EntityDataModel;

            if (model.HasSpatialFeatures())
            {
                yield return DataFxAssemblyRef.File.SpatialCore;
            }

#if SILVERLIGHT && !WIN8
            yield return "System.Windows.dll";
            yield return "Microsoft.Test.Taupo.SL.dll";
            yield return "Microsoft.Test.Taupo.Astoria.SL.dll";
            yield return "Microsoft.Test.Taupo.Query.SL.dll";
#else
            yield return "Microsoft.Test.Taupo.dll";
            yield return "Microsoft.Test.Taupo.Astoria.dll";
            yield return "Microsoft.Test.Taupo.Query.dll";
#endif
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the PocoEntityClassGenerator class
 /// </summary>
 /// <param name="language">The language.</param>
 public PocoEntityClassGenerator(IProgrammingLanguageStrategy language)
 {
     ExceptionUtilities.CheckArgumentNotNull(language, "language");
     this.language   = language;
     this.PocoOption = PocoOption.None;
 }
        /// <summary>
        /// Generates the client-side proxy classes then calls the given callback
        /// </summary>
        /// <param name="continuation">The async continuation to report completion on</param>
        /// <param name="serviceRoot">The root uri of the service</param>
        /// <param name="model">The model for the service</param>
        /// <param name="language">The language to generate code in</param>
        /// <param name="onCompletion">The action to invoke with the generated code</param>
        public void GenerateClientCode(IAsyncContinuation continuation, Uri serviceRoot, EntityModelSchema model, IProgrammingLanguageStrategy language, Action <string> onCompletion)
        {
            ExceptionUtilities.CheckArgumentNotNull(continuation, "continuation");
            ExceptionUtilities.CheckArgumentNotNull(serviceRoot, "serviceRoot");
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckArgumentNotNull(language, "language");
            ExceptionUtilities.CheckArgumentNotNull(onCompletion, "onCompletion");
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            // because the product code-gen does not produce this overload of the DataServiceContext constructor, we need to add it ourselves
            // namespace <contextNamespace>
            // {
            //   partial class <contextType>
            //   {
            //     public <contextType>(Uri serviceUri, DataServiceProtocolVersion maxProtocolVersion)
            //       : base(serviceUri, maxProtocolVersion)
            //     {
            //     }
            //   }
            // }
            var compileUnit      = new CodeCompileUnit();
            var contextNamespace = compileUnit.AddNamespace(model.EntityTypes.First().NamespaceName);
            var contextType      = contextNamespace.DeclareType(model.EntityContainers.Single().Name);

            contextType.IsPartial = true;

            contextType.AddConstructor()
            .WithArgument(Code.TypeRef <Uri>(), "serviceUri")
            .WithArgument(Code.TypeRef("Microsoft.OData.Client.ODataProtocolVersion"), "maxProtocolVersion")
            .WithBaseConstructorArgument(Code.Variable("serviceUri"))
            .WithBaseConstructorArgument(Code.Variable("maxProtocolVersion"));

            string constructorOverload = language.CreateCodeGenerator().GenerateCodeFromNamespace(contextNamespace);

            this.DataServiceBuilder.BeginGenerateClientLayerCode(
                serviceRoot.OriginalString,
                this.DesignVersion,
                this.ClientVersion,
                language.FileExtension,
                result =>
            {
                AsyncHelpers.CatchErrors(
                    continuation,
                    () =>
                {
                    string errorMessage;
                    string clientCode = this.DataServiceBuilder.EndGenerateClientLayerCode(out errorMessage, result);
                    if (errorMessage != null)
                    {
                        throw new TaupoInfrastructureException(errorMessage);
                    }

                    // add the extra constructor overload we generated above
                    clientCode = string.Concat(clientCode, Environment.NewLine, constructorOverload);

                    onCompletion(clientCode);

                    continuation.Continue();
                });
            },
                null);
        }
        /// <summary>
        /// Generates the client-side proxy classes then calls the given callback
        /// </summary>
        /// <param name="continuation">The async continuation to report completion on</param>
        /// <param name="serviceRoot">The root uri of the service</param>
        /// <param name="model">The model for the service</param>
        /// <param name="language">The language to generate code in</param>
        /// <param name="onCompletion">The action to invoke with the generated code</param>
        public void GenerateClientCode(IAsyncContinuation continuation, Uri serviceRoot, EntityModelSchema model, IProgrammingLanguageStrategy language, Action<string> onCompletion)
        {
            ExceptionUtilities.CheckArgumentNotNull(continuation, "continuation");
            ExceptionUtilities.CheckArgumentNotNull(serviceRoot, "serviceRoot");
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckArgumentNotNull(language, "language");
            ExceptionUtilities.CheckArgumentNotNull(onCompletion, "onCompletion");
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            // because the product code-gen does not produce this overload of the DataServiceContext constructor, we need to add it ourselves
            // namespace <contextNamespace>
            // {
            //   partial class <contextType>
            //   {
            //     public <contextType>(Uri serviceUri, DataServiceProtocolVersion maxProtocolVersion)
            //       : base(serviceUri, maxProtocolVersion)
            //     {
            //     }
            //   }
            // }
            var compileUnit = new CodeCompileUnit();
            var contextNamespace = compileUnit.AddNamespace(model.EntityTypes.First().NamespaceName);
            var contextType = contextNamespace.DeclareType(model.EntityContainers.Single().Name);
            contextType.IsPartial = true;

            contextType.AddConstructor()
                .WithArgument(Code.TypeRef<Uri>(), "serviceUri")
                .WithArgument(Code.TypeRef("Microsoft.OData.Client.ODataProtocolVersion"), "maxProtocolVersion")
                .WithBaseConstructorArgument(Code.Variable("serviceUri"))
                .WithBaseConstructorArgument(Code.Variable("maxProtocolVersion"));

            string constructorOverload = language.CreateCodeGenerator().GenerateCodeFromNamespace(contextNamespace);

#if !WIN8
            this.DataServiceBuilder.BeginGenerateClientLayerCode(
                serviceRoot.OriginalString,
                this.DesignVersion,
                this.ClientVersion,
                language.FileExtension,
                result =>
                {
                    AsyncHelpers.CatchErrors(
                        continuation,
                        () =>
                        {
                            string errorMessage;
                            string clientCode = this.DataServiceBuilder.EndGenerateClientLayerCode(out errorMessage, result);
                            if (errorMessage != null)
                            {
                                throw new TaupoInfrastructureException(errorMessage);
                            }

                            // add the extra constructor overload we generated above
                            clientCode = string.Concat(clientCode, Environment.NewLine, constructorOverload);

                            onCompletion(clientCode);

                            continuation.Continue();
                        });
                },
                null);
#else
            var task = this.DataServiceBuilder.GenerateClientLayerCodeAsync(
                new GenerateClientLayerCodeRequest(
                    serviceRoot.OriginalString,
                    this.DesignVersion,
                    this.ClientVersion,
                    language.FileExtension));
            task.Wait();
            var result = task.Result;
            string clientCode = result.GenerateClientLayerCodeResult;
            string errorMessage = result.errorLog;
            if (errorMessage != null)
            {
                throw new TaupoInfrastructureException(errorMessage);
            }

            // add the extra constructor overload we generated above
            clientCode = string.Concat(clientCode, Environment.NewLine, constructorOverload);

            onCompletion(clientCode);

            continuation.Continue();
#endif
        }
        /// <summary>
        /// Gets the reference assemblies needed to compile a client for the given model and language
        /// </summary>
        /// <param name="model">The model being generated</param>
        /// <param name="language">The current language</param>
        /// <returns>The list of reference assemblies</returns>
        internal static IEnumerable<string> GetClientReferenceAssemblies(EntityModelSchema model, IProgrammingLanguageStrategy language)
        {
            bool isVB = language.LanguageName == "VB";
            IEnumerable<string> languageSpecificReferences = isVB ? referenceAssemblies.Where(l => l != "mscorlib.dll") : referenceAssemblies;

            if (model.HasSpatialFeatures())
            {
                languageSpecificReferences = languageSpecificReferences.Concat(DataFxAssemblyRef.File.SpatialCore);
            }

            return languageSpecificReferences;
        }
Example #10
0
        /// <summary>
        /// Generates the client-side proxy classes then calls the given callback
        /// </summary>
        /// <param name="continuation">The async continuation to report completion on</param>
        /// <param name="serviceRoot">The root uri of the service</param>
        /// <param name="model">The model for the service</param>
        /// <param name="language">The language to generate code in</param>
        /// <param name="onCompletion">The action to invoke with the generated code</param>
        public void GenerateClientCode(IAsyncContinuation continuation, Uri serviceRoot, EntityModelSchema model, IProgrammingLanguageStrategy language, Action <string> onCompletion)
        {
            ExceptionUtilities.CheckArgumentNotNull(continuation, "continuation");
            ExceptionUtilities.CheckArgumentNotNull(serviceRoot, "serviceRoot");
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckArgumentNotNull(language, "language");
            ExceptionUtilities.CheckArgumentNotNull(onCompletion, "onCompletion");

            var compileUnit = new CodeCompileUnit();

            this.GenerateObjectLayer(compileUnit, model);
            this.GenerateContextType(compileUnit, model);

            string clientCode = language.CreateCodeGenerator().GenerateCodeFromCompileUnit(compileUnit);

            onCompletion(clientCode);
            continuation.Continue();
        }
        internal static IEnumerable <string> GetAssembliesToReference(EntityModelSchema model, IProgrammingLanguageStrategy language)
        {
            if (language.LanguageName != "VB")
            {
                yield return("mscorlib.dll");
            }

            yield return("System.dll");

            yield return("System.Core.dll");

#if SILVERLIGHT && !WIN8
            yield return(DataFxAssemblyRef.File.DataServicesSilverlightClient);
#else
            yield return(DataFxAssemblyRef.File.DataServicesClient);
#endif
            yield return(DataFxAssemblyRef.File.ODataLib);

            yield return(DataFxAssemblyRef.File.EntityDataModel);

            if (model.HasSpatialFeatures())
            {
                yield return(DataFxAssemblyRef.File.SpatialCore);
            }

#if SILVERLIGHT && !WIN8
            yield return("System.Windows.dll");

            yield return("Microsoft.Test.Taupo.SL.dll");

            yield return("Microsoft.Test.Taupo.Astoria.SL.dll");

            yield return("Microsoft.Test.Taupo.Query.SL.dll");
#else
            yield return("Microsoft.Test.Taupo.dll");

            yield return("Microsoft.Test.Taupo.Astoria.dll");

            yield return("Microsoft.Test.Taupo.Query.dll");
#endif
        }
 /// <summary>
 /// Initializes a new instance of the PocoEntityClassGenerator class
 /// </summary>
 /// <param name="language">The language.</param>
 public PocoEntityClassGenerator(IProgrammingLanguageStrategy language)
 {
     ExceptionUtilities.CheckArgumentNotNull(language, "language");
     this.language = language;
     this.PocoOption = PocoOption.None;
 }