public static Builder LoadFromXML(XmlElement root) { Builder b = new Builder(); b.name = root.GetAttribute("name"); using (ScopeDebugContext.Func(() => { return("ViewSchema '" + b.name + "'"); })) { foreach (XmlNode node in root.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { XmlElement e = (XmlElement)node; if (e.Name == "View") { var v = ViewTable.Builder.LoadFromXML(e); if (v != null) { b.viewTable.Add(v); } } } } return(b); } }
void SetSnapshot(DataRenderer dataRenderer, PackedMemorySnapshot snapshot) { if (snapshot == null) { m_RawSnapshot = null; m_RawSchema = null; SchemaToDisplay = null; UpdateTableSelectionNames(); return; } m_RawSnapshot = snapshot; ProgressBarDisplay.ShowBar(string.Format("Opening snapshot: {0}", System.IO.Path.GetFileNameWithoutExtension(snapshot.filePath))); var cachedSnapshot = new CachedSnapshot(snapshot); using (Profiling.GetMarker(Profiling.MarkerId.CrawlManagedData).Auto()) { var crawling = Crawler.Crawl(cachedSnapshot); crawling.MoveNext(); //start execution var status = crawling.Current as EnumerationStatus; float progressPerStep = 1.0f / status.StepCount; while (crawling.MoveNext()) { ProgressBarDisplay.UpdateProgress(status.CurrentStep * progressPerStep, status.StepStatus); } } ProgressBarDisplay.ClearBar(); m_RawSchema = new RawSchema(); m_RawSchema.SetupSchema(cachedSnapshot, dataRenderer); SchemaToDisplay = m_RawSchema; if (k_DefaultViewFilePath.Length > 0) { using (ScopeDebugContext.Func(() => { return("File '" + k_DefaultViewFilePath + "'"); })) { Database.View.ViewSchema.Builder builder = null; using (Profiling.GetMarker(Profiling.MarkerId.LoadViewDefinitionFile).Auto()) { builder = Database.View.ViewSchema.Builder.LoadFromXMLFile(k_DefaultViewFilePath); } if (builder != null) { using (Profiling.GetMarker(Profiling.MarkerId.BuildViewDefinitionFile).Auto()) { ViewSchema = builder.Build(m_RawSchema); } if (ViewSchema != null) { SchemaToDisplay = ViewSchema; } } } } UpdateTableSelectionNames(); }
public static LinkRequestTable MakeLinkRequest(TableLink metaLink, Table sourceTable, Column sourceColumn, long sourceRow, Database.Operation.ExpressionParsingContext expressionParsingContext) { if (metaLink == null) { return(null); } using (ScopeDebugContext.Func(() => { return("MakeLinkRequest from table '" + sourceTable.GetName() + "' row " + sourceRow); })) { var lr = new LinkRequestTable(); lr.LinkToOpen = metaLink; lr.SourceTable = sourceTable; lr.SourceView = sourceTable as View.ViewTable; lr.SourceColumn = sourceColumn; lr.SourceRow = sourceRow; if (lr.LinkToOpen.Parameters != null) { foreach (var p in lr.LinkToOpen.Parameters) { var opt = new Operation.Expression.ParseIdentifierOption(sourceTable.Schema as View.ViewSchema, sourceTable, true, true, typeof(string), expressionParsingContext); var metaExpression = new Operation.Expression.MetaExpression(p.Value, true); var exp = Operation.Expression.ParseIdentifier(metaExpression, opt); var exp2 = Operation.ColumnCreator.CreateTypedExpressionFixedRow(exp, sourceRow); lr.Parameters.Add(p.Key, exp2); } } return(lr); } }
public bool EvaluateCondition(ViewSchema vs, ViewTable parentViewTable, Operation.ExpressionParsingContext expressionParsingContext) { if (condition == null) { return(true); } using (ScopeDebugContext.Func(() => { return("EvaluateCondition on Node '" + GetFullName() + "'"); })) { var option = new Operation.Expression.ParseIdentifierOption(vs, parentViewTable, true, true, null, expressionParsingContext); option.formatError = (string s, Operation.Expression.ParseIdentifierOption opt) => { string str = "Error while evaluating node condition."; if (vs != null) { str += " schema '" + vs.name + "'"; } if (parentViewTable != null) { str += " view table '" + parentViewTable.GetName() + "'"; } return(str + " : " + s); }; var resolvedCondition = condition.Build(option); if (resolvedCondition == null) { return(false); } return(resolvedCondition.GetValue(0)); } }
public static Node LoadFromXML(Node parent, XmlElement root) { Node node = new Node(parent); if (parent != null) { node.name = root.GetAttribute("name"); } else { DebugUtility.TryGetMandatoryXmlAttribute(root, "name", out node.name); } using (ScopeDebugContext.Func(() => { return("Node '" + node.name + "'"); })) { foreach (XmlNode xNode in root.ChildNodes) { if (xNode.NodeType == XmlNodeType.Element) { XmlElement e = (XmlElement)xNode; switch (e.Name) { case "Column": var c = ViewColumn.Builder.LoadFromXML(e); if (c != null) { node.column.Add(c); } break; case "Data": node.data = Data.LoadFromXML(node, e); break; case "Filter": LoadFilterFromXML(node, e); break; case "SelectSet": node.localSelectSet = SelectSet.Builder.LoadFromXML(e); break; case "Condition": node.condition = Operation.MetaExpComparison.LoadFromXML(e); break; default: DebugUtility.LogInvalidXmlChild(root, e); break; } } } return(node); } }
public bool LoadView(string filename) { if (CurrentViewMode == ViewMode.ShowNone) { DebugUtility.LogWarning("Must open a snapshot before loading a view file"); MemoryProfilerAnalytics.AddMetaDatatoEvent <MemoryProfilerAnalytics.LoadViewXMLEvent>(1); return(false); } if (String.IsNullOrEmpty(filename)) { return(false); } using (ScopeDebugContext.Func(() => { return("File '" + filename + "'"); })) { var builder = Database.View.ViewSchema.Builder.LoadFromXMLFile(filename); if (builder == null) { return(false); } BaseMode newMode = CurrentMode.BuildViewSchemaClone(builder); if (newMode == null) { return(false); } switch (CurrentViewMode) { case ViewMode.ShowFirst: FirstMode = newMode; break; case ViewMode.ShowSecond: SecondMode = newMode; break; case ViewMode.ShowDiff: diffMode = newMode as DiffMode; FirstMode = diffMode.modeFirst; SecondMode = diffMode.modeSecond; break; default: break; } history.Clear(); ModeChanged(CurrentMode, CurrentViewMode); } return(true); }
public static Builder LoadFromXML(XmlElement root) { Builder b = new Builder(); DebugUtility.TryGetMandatoryXmlAttribute(root, "name", out b.name); using (ScopeDebugContext.Func(() => { return("Column '" + b.name + "'"); })) { b.value = Operation.Expression.MetaExpression.LoadFromXML(root); if (!int.TryParse(root.GetAttribute("width"), out b.displayDefaultWidth)) { b.displayDefaultWidth = 100; } string strisKey = root.GetAttribute("isKey"); if (strisKey != null && strisKey != "") { if (!bool.TryParse(strisKey, out b.isPrimaryKey)) { UnityEngine.Debug.LogError("Error parsing bool value '" + strisKey + "', default to false"); b.isPrimaryKey = false; } } string strGroupable = root.GetAttribute("groupable"); if (strGroupable == "duplicate") { b.groupAlgo = Database.Operation.Grouping.groupByDuplicate; } string strOp = root.GetAttribute("merged"); m_StringToMergeAlgo.TryGetValue(strOp, out b.mergeAlgoE); b.FormatName = root.GetAttribute("format"); foreach (XmlNode node in root.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { XmlElement e = (XmlElement)node; if (e.Name == "Link") { LoadLinkFromXML(b, e); } else if (e.Name == "ParentGroup") { LoadParentGroupFromXML(b, e); } } } return(b); } }
public Select Create(ViewSchema vs, Database.Schema baseSchema, Table table) { Select sel = new Select(); sel.name = name; sel.sourceTable = baseSchema.GetTableByName(sourceTableName); sel.MaxRow = MaxRow; if (sel.sourceTable == null) { using (ScopeDebugContext.Func(() => { return("Select:'" + name + "'"); })) { DebugUtility.LogError("Error while building view '" + vs.name + "' select '" + name + "'. No table named '" + sourceTableName + "'"); return(null); } } return(sel); }
public void Build(ViewSchema vs, ViewTable vTable, SelectSet selectSet, Select sel, Database.Schema baseSchema, Operation.ExpressionParsingContext expressionParsingContext) { using (ScopeDebugContext.Func(() => { return("Select:'" + name + "'"); })) { if (where.Count > 0) { sel.where = new WhereUnion(); foreach (var w in where) { var w2 = w.Build(vs, vTable, selectSet, sel, baseSchema, sel.sourceTable, expressionParsingContext); if (w2.Comparison.IsManyToMany()) { sel.isManyToMany = true; } sel.where.Add(w2); } } } }
public ViewSchema Build(Database.Schema baseSchema) { using (ScopeDebugContext.Func(() => { return("ViewSchema '" + name + "'"); })) { ViewSchema vs = new ViewSchema(); vs.baseSchema = baseSchema; vs.tables = new ViewTable[viewTable.Count]; vs.name = name; int i = 0; foreach (var tBuilder in viewTable) { var table = tBuilder.Build(vs, baseSchema); vs.tables[i] = table; vs.tablesByName.Add(table.GetName(), table); ++i; } return(vs); } }
public static Builder LoadFromXML(XmlElement root) { Builder b = new Builder(); b.name = root.GetAttribute("name"); b.sourceTableName = root.GetAttribute("table"); string strMaxRow = root.GetAttribute("maxRow"); if (string.IsNullOrEmpty(strMaxRow) || !int.TryParse(strMaxRow, out b.MaxRow)) { b.MaxRow = -1; } using (ScopeDebugContext.Func(() => { return("Select:'" + b.name + "'"); })) { foreach (XmlNode node in root.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { XmlElement e = (XmlElement)node; switch (e.Name) { case "Where": { var w = Where.Builder.LoadFromXML(e); if (w != null) { b.where.Add(w); } break; } default: DebugUtility.LogInvalidXmlChild(root, e); break; } } } return(b); } }
public static Builder LoadFromXML(XmlElement root) { using (ScopeDebugContext.Func(() => { return("Loading SelectSet"); })) { Builder b = new Builder(); foreach (XmlNode xNode in root.ChildNodes) { if (xNode.NodeType == XmlNodeType.Element) { XmlElement e = (XmlElement)xNode; switch (e.Name) { case "Select": { var s = Select.Builder.LoadFromXML(e); if (s != null) { b.select.Add(s); } break; } case "Condition": { b.Condition = Operation.MetaExpComparison.LoadFromXML(e); break; } default: DebugUtility.LogInvalidXmlChild(root, e); break; } } } return(b); } }
public ViewTable Build(BuildingData buildingData, ViewTable parent, long row, ViewSchema vs, Database.Schema baseSchema, Operation.ExpressionParsingContext parentExpressionParsingContext) { // Check for usage error from data. if (parent == null && String.IsNullOrEmpty(name)) { DebugUtility.LogError("Table need a name"); return(null); } using (ScopeDebugContext.Func(() => { return("View '" + GetFullName() + "'"); })) { // Check for usage error from code. DebugUtility.CheckCondition(parent == null || (parent.node == this.parent), "Parent ViewTable must points to the node's parent while building child node's ViewTable."); ViewTable vTable = new ViewTable(vs, baseSchema, this, parentExpressionParsingContext); // If has local select set, create it and add it to the expression parsing context hierarchy. see [Figure.1] vTable.SetupLocalSelectSet(localSelectSet.Build(vTable, vs, baseSchema)); MetaTable metaTable = BuildOrGetMetaTable(parent, vTable); if (buildingData.MetaTable == null) { buildingData.MetaTable = metaTable; } //declare columns foreach (var colb in column) { MetaColumn metaColumn = metaTable.GetColumnByName(colb.name); colb.BuildOrUpdateDeclaration(buildingData, vTable, ref metaColumn, vTable.ExpressionParsingContext); } if (data != null) { data.Build(buildingData, this, vTable, parent, parentExpressionParsingContext); } // Fix meta columns (that does not have a data type set) to their fallback value foreach (var fb in buildingData.FallbackColumnType) { if (fb.Key.Type == null) { fb.Key.Type = fb.Value; } } //Build missing column with default behavior for (int i = 0; i != metaTable.GetColumnCount(); ++i) { var metaColumn = metaTable.GetColumnByIndex(i); var column = vTable.GetColumnByIndex(i); if (column == null) { if (metaColumn.DefaultMergeAlgorithm != null) { //when we have a merge algorithm, set the entries as the result of each group's merge value. column = ViewColumn.Builder.BuildColumnNodeMerge(vTable, metaColumn, parentExpressionParsingContext); } vTable.SetColumn(metaColumn, column); } } if (data != null && data.type == Data.DataType.Select && vTable.dataSelectSet.IsManyToMany()) { DebugUtility.LogError("Cannot build a view using a many-to-many select statement. Specify a row value for your select statement where condition(s)."); MemoryProfilerAnalytics.AddMetaDatatoEvent <MemoryProfilerAnalytics.LoadViewXMLEvent>(7); } return(vTable); } }
public ViewTable Build(ViewTable parent, long row, ViewSchema vs, Database.Schema baseSchema, Operation.ExpressionParsingContext parentExpressionParsingContext) { // Check for usage error from data. if (parent == null && String.IsNullOrEmpty(name)) { DebugUtility.LogError(FormatErrorContextInfo(vs) + ": Table need a name"); return(null); } using (ScopeDebugContext.Func(() => { return("View '" + GetFullName() + "'"); })) { // Check for usage error from code. DebugUtility.CheckCondition(parent == null || (parent.node == this.parent), FormatErrorContextInfo(vs) + ": Parent ViewTable must points to the node's parent while building child node's ViewTable."); if (data == null) { //no data return(null); } ViewTable vTable = new ViewTable(vs, baseSchema); vTable.node = this; vTable.parentExpressionParsingContext = parentExpressionParsingContext; vTable.expressionParsingContext = parentExpressionParsingContext; // If has local select set, create it and add it to the expression parsing context hierarchy. see [Figure.1] vTable.localSelectSet = localSelectSet.Build(vTable, vs, baseSchema); if (vTable.localSelectSet != null) { vTable.expressionParsingContext = new Operation.ExpressionParsingContext(vTable.expressionParsingContext, vTable.localSelectSet); } MetaTable metaTable = BuildOrGetMetaTable(parent, vTable); //declare columns foreach (var colb in column) { MetaColumn metaColumn = metaTable.GetColumnByName(colb.name); bool hadMetaColumn = metaColumn != null; colb.BuildOrUpdateDeclaration(ref metaColumn); // add the metacolum to the metatable if it just got created if (!hadMetaColumn) { metaTable.AddColumn(metaColumn); } } data.Build(this, vTable, parent, vs, baseSchema, parentExpressionParsingContext, metaTable); //Build missing column with default behavior for (int i = 0; i != metaTable.GetColumnCount(); ++i) { var metaColumn = metaTable.GetColumnByIndex(i); var column = vTable.GetColumnByIndex(i); if (column == null) { if (metaColumn.DefaultMergeAlgorithm != null) { //when we have a merge algorithm, set the entries as the result of each group's merge value. column = ViewColumn.Builder.BuildColumnNodeMerge(vTable, metaColumn, parentExpressionParsingContext); } vTable.SetColumn(metaColumn, column); } } if (data.type == Data.DataType.Select && vTable.dataSelectSet.IsManyToMany()) { DebugUtility.LogError("Cannot build the view table '" + vTable.GetName() + "' using a many-to-many select statement. Specify a row value for your select statement where condition(s)."); MemoryProfilerAnalytics.AddMetaDatatoEvent <MemoryProfilerAnalytics.LoadViewXMLEvent>(7); } return(vTable); } }