Example #1
0
 private void SetWalkStartFor(CodeRegion region, int outputLineCnt)
 {
     _walkthroughRanges[region.Name] = new LinesRange
     {
         Start = outputLineCnt + 1
     };
 }
Example #2
0
        private void ExecuteTest(CodeRegion models, CodeRegion input, CodeRegion expected, Location location, string message)
        {
            var inputCode    = string.Join("\r\n", models.Lines.AddRange(input.Lines));
            var expectedCode = string.Join("\r\n", models.Lines.AddRange(expected.Lines));

            var offsetLocation = new Location(location.Line + models.Lines.Count, location.Column);

            var expectedDiagnostic = new DiagnosticResult
            {
                Id        = NotAutoMapperAnalyzer.DiagnosticId,
                Message   = message,
                Severity  = Microsoft.CodeAnalysis.DiagnosticSeverity.Info,
                Locations = new[] { new DiagnosticResultLocation
                                    (
                                        path: "Test0.cs",
                                        line: offsetLocation.Line,
                                        column: offsetLocation.Column
                                    ) }
            };

            VerifyCSharpDiagnostic
            (
                source: inputCode,
                expected: expectedDiagnostic
            );

            VerifyCSharpFix
            (
                oldSource: inputCode,
                newSource: expectedCode,
                allowNewCompilerDiagnostics: true
            );
        }
Example #3
0
        public void TestSourceFiles()
        {
            var files = Directory.EnumerateFiles("TestCases", "*.cs");

            foreach (var f in files)
            {
                var content     = File.ReadAllLines(f);
                var topComments = content.TakeWhile(x => Regex.IsMatch(x, "^//.*$")).ToImmutableList();

                var location = Location.FromComments(topComments);
                var message  = MessageFromComments(topComments);
                var regions  = CodeRegion.FromSource(content.ToImmutableList());

                var models   = regions.Where(x => x.Name.Equals("Models", StringComparison.OrdinalIgnoreCase)).ToImmutableList();
                var expected = regions.Single(x => x.Name.Equals("Expected", StringComparison.OrdinalIgnoreCase));
                var inputs   = regions.Where(x => x.Name.Equals("Input", StringComparison.OrdinalIgnoreCase)).ToImmutableList();

                foreach (var model in models)
                {
                    foreach (var input in inputs)
                    {
                        ExecuteTest(model, input, expected, location, message);
                    }
                }
            }
        }
 public void ReportLookupTypeError(CodeRegion environment, string name, Type new_type, Type existing_type)
 {
     if (existing_type == 0) {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: No possible type for “{5}”. Expression should have types: {6}.", environment.FileName, environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name, new_type);
     } else {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: Lookup for “{5}” has conflicting types: {6} versus {7}.", environment.FileName, environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name, new_type, existing_type);
     }
 }
 public void ReportExpressionTypeError(CodeRegion where, Type new_type, Type existing_type)
 {
     if (existing_type == 0) {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: No possible type for {5}. Expression should have types: {6}.", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, where.PrettyName, new_type);
     } else {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: Conflicting types for {5}: {6} versus {7}.", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, where.PrettyName, new_type, existing_type);
     }
 }
Example #6
0
 public void ReportExpressionTypeError(CodeRegion where, Type new_type, Type existing_type)
 {
     if (existing_type == 0)
     {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: No possible type for {5}. Expression should have types: {6}.", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, where.PrettyName, new_type);
     }
     else
     {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: Conflicting types for {5}: {6} versus {7}.", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, where.PrettyName, new_type, existing_type);
     }
 }
Example #7
0
 public void ReportLookupTypeError(CodeRegion environment, string name, Type new_type, Type existing_type)
 {
     if (existing_type == 0)
     {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: No possible type for “{5}”. Expression should have types: {6}.", environment.FileName, environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name, new_type);
     }
     else
     {
         Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: Lookup for “{5}” has conflicting types: {6} versus {7}.", environment.FileName, environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name, new_type, existing_type);
     }
 }
