Ejemplo n.º 1
0
 public void Dispose()
 {
     if (_codeLanguageHelper != null)
     {
         _codeLanguageHelper.Dispose();
         _codeLanguageHelper = null;
     }
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (_codeLanguageHelper != null)
     {
         _codeLanguageHelper.Dispose();
         _codeLanguageHelper = null;
     }
 }
Ejemplo n.º 3
0
        protected internal CodeLayerBuilderBase(Workspace workspace, WorkspaceLanguage language, string codefilePath)
        {
            _workspace = workspace;
            _language = language;
            _codeFilePath = codefilePath;

            _writer = new StreamWriter(_codeFilePath);

            _codeLanguageHelper = new CSharpCodeLanguageHelper(_writer);
        }
Ejemplo n.º 4
0
        protected internal CodeLayerBuilderBase(Workspace workspace, WorkspaceLanguage language, string codefilePath)
        {
            _workspace    = workspace;
            _language     = language;
            _codeFilePath = codefilePath;

            _writer = new StreamWriter(_codeFilePath);

            _codeLanguageHelper = new CSharpCodeLanguageHelper(_writer);
        }
Ejemplo n.º 5
0
        public override void ApplyFriendlyFeeds()
        {
            if (GenerateServerMappings)
            {
                string partialClassPath = Path.Combine(Path.Combine(this.DataService.DestinationFolder, "App_Code"), this.ObjectLayerOutputFileName.Replace("InMemory", "InMemoryPartial"));
                IOUtil.EnsureFileDeleted(partialClassPath);

                StreamWriter textStream = IOUtil.CreateTextStream(partialClassPath);
                ReflectionProvider.CSharpCodeLanguageHelper codeHelper
                    = new ReflectionProvider.CSharpCodeLanguageHelper(textStream);

                WritePartialClassAttributes(this.ContextNamespace, codeHelper);
                textStream.Close();

                this.ObjectLayerFileNames.Add(partialClassPath);
            }
            if (GenerateClientTypes)
            {
                GenerateAndLoadClientTypes();
                PopulateClientTypes();
            }
            this.RestoreData();
        }
Ejemplo n.º 6
0
        public override void ApplyFriendlyFeeds()
        {
            if (GenerateServerMappings)
            {
                string partialClassPath = Path.Combine(Path.Combine(this.DataService.DestinationFolder, "App_Code"), this.ObjectLayerOutputFileName.Replace("LinqToSql", "LinqToSqlPartial"));
                if (File.Exists(partialClassPath))
                {
                    IOUtil.EnsureFileDeleted(partialClassPath);
                }

                StreamWriter textStream = File.CreateText(partialClassPath);
                ReflectionProvider.CSharpCodeLanguageHelper codeHelper
                    = new ReflectionProvider.CSharpCodeLanguageHelper(textStream);

                WritePartialClassAttributes(this.ContextNamespace, codeHelper);
                textStream.Close();
            }
            if (GenerateClientTypes || GenerateClientTypesManually)
            {
                GenerateAndLoadClientTypes();
            }
            PopulateClientTypes();
        }
Ejemplo n.º 7
0
        public override void ApplyFriendlyFeeds()
        {
            if (GenerateServerMappings)
            {
                string partialClassPath = Path.Combine(Path.Combine(this.DataService.DestinationFolder, "App_Code"), this.ObjectLayerOutputFileName.Replace("LinqToSql", "LinqToSqlPartial"));
                if (File.Exists(partialClassPath))
                {
                    IOUtil.EnsureFileDeleted(partialClassPath);
                }

                StreamWriter textStream = File.CreateText(partialClassPath);
                ReflectionProvider.CSharpCodeLanguageHelper codeHelper
                    = new ReflectionProvider.CSharpCodeLanguageHelper(textStream);

                WritePartialClassAttributes(this.ContextNamespace, codeHelper);
                textStream.Close();
            }
            if (GenerateClientTypes || GenerateClientTypesManually)
            {
                GenerateAndLoadClientTypes();
            }
            PopulateClientTypes();

        }
