Beispiel #1
0
        public void ProjectCountSample()
        {
            var query = new ComplexQuery(
                "id, englishName",
                "title eq 'moeta' and property/field ne 'val' or number ge 5 and (likes ne 3 or special lt 3)",
                30,
                null,
                "_created asc, createdDateTime desc",
                "dev",
                true);
            var projectTranslator = new ProjectTranslator();
            var sqlQuery          = projectTranslator.Translate(query);

            Assert.AreEqual("select count(1)  from c where c.title = 'moeta' and c.property.field <> 'val' or c.number >= 5 and (c.likes <> 3 or c.special < 3) and c.entity = 'kotori/project' and c.instance = 'dev' ", sqlQuery);
        }
Beispiel #2
0
        public void ProjectSelectSampleWithTransformation()
        {
            var query = new ComplexQuery(
                "",
                "id eq 'yuri-yuri'",
                null,
                null,
                null,
                "dev",
                false);
            var projectTranslator = new ProjectTranslator();
            var sqlQuery          = projectTranslator.Translate(query);

            Assert.AreEqual("select * from c where c.identifier = 'kotori://api/projects/yuri-yuri' and c.entity = 'kotori/project' and c.instance = 'dev' ", sqlQuery);
        }
Beispiel #3
0
        public void ProjectSelectSample3()
        {
            var query = new ComplexQuery(
                "a,b,c",
                null,
                null,
                null,
                null,
                "dev",
                false);
            var projectTranslator = new ProjectTranslator();
            var sqlQuery          = projectTranslator.Translate(query);

            Assert.AreEqual("select c.a,c.b,c.c from c where c.entity = 'kotori/project' and c.instance = 'dev' ", sqlQuery);
        }
Beispiel #4
0
        public void ProjectSelectSample()
        {
            var query = new ComplexQuery(
                "id, robot",
                "title eq 'moeta'",
                30,
                null,
                null,
                "dev",
                false);
            var projectTranslator = new ProjectTranslator();
            var sqlQuery          = projectTranslator.Translate(query);

            Assert.AreEqual("select top 30 c.identifier, c.robot from c where c.title = 'moeta' and c.entity = 'kotori/project' and c.instance = 'dev' ", sqlQuery);
        }
Beispiel #5
0
 private void TranslateSource(out TemporaryDirectory td, out TempFileCollection tfc, out List <string> files, out Stack <IIntermediateProject> partialCompletions, out Dictionary <IIntermediateModule, List <string> > moduleFiles)
 {
     ProjectTranslator.WriteProject(this.Project, this.Translator, Path.Combine(TemporaryFileHelper.GetTemporaryPath(), "Oilexer"), out td, out tfc, out files, out partialCompletions, out moduleFiles, options.KeepTempFiles, this.translator.Options.AllowPartials);
 }