Example #8
0
 public void ReportExpressionTypeError(CodeRegion where, Type new_type, Type existing_type)
 {
     MakeDirty();
     if (existing_type == 0)
     {
         buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>No possible type for {4}. Expression should have types: {5}.</td></tr>", where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, where.PrettyName, new_type);
     }
     else
     {
         buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>Conflicting types for {4}: {5} versus {6}.</td></tr>", where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, where.PrettyName, new_type, existing_type);
     }
 }
        public override void VisitRegionDirectiveTrivia(RegionDirectiveTriviaSyntax node)
        {
            var region = new CodeRegion
            {
                StartIndex = node.FullSpan.Start,
                Name       = ParseRegionName(node)
            };

            _stack.Push(region);

            base.VisitRegionDirectiveTrivia(node);
        }
Example #10
0
 public void ReportLookupTypeError(CodeRegion environment, string name, Type new_type, Type existing_type)
 {
     MakeDirty();
     if (existing_type == 0)
     {
         buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>No possible type for “{4}”. Expression should have types: {5}.</td></tr>", environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name, new_type);
     }
     else
     {
         buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>Lookup for “{4}” has conflicting types: {5} versus {6}.</td></tr>", environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name, new_type, existing_type);
     }
 }
Example #11
0
        public ApiGenerator CreateChild(string name, CodeRegion region, Type type, bool informative)
        {
            var node = Document.CreateElement("o_0:attr", Document.DocumentElement.NamespaceURI);

            node.SetAttribute("name", name);
            node.SetAttribute("startline", region.StartRow.ToString());
            node.SetAttribute("startcol", region.StartColumn.ToString());
            node.SetAttribute("endline", region.EndRow.ToString());
            node.SetAttribute("endcol", region.EndColumn.ToString());
            node.SetAttribute("informative", informative ? "true" : "false");
            this.node.AppendChild(node);

            string base_name = name;
            var    it        = 0;

            do
            {
                var def_node = Document.CreateElement("o_0:def", Document.DocumentElement.NamespaceURI);
                def_node.AppendChild(Document.CreateTextNode(base_name));
                node.AppendChild(def_node);
                if (it < names.Length)
                {
                    base_name = names[it] + "." + base_name;
                }
            } while (it++ < names.Length);
            string[] new_names;
            if ((type & Type.Template) != 0)
            {
                new_names = new string[0];
            }
            else
            {
                new_names = new string[names.Length + 1];
                names.CopyTo(new_names, 0);
                new_names[names.Length] = name;
            }

            if (type != NameInfo.AnyType)
            {
                foreach (var t in Enum.GetValues(typeof(Type)).Cast <Type>())
                {
                    if ((type & t) == 0)
                    {
                        continue;
                    }
                    var type_node = Document.CreateElement("o_0:type", Document.DocumentElement.NamespaceURI);
                    type_node.AppendChild(Document.CreateTextNode(t == Type.Unit ? "Null" : t.ToString()));
                    node.AppendChild(type_node);
                }
            }
            return(new ApiGenerator(Document, node, new_names));
        }
Example #12
0
        private void AppendDemoRegion(CodeRegion demoRegion)
        {
            var demoCode = CodeSlicer.CopyCodeWithWalkthroughs(new CodeSlicer.CodeWithWalkthroughsInput
            {
                Start           = demoRegion.LineStart,
                End             = demoRegion.LineEnd,
                LineCountOffset = _lineCountOffset
            });

            _outputCode.Append(demoCode.Code);
            _lineCountOffset += demoCode.LineCount;

            CopyWalkthroughs(demoCode.WalkthroughRanges);
        }