Ejemplo n.º 8
0
 // Apply as code
 public virtual void Apply(CSharpCodeLanguageHelper codeHelper)
 {
     codeHelper.WriteAttribute(this.Name, namedParams, orderedParams.ToArray());
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generate the client types for a given service 
        /// </summary>
        protected void GenerateAndLoadClientTypes()
        {
            if (GenerateClientTypes)
            {
                string commonProgramFiles = Environment.GetEnvironmentVariable("CommonProgramFiles");
                string t4TransformToolPath = commonProgramFiles + "\\Microsoft Shared\\TextTemplating\\11.0\\TextTransform.exe";
                string newFileNameSeed = Guid.NewGuid().ToString();
                string outFilePath = Path.Combine(Environment.CurrentDirectory, newFileNameSeed + ".cs");
                string partialClassFilePath = Path.Combine(Environment.CurrentDirectory, newFileNameSeed + "Partial.cs");
                string dllOutputPath = Path.Combine(Environment.CurrentDirectory, newFileNameSeed + ".dll");
                string t4TemplatePath = Path.Combine(Environment.CurrentDirectory, "ODataT4CodeGenerator.tt");

                ClientTypesNamespace = this.Name;

                try
                {
                     string arguments = "-out \"" + outFilePath
                        + "\" -a !!MetadataDocumentUri!" + this.ServiceUri
                        + " -a !!UseDataServiceCollection!False"
                        + " -a !!TargetLanguage!CSharp"
                        + " -p \"" + Environment.CurrentDirectory + "\" \"" + t4TemplatePath + "\"";

                    var returnValue = Execute(t4TransformToolPath, arguments, null);
                    AstoriaTestLog.Compare(string.IsNullOrEmpty(returnValue), "Error \n" + returnValue);
                }
                catch (Exception excp)
                {
                    string activationError = excp.Message;
                    System.Net.WebRequest webRequest = System.Net.WebRequest.Create(this.ServiceUri + "/$metadata");
                    webRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    try
                    {
                        using (System.Net.WebResponse response = webRequest.GetResponse()) { }
                    }
                    catch (System.Net.WebException inner)
                    {
                        using (Stream respStream = inner.Response.GetResponseStream())
                        {
                            StreamReader strReader = new StreamReader(respStream);
                            activationError += Environment.NewLine + strReader.ReadToEnd();
                            AstoriaTestLog.WriteLineIgnore(activationError);
                            throw new TestException(TestResult.Unknown, activationError);
                        }
                    }

                    throw (new TestSkippedException("Failed to generate client types for server :" + this.ServiceUri + "  because of error \r\n" + activationError));
                }

                AstoriaTestLog.Compare(File.Exists(outFilePath), "Cannot find code generated file " + outFilePath);
                List<string> filesToCompile = new List<string>();

                if (GenerateClientTypesManually)
                {
                    StreamWriter textStream = File.CreateText(partialClassFilePath);
                    ReflectionProvider.CSharpCodeLanguageHelper codeHelper
                        = new ReflectionProvider.CSharpCodeLanguageHelper(textStream);
                    if (this.ContextNamespace == "Aruba")
                        WritePartialClassAttributes("ArubaClient", codeHelper);
                    else
                        WritePartialClassAttributes(this.ContextNamespace, codeHelper);
                    textStream.Close();

                    filesToCompile.Add(partialClassFilePath);
                }
                filesToCompile.Add(outFilePath);

                if (this.ContextNamespace == "Aruba")
                {
                    string originalCode = File.ReadAllText(outFilePath);
                    if (AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.Edm))
                    {
                        originalCode = originalCode.Replace("namespace Aruba", "namespace ArubaClient");
                    }
                    if (AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.NonClr))
                    {
                        originalCode = originalCode.Replace("namespace Aruba.NonClr", "namespace ArubaClient");
                        originalCode = originalCode.Replace("namespace northwind.NonClr", "namespace northwind");
                    }
                    if (AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.LinqToSql)
                        && (!AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.Edm)))
                    {
                        originalCode = originalCode.Replace(String.Format("namespace {0}", this.ContextNamespace), String.Format("namespace {0}ClientLTS", this.ContextNamespace));

                    }
                    FileStream fsOriginalCode = File.Open(outFilePath, FileMode.OpenOrCreate);
                    byte[] Code = System.Text.Encoding.UTF8.GetBytes(originalCode);
                    fsOriginalCode.Write(Code, 0, Code.Length);
                    fsOriginalCode.Close();
                }
                else if (
                        AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.LinqToSql)
                        &&
                        !AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.Edm)
                        )
                {
                    string originalCode = File.ReadAllText(outFilePath);
                    originalCode = originalCode.Replace(String.Format("namespace {0}", this.ContextNamespace), String.Format("namespace {0}ClientLTS", this.ContextNamespace));
                    FileStream fsOriginalCode = File.Open(outFilePath, FileMode.Open);
                    byte[] Code = System.Text.Encoding.UTF8.GetBytes(originalCode);
                    fsOriginalCode.Write(Code, 0, Code.Length);
                    fsOriginalCode.Close();
                }

                //Compile the client types into an assembly
                Util.CodeCompilerHelper.CompileCodeFiles(
                    filesToCompile.ToArray(),
                    dllOutputPath,
                    new string[] { this.DataLayerProviderKind.ToString() },
                    this.Language,
                    ReferencedDlls);

                //Load the newly created assembly into this app domain
                ClientTypesAssembly = Assembly.Load(Path.GetFileNameWithoutExtension(dllOutputPath));


            }
        }
Ejemplo n.º 10
0
        protected void WritePartialClassAttributes(string ns, CSharpCodeLanguageHelper codeHelper)
        {
            codeHelper.WriteStartNamespace(ns);

            foreach (ResourceType resourceType in this.ServiceContainer.ResourceTypes)
            {
                foreach (ResourceAttribute resourceAttrib in resourceType.Facets.Attributes)
                {
                    resourceAttrib.Apply(codeHelper);
                }

                codeHelper.WriteLine();
                codeHelper.WriteBeginClass(resourceType.Name, null, null, false);
                codeHelper.WriteEndClass(resourceType.Name);
                codeHelper.WriteLine();
            }

            codeHelper.WriteEndNamespace(this.ContextNamespace);
        }