internal SectionQuery(CellQuery parent, int ordinal, IVisio.VisSectionIndices section) { this.Parent = parent; this.Ordinal = ordinal; this.SectionIndex = section; this.Columns = new ColumnList(); }
private static void ProcessWorksheet() { WorksheetEntry worksheet = GetWorksheet(); AtomLink cellFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null); List <string> keys = new List <string>(); CellQuery query = new CellQuery(cellFeedLink.HRef.ToString()); CellFeed feed = ss.Query(query); Console.WriteLine("Processing cells..."); string currentKey = null; foreach (CellEntry cell in feed.Entries) { switch (cell.Column) { case 1: if (cell.Value == null || cell.Value.Contains(' ')) { currentKey = null; } else if (cell.Row < 5) { break; } else { Console.WriteLine("Processing key: " + cell.Value); keys.Add(currentKey = cell.Value); if (currentKey.Contains("DONT_TRANSLATE")) { currentKey = null; } } break; default: if (cell.Row == 2) { //langauge codes writers.Add(new LanguageCodeWriter(cell.Value)); continue; } if (cell.Row < 5) { break; } if (writers.Count > 0 && currentKey != null) { if (cell.Value == null) { continue; } string content = cell.Value.Trim(' ', '\n', '\r', '\t').Replace("\n", "\\n"); if (content.IndexOf(@"\\") >= 0) { Console.WriteLine("key {0} translation {1} failed with excess escape characters", currentKey, content); Console.ReadLine(); } try { int argCount = content.Count <char>(c => c == '{'); string[] args = new string[argCount]; for (int i = 0; i < argCount; i++) { args[i] = "test"; } string test = string.Format(content, args); } catch { Console.WriteLine("key {0} translation {1} failed with string format", currentKey, content); Console.ReadLine(); } writers[(int)cell.Column - 2].Add(currentKey, content); } break; } } //write enum out to .cs file using (TextWriter w = new StreamWriter(osu_path + @"osu!common\Helpers\LocalisationManager_Strings.cs")) { //header w.WriteLine("namespace osu_common.Helpers"); w.WriteLine("{"); w.WriteLine(" public enum OsuString"); w.WriteLine(" {"); foreach (string s in keys) { w.WriteLine(" {0},", s); } //footer w.WriteLine(" }"); w.WriteLine("}"); } }
MergeBoolExpressions( CellQuery query1, CellQuery query2, BoolExpression conjunct1, BoolExpression conjunct2, CellTreeOpType opType) { var bools1 = query1.BoolVars; var bools2 = query2.BoolVars; // Add conjuncts to both sets if needed if (false == conjunct1.IsTrue) { bools1 = BoolExpression.AddConjunctionToBools(bools1, conjunct1); } if (false == conjunct2.IsTrue) { bools2 = BoolExpression.AddConjunctionToBools(bools2, conjunct2); } // Perform merge Debug.Assert(bools1.Count == bools2.Count); var bools = new List <BoolExpression>(); // Both bools1[i] and bools2[i] be null for some of the i's. When // we merge two (leaf) cells (say), only one boolean each is set // in it; the rest are all nulls. If the SP/TM rules have been // applied, more than one boolean may be non-null in a cell query for (var i = 0; i < bools1.Count; i++) { BoolExpression merged = null; if (bools1[i] == null) { merged = bools2[i]; } else if (bools2[i] == null) { merged = bools1[i]; } else { if (opType == CellTreeOpType.IJ) { merged = BoolExpression.CreateAnd(bools1[i], bools2[i]); } else if (opType == CellTreeOpType.Union) { merged = BoolExpression.CreateOr(bools1[i], bools2[i]); } else if (opType == CellTreeOpType.LASJ) { merged = BoolExpression.CreateAnd( bools1[i], BoolExpression.CreateNot(bools2[i])); } else { Debug.Fail("No other operation expected for boolean merge"); } } if (merged != null) { merged.ExpensiveSimplify(); } bools.Add(merged); } return(bools); }
/// <summary> /// Given a cell, a member and a boolean condition on that member, creates additional cell /// which with the specified restriction on the member in addition to original condition. /// e.i conjunction of original condition AND member in newCondition /// Creation fails when the original condition contradicts new boolean condition /// ViewTarget tells whether MemberPath is in Cquery or SQuery /// </summary> private bool TryCreateAdditionalCellWithCondition( Cell originalCell, MemberPath memberToExpand, bool conditionValue, ViewTarget viewTarget, out Cell result) { DebugCheck.NotNull(originalCell); DebugCheck.NotNull(memberToExpand); result = null; //Create required structures var leftExtent = originalCell.GetLeftQuery(viewTarget).SourceExtentMemberPath; var rightExtent = originalCell.GetRightQuery(viewTarget).SourceExtentMemberPath; //Now for the given left-side projected member, find corresponding right-side member that it is mapped to var indexOfBooLMemberInProjection = originalCell.GetLeftQuery(viewTarget).GetProjectedMembers().TakeWhile(path => !path.Equals(memberToExpand)).Count(); var rightConditionMemberSlot = ((MemberProjectedSlot)originalCell.GetRightQuery(viewTarget).ProjectedSlotAt(indexOfBooLMemberInProjection)); var rightSidePath = rightConditionMemberSlot.MemberPath; var leftSlots = new List <ProjectedSlot>(); var rightSlots = new List <ProjectedSlot>(); //Check for impossible conditions (otehrwise we get inaccurate pre-validation errors) var negatedCondition = new ScalarConstant(!conditionValue); if (originalCell.GetLeftQuery(viewTarget).Conditions .Where(restriction => restriction.RestrictedMemberSlot.MemberPath.Equals(memberToExpand)) .Where(restriction => restriction.Domain.Values.Contains(negatedCondition)).Any() || originalCell.GetRightQuery(viewTarget).Conditions .Where(restriction => restriction.RestrictedMemberSlot.MemberPath.Equals(rightSidePath)) .Where(restriction => restriction.Domain.Values.Contains(negatedCondition)).Any()) { return(false); } //End check //Create Projected Slots // Map all slots in original cell (not just keys) because some may be required (non nullable and no default) // and others may have not_null condition so MUST be projected. Rely on the user doing the right thing, otherwise // they will get the error message anyway for (var i = 0; i < originalCell.GetLeftQuery(viewTarget).NumProjectedSlots; i++) { leftSlots.Add(originalCell.GetLeftQuery(viewTarget).ProjectedSlotAt(i)); } for (var i = 0; i < originalCell.GetRightQuery(viewTarget).NumProjectedSlots; i++) { rightSlots.Add(originalCell.GetRightQuery(viewTarget).ProjectedSlotAt(i)); } //Create condition boolena expressions var leftQueryWhereClause = BoolExpression.CreateLiteral(new ScalarRestriction(memberToExpand, new ScalarConstant(conditionValue)), null); leftQueryWhereClause = BoolExpression.CreateAnd(originalCell.GetLeftQuery(viewTarget).WhereClause, leftQueryWhereClause); var rightQueryWhereClause = BoolExpression.CreateLiteral(new ScalarRestriction(rightSidePath, new ScalarConstant(conditionValue)), null); rightQueryWhereClause = BoolExpression.CreateAnd(originalCell.GetRightQuery(viewTarget).WhereClause, rightQueryWhereClause); //Create additional Cells var rightQuery = new CellQuery( rightSlots, rightQueryWhereClause, rightExtent, originalCell.GetRightQuery(viewTarget).SelectDistinctFlag); var leftQuery = new CellQuery( leftSlots, leftQueryWhereClause, leftExtent, originalCell.GetLeftQuery(viewTarget).SelectDistinctFlag); Cell newCell; if (viewTarget == ViewTarget.UpdateView) { newCell = Cell.CreateCS(rightQuery, leftQuery, originalCell.CellLabel, m_currentCellNumber); } else { newCell = Cell.CreateCS(leftQuery, rightQuery, originalCell.CellLabel, m_currentCellNumber); } m_currentCellNumber++; result = newCell; return(true); }
public void Init() { query = new CellQuery(""); rng = new Random(); }
// effects: Merges query2 with this according to the TM/SP rules for opType and // returns the merged result. canBooleansOverlap indicates whether the bools in this and query2 can overlap, i.e. // the same cells may have contributed to query2 and this earlier in the merge process internal static bool TryMergeTwoCellQueries( CellQuery query1, CellQuery query2, CellTreeOpType opType, out CellQuery mergedQuery) { mergedQuery = null; // Initialize g1 and g2 according to the TM/SP rules for IJ, LOJ, Union, FOJ cases BoolExpression g1 = null; BoolExpression g2 = null; switch (opType) { case CellTreeOpType.IJ: break; case CellTreeOpType.LOJ: case CellTreeOpType.LASJ: g2 = BoolExpression.True; break; case CellTreeOpType.FOJ: case CellTreeOpType.Union: g1 = BoolExpression.True; g2 = BoolExpression.True; break; default: Debug.Fail("Unsupported operator"); break; } var remap = new Dictionary <MemberPath, MemberPath>(MemberPath.EqualityComparer); //Continue merging only if both queries are over the same source MemberPath newRoot; if (!query1.Extent.Equals(query2.Extent)) { // could not merge return(false); } else { newRoot = query1.SourceExtentMemberPath; } // Conjuncts for ANDing with the previous whereClauses var conjunct1 = BoolExpression.True; var conjunct2 = BoolExpression.True; BoolExpression whereClause = null; switch (opType) { case CellTreeOpType.IJ: // Project[D1, D2, A, B, C] Select[cond1 and cond2] (T) // We simply merge the two lists of booleans -- no conjunct is added // conjunct1 and conjunct2 don't change // query1.WhereCaluse AND query2.WhereCaluse Debug.Assert(g1 == null && g2 == null, "IJ does not affect g1 and g2"); whereClause = BoolExpression.CreateAnd(query1.WhereClause, query2.WhereClause); break; case CellTreeOpType.LOJ: // conjunct1 does not change since D1 remains as is // Project[D1, (expr2 and cond2 and G2) as D2, A, B, C] Select[cond1] (T) // D1 does not change. New d2 is the list of booleans expressions // for query2 ANDed with g2 AND query2.WhereClause Debug.Assert(g1 == null, "LOJ does not affect g1"); conjunct2 = BoolExpression.CreateAnd(query2.WhereClause, g2); // Just query1's whereclause whereClause = query1.WhereClause; break; case CellTreeOpType.FOJ: case CellTreeOpType.Union: // Project[(expr1 and cond1 and G1) as D1, (expr2 and cond2 and G2) as D2, A, B, C] Select[cond1] (T) // New D1 is a list -- newD1 = D1 AND query1.WhereClause AND g1 // New D1 is a list -- newD2 = D2 AND query2.WhereClause AND g2 conjunct1 = BoolExpression.CreateAnd(query1.WhereClause, g1); conjunct2 = BoolExpression.CreateAnd(query2.WhereClause, g2); // The new whereClause -- g1 AND query1.WhereCaluse OR g2 AND query2.WhereClause whereClause = BoolExpression.CreateOr( BoolExpression.CreateAnd(query1.WhereClause, g1), BoolExpression.CreateAnd(query2.WhereClause, g2)); break; case CellTreeOpType.LASJ: // conjunct1 does not change since D1 remains as is // Project[D1, (expr2 and cond2 and G2) as D2, A, B, C] Select[cond1] (T) // D1 does not change. New d2 is the list of booleans expressions // for query2 ANDed with g2 AND NOT query2.WhereClause Debug.Assert(g1 == null, "LASJ does not affect g1"); conjunct2 = BoolExpression.CreateAnd(query2.WhereClause, g2); whereClause = BoolExpression.CreateAnd(query1.WhereClause, BoolExpression.CreateNot(conjunct2)); break; default: Debug.Fail("Unsupported operator"); break; } // Create the various remapped parts for the cell query -- // boolean expressions, merged slots, whereclause, duplicate // elimination, join tree var boolExprs = MergeBoolExpressions(query1, query2, conjunct1, conjunct2, opType); //BoolExpression.RemapBools(boolExprs, remap); ProjectedSlot[] mergedSlots; if (false == ProjectedSlot.TryMergeRemapSlots(query1.ProjectedSlots, query2.ProjectedSlots, out mergedSlots)) { // merging failed because two different right slots go to same left slot return(false); } whereClause = whereClause.RemapBool(remap); var elimDupl = MergeDupl(query1.SelectDistinctFlag, query2.SelectDistinctFlag); whereClause.ExpensiveSimplify(); mergedQuery = new CellQuery( mergedSlots, whereClause, boolExprs, elimDupl, newRoot); return(true); }
internal static bool TryMergeTwoCellQueries( CellQuery query1, CellQuery query2, CellTreeOpType opType, out CellQuery mergedQuery) { mergedQuery = (CellQuery)null; BoolExpression boolExpression1 = (BoolExpression)null; BoolExpression boolExpression2 = (BoolExpression)null; switch (opType) { case CellTreeOpType.Union: case CellTreeOpType.FOJ: boolExpression1 = BoolExpression.True; boolExpression2 = BoolExpression.True; break; case CellTreeOpType.LOJ: case CellTreeOpType.LASJ: boolExpression2 = BoolExpression.True; break; } Dictionary <MemberPath, MemberPath> remap = new Dictionary <MemberPath, MemberPath>(MemberPath.EqualityComparer); if (!query1.Extent.Equals((object)query2.Extent)) { return(false); } MemberPath extentMemberPath = query1.SourceExtentMemberPath; BoolExpression and1 = BoolExpression.True; BoolExpression and2 = BoolExpression.True; BoolExpression boolExpression3 = (BoolExpression)null; switch (opType) { case CellTreeOpType.Union: case CellTreeOpType.FOJ: and1 = BoolExpression.CreateAnd(query1.WhereClause, boolExpression1); and2 = BoolExpression.CreateAnd(query2.WhereClause, boolExpression2); boolExpression3 = BoolExpression.CreateOr(BoolExpression.CreateAnd(query1.WhereClause, boolExpression1), BoolExpression.CreateAnd(query2.WhereClause, boolExpression2)); break; case CellTreeOpType.LOJ: and2 = BoolExpression.CreateAnd(query2.WhereClause, boolExpression2); boolExpression3 = query1.WhereClause; break; case CellTreeOpType.IJ: boolExpression3 = BoolExpression.CreateAnd(query1.WhereClause, query2.WhereClause); break; case CellTreeOpType.LASJ: and2 = BoolExpression.CreateAnd(query2.WhereClause, boolExpression2); boolExpression3 = BoolExpression.CreateAnd(query1.WhereClause, BoolExpression.CreateNot(and2)); break; } List <BoolExpression> boolExprs = CellTreeSimplifier.MergeBoolExpressions(query1, query2, and1, and2, opType); ProjectedSlot[] result; if (!ProjectedSlot.TryMergeRemapSlots(query1.ProjectedSlots, query2.ProjectedSlots, out result)) { return(false); } BoolExpression whereClause = boolExpression3.RemapBool(remap); CellQuery.SelectDistinct elimDupl = CellTreeSimplifier.MergeDupl(query1.SelectDistinctFlag, query2.SelectDistinctFlag); whereClause.ExpensiveSimplify(); mergedQuery = new CellQuery(result, whereClause, boolExprs, elimDupl, extentMemberPath); return(true); }
protected List <T> Deserialize <T>(WorksheetEntry sheet, string[] filterFieldNames) { var output = new List <T>(); HashSet <string> filterFieldLookup = filterFieldNames != null && filterFieldNames.Length > 0 ? new HashSet <string>(filterFieldNames) : null; //grab headers var headerQuery = new CellQuery(sheet.CellFeedLink); headerQuery.MinimumRow = 1; headerQuery.MaximumRow = 1; var headerCellFeed = mDatabaseQuery.spreadsheetService.Query(headerQuery) as CellFeed; // //grab contents var contentQuery = new CellQuery(sheet.CellFeedLink); contentQuery.MinimumRow = 2; var contentFeed = mDatabaseQuery.spreadsheetService.Query(contentQuery) as CellFeed; uint curRow = 0; var type = typeof(T); T item = default(T); foreach (CellEntry cell in contentFeed.Entries) { //next item? if (curRow != cell.Row) { item = Activator.CreateInstance <T>(); output.Add(item); curRow = cell.Row; } if (string.IsNullOrEmpty(cell.Value)) { continue; } //get associated header var headerCell = headerCellFeed[1, cell.Column]; if (headerCell == null) { continue; } string headerName = headerCell.Value; if (string.IsNullOrEmpty(headerName)) { continue; } if (filterFieldLookup != null && !filterFieldLookup.Contains(headerName)) { continue; } //set value const BindingFlags bindFlags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; //try field FieldInfo fieldInfo = type.GetField(headerName, bindFlags); if (fieldInfo != null) { try { var value = ConvertFrom(cell, fieldInfo.FieldType); fieldInfo.SetValue(item, value); } catch (Exception e) { string pos = string.Format("Row[{0}] Col[{1}]", cell.Row, cell.Column); Debug.LogError(string.Format("Deserialize {0}:{1} ({2}) Exception: {3}", mSheetName, sheet.Title.Text, pos, e.Message)); } continue; } //try property PropertyInfo propInfo = type.GetProperty(headerName, bindFlags); if (propInfo != null) { if (!propInfo.CanWrite) //ignore readonly properties { continue; } try { var value = ConvertFrom(cell, propInfo.PropertyType); propInfo.SetValue(item, value, null); } catch (Exception e) { string pos = string.Format("Row[{0}] Col[{1}]", cell.Row, cell.Column); Debug.LogError(string.Format("Deserialize {0}:{1} ({2}) Exception: {3}", mSheetName, sheet.Title.Text, pos, e.Message)); } continue; } } // return(output); }
/// <summary> /// Finds errors related to splitting Conditions /// 1. Condition value is repeated across multiple types /// 2. A Column/attribute is mapped but also used as a condition /// </summary> private void MatchConditionErrors() { List <LeftCellWrapper> leftCellWrappers = m_viewgenContext.AllWrappersForExtent; //Stores violating Discriminator (condition member) so that we dont repeat the same error Set <MemberPath> mappedConditionMembers = new Set <MemberPath>(); //Both of these data-structs help in finding duplicate conditions Set <CompositeCondition> setOfconditions = new Set <CompositeCondition>(new ConditionComparer()); Dictionary <CompositeCondition, LeftCellWrapper> firstLCWForCondition = new Dictionary <CompositeCondition, LeftCellWrapper>(new ConditionComparer()); foreach (var leftCellWrapper in leftCellWrappers) { CompositeCondition condMembersValues = new CompositeCondition(); CellQuery cellQuery = leftCellWrapper.OnlyInputCell.GetLeftQuery(m_viewgenContext.ViewTarget); foreach (MemberRestriction condition in cellQuery.GetConjunctsFromWhereClause()) { MemberPath memberPath = condition.RestrictedMemberSlot.MemberPath; if (!m_domainMap.IsConditionMember(memberPath)) { continue; } ScalarRestriction scalarCond = condition as ScalarRestriction; //Check for mapping of Scalar member condition, ignore type conditions if (scalarCond != null && !mappedConditionMembers.Contains(memberPath) && /* prevents duplicate errors */ !leftCellWrapper.OnlyInputCell.CQuery.WhereClause.Equals(leftCellWrapper.OnlyInputCell.SQuery.WhereClause) && /* projection allowed when both conditions are equal */ !IsMemberPartOfNotNullCondition(leftCellWrappers, memberPath, m_viewgenContext.ViewTarget)) { //This member should not be mapped CheckThatConditionMemberIsNotMapped(memberPath, leftCellWrappers, mappedConditionMembers); } //If a not-null condition is specified on a nullable column, //check that the property it is mapped to in the fragment is non-nullable, //unless there is a not null condition on the property that is being mapped it self. //Otherwise return an error. if (m_viewgenContext.ViewTarget == ViewTarget.UpdateView) { if (scalarCond != null && memberPath.IsNullable && IsMemberPartOfNotNullCondition(new LeftCellWrapper[] { leftCellWrapper }, memberPath, m_viewgenContext.ViewTarget)) { MemberPath rightMemberPath = GetRightMemberPath(memberPath, leftCellWrapper); if (rightMemberPath != null && rightMemberPath.IsNullable && !IsMemberPartOfNotNullCondition(new LeftCellWrapper[] { leftCellWrapper }, rightMemberPath, m_viewgenContext.ViewTarget)) { m_errorLog.AddEntry(new ErrorLog.Record(true, ViewGenErrorCode.ErrorPatternConditionError, Strings.Viewgen_ErrorPattern_NotNullConditionMappedToNullableMember( memberPath, rightMemberPath ), leftCellWrapper.OnlyInputCell, "")); } } } //CheckForDuplicateConditionValue //discover a composite condition of the form {path1=x, path2=y, ...} foreach (var element in condition.Domain.Values) { Set <Constant> values; //if not in the dict, add it if (!condMembersValues.TryGetValue(memberPath, out values)) { values = new Set <Constant>(Constant.EqualityComparer); condMembersValues.Add(memberPath, values); } values.Add(element); } } //foreach condition if (condMembersValues.Count > 0) //it is possible that there are no condition members { //Check if the composite condition has been encountered before if (setOfconditions.Contains(condMembersValues)) { //Extents may be Equal on right side (e.g: by some form of Refconstraint) if (!RightSideEqual(firstLCWForCondition[condMembersValues], leftCellWrapper)) { //error duplicate conditions m_errorLog.AddEntry(new ErrorLog.Record(true, ViewGenErrorCode.ErrorPatternConditionError, Strings.Viewgen_ErrorPattern_DuplicateConditionValue( BuildCommaSeparatedErrorString <MemberPath>(condMembersValues.Keys) ), ToIEnum(firstLCWForCondition[condMembersValues].OnlyInputCell, leftCellWrapper.OnlyInputCell), "")); } } else { setOfconditions.Add(condMembersValues); //Remember which cell the condition came from.. used for error reporting firstLCWForCondition.Add(condMembersValues, leftCellWrapper); } } } //foreach fragment related to the Extent we are working on }
public void CreateScript() { GSheetSettings setting = GSheetUtility.GetSettings(); if (setting == null) { return; } SpreadsheetsService service = setting.GetService(); WorksheetEntry worksheet = setting.GetWorkSheet(service, manager.SpreadSheetName, manager.WorkSheetName); CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink); CellFeed cellFeed = service.Query(cellQuery); string fieldFormat = setting.FieldTemplate.text; StringBuilder sb = new StringBuilder(); // Iterate through each cell, printing its value. foreach (CellEntry cell in cellFeed.Entries) { if (cell.Row > 1) { break; } string fieldType = "string"; if (cell.Value[0] == 'n') { fieldType = "int"; } else if (cell.Value[0] == 'f') { fieldType = "float"; } string fieldScript = fieldFormat.Replace("{FieldName}", cell.Value).Replace("{LowerCaseFieldName}", cell.Value.ToLower()).Replace("{FieldType}", fieldType); sb.Append(fieldScript); } string dataFormat = setting.DataTemplate.text; string dataScript = dataFormat.Replace("{WorkSheetName}", manager.WorkSheetName).Replace("{FieldList}", sb.ToString()); StringBuilder dataPathSB = new StringBuilder(setting.ScriptPath); if (setting.ScriptPath[setting.ScriptPath.Length - 1] != '/') { dataPathSB.Append("/"); } dataPathSB.Append(manager.WorkSheetName); dataPathSB.Append("Data.cs"); System.IO.File.WriteAllText(dataPathSB.ToString(), dataScript); string editorFormat = setting.DataEditorTemplate.text; string editorScript = editorFormat.Replace("{WorkSheetName}", manager.WorkSheetName); StringBuilder editorPathSB = new StringBuilder(setting.EditorScriptPath); if (setting.EditorScriptPath [setting.EditorScriptPath.Length - 1] != '/') { editorPathSB.Append("/"); } editorPathSB.Append(manager.WorkSheetName); editorPathSB.Append("DataEditor.cs"); System.IO.File.WriteAllText(editorPathSB.ToString(), editorScript); AssetDatabase.Refresh(); }
public CellFeed Query(CellQuery cellQuery) { Debug.WriteLine("Try CellQuery"); return(Service.Query(cellQuery)); }