Example #13
0
        public IEnumerable <ICodeRegion> GetRegions(string src)
        {
            var ret = new List <ICodeRegion>();

            var lines = src.Split(new char[] { '\n' });

            CodeRegion currentCodeRegion = null;
            var        regionStack       = new Stack <CodeRegion>();

            int lineNumber = 0;

            foreach (var line in lines)
            {
                if (line.Contains("#region"))
                {
                    // start a new region
                    var start = line.IndexOf("#region") + "#region".Length;

                    var name = line.Substring(start).Trim();

                    currentCodeRegion           = new CodeRegion();
                    currentCodeRegion.Name      = name;
                    currentCodeRegion.LineStart = lineNumber;

                    // add as child of the last item in the stack
                    if (regionStack.Count > 0 && regionStack.Peek() != null)
                    {
                        regionStack.Peek().Add(currentCodeRegion);
                    }
                    else
                    {
                        ret.Add(currentCodeRegion);
                    }
                    regionStack.Push(currentCodeRegion);
                }
                if (line.Contains("#endregion"))
                {
                    if (regionStack.Peek() != null)
                    {
                        var c = regionStack.Pop();

                        c.LineEnd = lineNumber;
                    }
                }
                lineNumber++;
            }
            return(ret);
        }
Example #14
0
 public void ReportForbiddenNameAccess(CodeRegion environment, string name)
 {
     Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: Lookup for “{5}” is forbidden.", environment.FileName, environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name);
 }
Example #15
0
 public void ReportRawError(CodeRegion where, string message)
 {
     MakeDirty();
     buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>{4}</td></tr>", where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, message);
 }
Example #16
0
 public void ReportExpressionTypeError(CodeRegion where, Type new_type, Type existing_type)
 {
     AnalyseDirty = true;
 }
Example #17
0
 public void ReportLookupTypeError(CodeRegion environment, string name, Type new_type, Type existing_type)
 {
     AnalyseDirty = true;
 }
Example #18
0
 public void ReportExpressionTypeError(CodeRegion where, Type new_type, Type existing_type)
 {
     AnalyseDirty = true;
 }
Example #19
0
 public void ReportRawError(CodeRegion where, string message)
 {
     AnalyseDirty = true;
 }
Example #20
0
 public void ReportSingleTypeError(CodeRegion where, Type type)
 {
     Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: The expression has types {5}, but it must only have one.", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, type);
 }
 public void ReportForbiddenNameAccess(CodeRegion environment, string name)
 {
     Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: Lookup for “{5}” is forbidden.", environment.FileName, environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name);
 }
Example #22
0
 protected override void Visit(CodeRegion region)
 {
     VisitList(region.Members);
 }
Example #23
0
 public void ReportSingleTypeError(CodeRegion where, Type type)
 {
     MakeDirty();
     buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>The expression has types {4}, but it must only have one.</td></tr>", where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, type);
 }
Example #24
0
 internal RegionBuilder(CodeRegion region)
 {
     Region = region;
 }
 public void ReportRawError(CodeRegion where, string message)
 {
     Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: {5}", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, message);
 }
Example #26
0
 public void ReportSingleTypeError(CodeRegion where, Type type)
 {
     AnalyseDirty = true;
 }
 public void ReportSingleTypeError(CodeRegion where, Type type)
 {
     Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: The expression has types {5}, but it must only have one.", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, type);
 }
Example #28
0
 public void ReportForbiddenNameAccess(CodeRegion environment, string name)
 {
     AnalyseDirty = true;
 }
Example #29
0
 public void ReportRawError(CodeRegion where, string message)
 {
     Console.Error.WriteLine("{0}:{1}:{2}-{3}:{4}: {5}", where.FileName, where.StartRow, where.StartColumn, where.EndRow, where.EndColumn, message);
 }
Example #30
0
 public void ReportForbiddenNameAccess(CodeRegion environment, string name)
 {
     AnalyseDirty = true;
 }
Example #31
0
 public void ReportSingleTypeError(CodeRegion where, Type type)
 {
     AnalyseDirty = true;
 }
Example #32
0
 public void ReportLookupTypeError(CodeRegion environment, string name, Type new_type, Type existing_type)
 {
     AnalyseDirty = true;
 }
Example #33
0
 public void ReportForbiddenNameAccess(CodeRegion environment, string name)
 {
     MakeDirty();
     buffer.Write("<tr><td>{0}:{1}-{2}:{3}</td><td>Lookup for “{4}” is forbidden.<td></tr>", environment.StartRow, environment.StartColumn, environment.EndRow, environment.EndColumn, name);
 }