Beispiel #6
0
        private void CompileToResponse(TemporaryDirectory td, TempFileCollection tfc, List <string> files, Stack <IIntermediateProject> partialCompletions, Dictionary <IIntermediateModule, List <string> > moduleFiles, out IIntermediateCompilerCommandLineModule module, out List <string> commandSequences, out string response)
        {
            module           = (IIntermediateCompilerCommandLineModule)this.Module;
            commandSequences = new List <string>();
            if (this.Project.OutputType == ProjectOutputType.ConsoleApplication || this.Project.OutputType == ProjectOutputType.WindowsApplication)
            {
                IMethodMember entryPoint = Project.EntryPoint;
                if (entryPoint != null && ((IDeclaredType)entryPoint.ParentTarget).Module != Project.RootModule)
                {
                    IClassType entryPointCover = Project.Partials.AddNew().DefaultNameSpace.Classes.AddNew(Project.Classes.GetUniqueName("_cover"));

                    entryPointCover.Attributes.AddNew(typeof(CompilerGeneratedAttribute));
                    entryPointCover.IsStatic    = true;
                    entryPointCover.AccessLevel = DeclarationAccessLevel.Internal;
                    entryPointCover.Module      = Project.RootModule;
                    IMethodMember coverPoint = entryPointCover.Methods.AddNew(new TypedName(entryPoint.Name, entryPoint.ReturnType));
                    coverPoint.Attributes.AddNew(typeof(CompilerGeneratedAttribute));
                    foreach (IMethodParameterMember impm in entryPoint.Parameters.Values)
                    {
                        coverPoint.Parameters.AddNew(new TypedName(impm.Name, impm.ParameterType));
                    }

                    coverPoint.Summary = "Entrypoint cover method, invokes the true entrypoint in a different module.";
                    IMethodInvokeExpression imie = entryPoint.GetReference().Invoke();
                    foreach (IMethodParameterMember impm in entryPoint.Parameters.Values)
                    {
                        imie.ArgumentExpressions.Add(impm.GetReference());
                    }
                    if (!(coverPoint.ReturnType.Equals(typeof(void).GetTypeReference())))
                    {
                        coverPoint.Return(imie);
                    }
                    else
                    {
                        coverPoint.CallMethod(imie);
                    }
                    string entryFile = ProjectTranslator.WriteFile(this.Project, this.Translator, td, tfc, partialCompletions, entryPointCover, ".cs", "    ");
                    moduleFiles[Project.RootModule].Add(entryFile);
                    files.Add(entryFile);
                    commandSequences.Add(module.GetEntryPointCommand(coverPoint, this.Options));
                    this.Project.Partials.Remove((IIntermediateProject)entryPointCover.ParentTarget.ParentTarget);
                }
                else
                {
                    commandSequences.Add(module.GetEntryPointCommand(entryPoint, this.Options));
                }
            }
            List <string> moduleCommandLines = new List <string>();

            foreach (IIntermediateModule iim in this.Project.Modules.Values)
            {
                string[] moduleFileNames = new string[moduleFiles[iim].Count + (iim == this.Project.RootModule ? this.Options.ExtraFiles.Count() : 0)];
                for (int i = 0; i < moduleFiles[iim].Count; i++)
                {
                    moduleFileNames[i] = moduleFiles[iim][i];
                }
                if (iim == this.Project.RootModule)
                {
                    int exC   = this.Options.ExtraFiles.Count();
                    int exO   = moduleFiles[iim].Count;
                    int index = exO;
                    foreach (var extraFile in this.Options.ExtraFiles)
                    {
                        var tempFile = td.Directories.GetTemporaryDirectory(iim.Name).Files.GetTemporaryFile(Path.GetFileName(extraFile));
                        tempFile.CloseStream();
                        File.Copy(extraFile, tempFile.FileName, true);
                        moduleFileNames[index++] = tempFile.FileName;
                    }
                }
                moduleCommandLines.AddRange(module.GetModuleCommand(iim, moduleFileNames, null, this.Options));
            }
            bool allowPartials = this.Translator.Options.AllowPartials;

            this.Translator.Options.AllowPartials = false;
            ProjectDependencyReport pdr = new ProjectDependencyReport(this.Project, this.Translator.Options);

            pdr.Begin();
            this.Translator.Options.AllowPartials = allowPartials;
            if (module.Supports(CompilerModuleSupportFlags.Optimization))
            {
                commandSequences.Add(module.GetOptimizationCommand(this.Options.Optimize, this.Options));
            }
            if (module.Supports(CompilerModuleSupportFlags.DebuggerSupport))
            {
                commandSequences.Add(module.GetDebugCommand(this.Options.DebugSupport, this.Options));
            }
            if (module.Supports(CompilerModuleSupportFlags.XMLDocumentation))
            {
                commandSequences.Add(module.GetXMLDocumentationCommand(this.Options.GenerateXMLDocs, this.Options));
            }
            commandSequences.AddRange(module.GetReferencesCommand(Tweaks.TranslateArray(pdr.CompiledAssemblyReferences.ToArray(), a =>
            {
                return(a.Location);
            }), this.Options));
            if (module.Supports(CompilerModuleSupportFlags.MultiFileAssemblies))
            {
                commandSequences.AddRange(moduleCommandLines.ToArray());
            }
            else
            {
                commandSequences.Add(module.GetOutputCommand(this.Options.Target, this.Options));
                commandSequences.AddRange(module.GetSourcesCommand(files.ToArray(), this.Options));
            }
            response = null;
            if (module.Supports(CompilerModuleSupportFlags.ResponseFile))
            {
                response = tfc.AddExtension("response");
                StreamWriter responseWriter = new StreamWriter(new FileStream(response, FileMode.Create));
                //string[] lines = fullCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in commandSequences)
                {
                    responseWriter.WriteLine(s);
                }
                responseWriter.Flush();
                responseWriter.Close();
            }
        }