Example #34
0
 public void ReportRawError(CodeRegion where, string message)
 {
     AnalyseDirty = true;
 }
Example #35
0
        //获得单一变量
        private CodeObject GetOneObject()
        {
            CodeObject ret      = null;
            Token      token    = ReadToken();
            bool       not      = false;
            bool       minus    = false;
            bool       negative = false;
            CALC       calc     = CALC.NONE;

            while (true)
            {
                if (token.Type == TokenType.Not)
                {
                    not = true;
                }
                else if (token.Type == TokenType.Minus)
                {
                    minus = true;
                }
                else if (token.Type == TokenType.Negative)
                {
                    negative = true;
                }
                else
                {
                    break;
                }
                token = ReadToken();
            }
            if (token.Type == TokenType.Increment)
            {
                calc  = CALC.PRE_INCREMENT;
                token = ReadToken();
            }
            else if (token.Type == TokenType.Decrement)
            {
                calc  = CALC.PRE_DECREMENT;
                token = ReadToken();
            }
            switch (token.Type)
            {
            case TokenType.Identifier:
                ret = new CodeMember((string)token.Lexeme);
                break;

            case TokenType.Function:
                UndoToken();
                ret = new CodeFunction(ParseFunctionDeclaration(false));
                break;

            case TokenType.LeftPar:
                ret = new CodeRegion(GetObject());
                ReadRightParenthesis();
                break;

            case TokenType.LeftBracket:
                UndoToken();
                ret = GetArray();
                break;

            case TokenType.LeftBrace:
                UndoToken();
                ret = GetTable();
                break;

            case TokenType.Eval:
                ret = GetEval();
                break;

            case TokenType.Null:
                ret = new CodeScriptObject(m_script, null);
                break;

            case TokenType.Boolean:
            case TokenType.Number:
            case TokenType.String:
            case TokenType.SimpleString:
                ret = new CodeScriptObject(m_script, token.Lexeme);
                break;

            default:
                throw new ParserException("Object起始关键字错误 ", token);
            }
            ret.StackInfo = new StackInfo(m_strBreviary, token.SourceLine);
            ret           = GetVariable(ret);
            ret.Not       = not;
            ret.Minus     = minus;
            ret.Negative  = negative;
            if (ret is CodeMember)
            {
                if (calc != CALC.NONE)
                {
                    ((CodeMember)ret).Calc = calc;
                }
                else
                {
                    Token peek = ReadToken();
                    if (peek.Type == TokenType.Increment)
                    {
                        calc = CALC.POST_INCREMENT;
                    }
                    else if (peek.Type == TokenType.Decrement)
                    {
                        calc = CALC.POST_DECREMENT;
                    }
                    else
                    {
                        UndoToken();
                    }
                    if (calc != CALC.NONE)
                    {
                        ((CodeMember)ret).Calc = calc;
                    }
                }
            }
            else if (calc != CALC.NONE)
            {
                throw new ParserException("++ 或者 -- 只支持变量的操作", token);
            }
            return(ret);
        }
Example #36
0
 ScriptObject ParseRegion(CodeRegion region)
 {
     return(ResolveOperand(region.Context));
 }
Example #37
0
        static void Main(string[] args)
        {
            Console.WriteLine("Entity Frameworks CodeGenerationTools Demo Program.\n");

            //I had problems with accessing Dictionary by [] index, so quickly used these
            //to check in normal C# usage.
            //var tc = new TestCollections();
            //tc.TestCollections2();

            try
            {
                //As this program only reads and interprets the XML within the EDMX,
                //there is no need for a ConnectionString in the App.Config and
                //no connection is made to a database.

                //Since this is a test program, let's assume you are executing from .\bin\Debug
                var currentdirectory = Environment.CurrentDirectory;
                var inputFile        = @"..\..\Model1.edmx";
                inputFile = Path.Combine(currentdirectory, inputFile);

                //Demo 1
                //EFFluentUtility is from
                //http://visualstudiogallery.msdn.microsoft.com/5d663b99-ed3b-481d-b7bc-b947d2457e3c
                //By opening the VSIX (DbContextFluentTemplate_V50, which is a ZIP) I've taken a
                //copy of "CSharpDbContextFluent.Mapping.tt" from the ItemTemplate.
                //Then copied the supporting classes from the template and
                //entered here in the CodeGenerationToolsLibrary project as a .Net Class here.
                //I've used the Mapping.tt because it is the most complex,
                //and shows how to obtain the Mapping info used to
                //create the EntityConfiguration from the EDMX.
                //
                // See PropertyToColumnMapping and ManyToManyMappings from
                // MetadataLoadResult
                //
                EF5FluentUtility   efu = new EF5FluentUtility();
                MetadataLoadResult mlr = efu.LoadMetadata(inputFile);

                var a = mlr.EdmItems;
                var b = mlr.ManyToManyMappings;
                var c = mlr.PropertyToColumnMapping;
                var d = mlr.TphMappings;

                //Obtain the EntityContainer from the ItemsCollection
                var container = mlr.EdmItems.GetItems <EntityContainer>()[0];

                //Iterate all the EntitySets and Properties
                //EntitySet are as in "People", where the EntityType is "Person"
                foreach (var entityset in container.BaseEntitySets.OfType <EntitySet>().OrderBy(e => e.Name))
                {
                    var entitysetname = entityset.Name;
                    var entityname    = entityset.ElementType.Name;
                    var entitytype    = entityset.ElementType;
                    var declaringtype = entityset.ElementType.NavigationProperties[0].DeclaringType;

                    //Navigation Properties for a particular Entity
                    var collectionNavigations1 = entityset.ElementType.NavigationProperties.Where(np => np.DeclaringType == entityset.ElementType);

                    // Find m:m relationshipsto configure for a particular Entity
                    var manyManyRelationships = entityset.ElementType.NavigationProperties
                                                .Where(np =>
                                                       //np.DeclaringType is EntityType &&
                                                       np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &&
                                                       np.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many
                                                       // Ensures we only configure from one end.
                                                       // Convention is to have source on the left, as it would be diagrammatically.
                                                       && np.RelationshipType.RelationshipEndMembers.First() == np.FromEndMember)
                                                .ToArray();

                    //Now process the M:Ms
                    foreach (var navProperty in manyManyRelationships)
                    {
                        var otherNavProperty = navProperty.ToEndMember.GetEntityType().NavigationProperties.Where(n => n.RelationshipType == navProperty.RelationshipType && n != navProperty).Single();
                        var association      = (AssociationType)navProperty.RelationshipType;

                        //This did not work in the T4 Template.
                        var mapping1 = mlr.ManyToManyMappings[association];

                        var mapping2 = mlr.ManyToManyMappings.Where(m => m.Key.Name == association.Name).FirstOrDefault().Value;
                        var item1    = mapping1.Item1;

                        //This did not work in the T4 Template.
                        var leftKeyMappings1 = mapping1.Item2[navProperty.ToEndMember];
                        var leftKeyMappings2 = mapping1.Item2.Where(np => np.Key.Name == navProperty.ToEndMember.Name).FirstOrDefault().Value;

                        // Need to ensure that FKs are declared in the same order as the PK properties on each principal type
                        var leftType  = (EntityType)navProperty.DeclaringType;
                        var rightType = (EntityType)otherNavProperty.DeclaringType;

                        //Access using Index [navProperty.FromEndMember] did not work within template.
                        var leftKeyMappings  = mapping1.Item2.Where(np => np.Key.Name == navProperty.FromEndMember.Name).FirstOrDefault().Value;      //[navProperty.FromEndMember];
                        var rightKeyMappings = mapping1.Item2.Where(np => np.Key.Name == otherNavProperty.FromEndMember.Name).FirstOrDefault().Value; //[otherNavProperty.FromEndMember];

                        var left  = leftKeyMappings.Where(km => km.Key.Name == "PersonID");
                        var right = rightType.KeyMembers.Select(m => "\"" + rightKeyMappings.Where(km => km.Key.Name == m.Name).FirstOrDefault().Value + "\"").FirstOrDefault();
                    }

                    //Dual OrderBy to bring Keys to top of list
                    //Iterate all properties for this particular Entity.
                    var properties = entityset.ElementType.Properties.OrderBy(s => s.Name).OrderBy(p => entityset.ElementType.KeyMembers.Contains(p) == false).ToArray();
                    foreach (var property in properties)
                    {
                        var propertyname = property.Name;

                        //This did not work in the T4 Template.
                        var mapping1 = mlr.PropertyToColumnMapping[entityset.ElementType];

                        //PropertyToColumnMapping is a collection for ALL Entities, so here the particular Entity needs to be filtered out.
                        //Mapping returned is a complex generic Dictionary.
                        var mapping2 = mlr.PropertyToColumnMapping.Where(k => k.Key == entityset.ElementType).FirstOrDefault().Value;
                        var mapping3 = mlr.PropertyToColumnMapping.Where(k => k.Key.FullName == entityset.ElementType.FullName).FirstOrDefault().Value;

                        var mapping4 = mapping3.Item2.Where(p => p.Key.Name == property.Name).FirstOrDefault().Value;

                        var i1       = mapping1.Item1;
                        var i2       = mapping1.Item2;
                        var mapright = i2[property];
                    }
                }

                //********************************************************************************

                //Demo 2
                //This takes EF.Utility.CS.ttinclude and receates as
                //.net Classes.
                //
                MyTextTransformation tt   = new MyTextTransformation();
                CodeGenerationTools  code = new CodeGenerationTools(tt);

                CodeRegion     cregion = new CodeRegion(tt, 1);
                MetadataTools  mtool   = new MetadataTools(tt);
                MetadataLoader mloader = new MetadataLoader(tt);

                var ItemCollection = mloader.CreateEdmItemCollection(inputFile);

                var Container = ItemCollection.GetItems <EntityContainer>()[0];
                Console.WriteLine(String.Format("Container Name: {0}", Container.Name));
                Console.WriteLine(String.Format("Model Namespace: {0}", mloader.GetModelNamespace(inputFile)));
                Console.WriteLine(String.Format("No Of Items in ItemsCollection: {0}\n", ItemCollection.Count));
                Console.WriteLine("Press any key to continue.\n"); Console.ReadKey();

                foreach (var i in ItemCollection)
                {
                    Console.WriteLine(String.Format("Item: {0}, {1}", i.ToString(), i.BuiltInTypeKind.ToString()));
                }
                Console.WriteLine("Press any key to continue.\n"); Console.ReadKey();

                EdmItemCollection edmItemCollection = null;;
                var ret = mloader.TryCreateEdmItemCollection(inputFile, out edmItemCollection);

                StoreItemCollection storeItemCollection = null;
                ret = mloader.TryCreateStoreItemCollection(inputFile, out storeItemCollection);

                StorageMappingItemCollection storageMappingItemCollection = null;
                ret = mloader.TryCreateStorageMappingItemCollection(inputFile, edmItemCollection, storeItemCollection, out storageMappingItemCollection);
                foreach (var i in storageMappingItemCollection)
                {
                    Console.WriteLine(String.Format("Item: {0}, {1}", i.ToString(), i.BuiltInTypeKind.ToString()));
                }
                DataSpace ds = storageMappingItemCollection.DataSpace;

                MetadataWorkspace metadataWorkspace = null;
                ret = mloader.TryLoadAllMetadata(inputFile, out metadataWorkspace);

                //Get the schema "dbo" from a particular Entity.
                EntityContainer ec          = storeItemCollection.GetItems <EntityContainer>().First();
                EntitySet       eset        = ec.GetEntitySetByName(code.Escape("People"), true);
                string          schemaName1 = eset.MetadataProperties["Schema"].Value.ToString();

                //Get the schema "dbo" from any Entity. I guess the schema will be same for all?!
                EntitySetBase fes         = ec.BaseEntitySets.FirstOrDefault();
                string        schemaName2 = fes.MetadataProperties["Schema"].Value.ToString();

                var edmxSchema = EDMXchema.GetSchemaElement(inputFile);

                Console.WriteLine("Press any key to continue.\n"); Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to quit.");
            Console.ReadKey();

            // var loadResult = LoadMetadata(inputFile);
        }
Example #38
0
 private void SetWalkEndFor(CodeRegion region, int outputLineCnt)
 {
     _walkthroughRanges[region.Name].End = outputLineCnt;
 }
Example #39
0
        private CodeObject GetOneObject()
        {
            CodeObject parent = null;
            Token      token  = this.ReadToken();
            bool       flag   = false;
            bool       flag2  = false;
            bool       flag3  = false;
            CALC       nONE   = CALC.NONE;

            while (true)
            {
                if (token.Type == Scorpio.Compiler.TokenType.Not)
                {
                    flag = true;
                }
                else if (token.Type == Scorpio.Compiler.TokenType.Minus)
                {
                    flag2 = true;
                }
                else
                {
                    if (token.Type != Scorpio.Compiler.TokenType.Negative)
                    {
                        break;
                    }
                    flag3 = true;
                }
                token = this.ReadToken();
            }
            if (token.Type == Scorpio.Compiler.TokenType.Increment)
            {
                nONE  = CALC.PRE_INCREMENT;
                token = this.ReadToken();
            }
            else if (token.Type == Scorpio.Compiler.TokenType.Decrement)
            {
                nONE  = CALC.PRE_DECREMENT;
                token = this.ReadToken();
            }
            switch (token.Type)
            {
            case Scorpio.Compiler.TokenType.LeftBrace:
                this.UndoToken();
                parent = this.GetTable();
                break;

            case Scorpio.Compiler.TokenType.LeftPar:
                parent = new CodeRegion(this.GetObject());
                this.ReadRightParenthesis();
                break;

            case Scorpio.Compiler.TokenType.LeftBracket:
                this.UndoToken();
                parent = this.GetArray();
                break;

            case Scorpio.Compiler.TokenType.Function:
                this.UndoToken();
                parent = new CodeFunction(this.ParseFunctionDeclaration(false));
                break;

            case Scorpio.Compiler.TokenType.Boolean:
            case Scorpio.Compiler.TokenType.Number:
            case Scorpio.Compiler.TokenType.String:
            case Scorpio.Compiler.TokenType.SimpleString:
                parent = new CodeScriptObject(this.m_script, token.Lexeme);
                break;

            case Scorpio.Compiler.TokenType.Null:
                parent = new CodeScriptObject(this.m_script, null);
                break;

            case Scorpio.Compiler.TokenType.Eval:
                parent = this.GetEval();
                break;

            case Scorpio.Compiler.TokenType.Identifier:
                parent = new CodeMember((string)token.Lexeme);
                break;

            default:
                throw new ParserException("Object起始关键字错误 ", token);
            }
            parent.StackInfo = new StackInfo(this.m_strBreviary, token.SourceLine);
            parent           = this.GetVariable(parent);
            parent.Not       = flag;
            parent.Minus     = flag2;
            parent.Negative  = flag3;
            if (parent is CodeMember)
            {
                if (nONE != CALC.NONE)
                {
                    ((CodeMember)parent).Calc = nONE;
                    return(parent);
                }
                Token token2 = this.ReadToken();
                if (token2.Type == Scorpio.Compiler.TokenType.Increment)
                {
                    nONE = CALC.POST_INCREMENT;
                }
                else if (token2.Type == Scorpio.Compiler.TokenType.Decrement)
                {
                    nONE = CALC.POST_DECREMENT;
                }
                else
                {
                    this.UndoToken();
                }
                if (nONE != CALC.NONE)
                {
                    ((CodeMember)parent).Calc = nONE;
                }
                return(parent);
            }
            if (nONE != CALC.NONE)
            {
                throw new ParserException("++ 或者 -- 只支持变量的操作", token);
            }
            return(parent);
        }