public async Task <User> GetUser(string key) { List <UserHistory> userHistory = new List <UserHistory>(); //throw new System.NotImplementedException(); var scannerOptions = new ScannerOptions { TableName = "dewey_users", Filter = new PrefixFilter(key) }; using (IScanner scanner = await StargateApi.CreateScannerAsync(scannerOptions)) { // int count = scanner.Count(); foreach (CellSet result in scanner) { userHistory.AddRange( result.GroupBy(a => a.Identifier.Row).Select(a => new UserHistory(a.Key, new CellSet(a)) )); } } return(User.CreateUser(userHistory)); }
public void IncompleteXmlTagInsideXmlTagBreaksOutOfXmlTagWhenInIntelliSenseMode() { Scanner scanner = new Scanner(new ErrorHandler()); ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; scanner.Options = scannerOptions; scanner.SetSource( "<div>\n" + " <a \n" + "</div>"); AssertMatchToken(scanner, TokenType.XmlTagStart); AssertMatchToken(scanner, TokenType.XmlTagName, "div"); AssertMatchToken(scanner, TokenType.XmlTagEnd); AssertMatchToken(scanner, TokenType.XmlText, "\n "); AssertMatchToken(scanner, TokenType.XmlTagStart); AssertMatchToken(scanner, TokenType.XmlTagName, "a"); AssertMatchToken(scanner, TokenType.XmlAttributeMemberSelect, " "); AssertMatchToken(scanner, TokenType.XmlAttributeMemberSelect, "\n"); // When in IntelliSense mode the scanner should drop out of a tag if it finds a '<' AssertMatchToken(scanner, TokenType.XmlTagStart); AssertMatchToken(scanner, TokenType.XmlForwardSlash); AssertMatchToken(scanner, TokenType.XmlTagName, "div"); AssertMatchToken(scanner, TokenType.XmlTagEnd); AssertEOF(); }
public async Task <IEnumerable <User> > GetUsers(bool?isDelete = null) { List <UserHistory> userHistory = new List <UserHistory>(); //throw new System.NotImplementedException(); var scannerOptions = new ScannerOptions { TableName = "dewey_users", Filter = new PrefixFilter(string.Empty) }; using (IScanner scanner = await StargateApi.CreateScannerAsync(scannerOptions)) { // int count = scanner.Count(); foreach (CellSet result in scanner) { userHistory.AddRange( result.GroupBy(a => a.Identifier.Row).Select(a => new UserHistory(a.Key, new CellSet(a)) )); } } IEnumerable <User> users = userHistory .GroupBy(a => a.UserKey) .Select(a => User.CreateUser(a.ToList())); if (isDelete.HasValue) { users = users.Where(a => a.IsDeleted == isDelete); } return(users); }
public void Sync(IComponentSerializer ser) { if (ser.IsReader) { int option = 0; ser.Sync(nameof(_scannerOptions), ref option); _scannerOptions = (ScannerOptions)option; } else { int option = (int)_scannerOptions; ser.Sync(nameof(_scannerOptions), ref option); } ser.Sync(nameof(_isVBlank), ref _isVBlank); ser.Sync(nameof(_framebuffer), ref _framebuffer, false); ser.Sync(nameof(_isTextInversed), ref _isTextInversed); ser.Sync(nameof(_cyclesPerVBlank), ref _cyclesPerVBlank); ser.Sync(nameof(_cyclesPerVBlankPreset), ref _cyclesPerVBlankPreset); ser.Sync(nameof(_cyclesPerVSync), ref _cyclesPerVSync); ser.Sync(nameof(_cyclesPerFlash), ref _cyclesPerFlash); ser.Sync(nameof(_vCountPreset), ref _vCountPreset); ser.Sync(nameof(_vLineLeaveVBlank), ref _vLineLeaveVBlank); ser.Sync(nameof(_charSet), ref _charSet, false); ser.Sync(nameof(_isCellDirty), ref _isCellDirty, false); ser.Sync(nameof(_isMonochrome), ref _isMonochrome); }
public void ParseXmlElementWithSingleQuotesAroundAttribute() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<tag attr='value'/>"); TemplateNode template = parser.ParseTemplate(); // Template has 1 XML Element XmlElement xmlElement = (XmlElement)template.Content[0]; // Element has 1 Attribute Assert.AreEqual(1, xmlElement.Attributes.Count); XmlAttribute xmlAttribute = (XmlAttribute)xmlElement.Attributes[0]; Assert.AreEqual("attr", xmlAttribute.Name); // Element has 1 XML text node Assert.AreEqual(1, xmlAttribute.Content.Count); XmlTextNode xmlTextNode = (XmlTextNode)xmlAttribute.Content[0]; Assert.AreEqual("value", xmlTextNode.Text); AssertNoErrors(parser); }
public void ParsePartialNVReferenceWithDollarIdentDotIdentLParen() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.LinkToRemote("); TemplateNode template = parser.ParseTemplate(); // Check errors Assert.AreEqual(2, parser.Errors.Count); AssertError("Expected expression, was 'Error'", new Position(1, 20, 1, 20), parser.Errors[0]); AssertError("Expected 'NVRParen' but was 'Error'", new Position(1, 20, 1, 20), parser.Errors[1]); // Check the TemplateNode Assert.AreEqual(1, template.Content.Count); NVReference nvReference = (NVReference)template.Content[0]; Assert.AreEqual("Ajax", nvReference.Designator.Name); Assert.AreEqual(1, nvReference.Designator.Selectors.Count); NVSelector selector = nvReference.Designator.Selectors[0]; Assert.AreEqual("LinkToRemote", selector.Name); Assert.AreEqual(0, selector.Actuals.Count); }
public ScannerFileEnumerator(string directory, ScannerOptions options) : base(directory, GetEnumerationOptions(options)) { _options = options; _shouldScan = options.ShouldScanFilePredicate ?? s_truePredicate; _shouldRecurse = options.ShouldRecursePredicate ?? s_truePredicate; }
public void ParsePartialNVReferenceWithDollarIdentDotInXmlElement() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser( "<tag>\n" + " $Ajax.\n" + "</tag>"); TemplateNode templateNode = parser.ParseTemplate(); // Check the TemplateNode Assert.AreEqual(1, templateNode.Content.Count); XmlElement xmlElement = (XmlElement)templateNode.Content[0]; NVReference nvReference = (NVReference)xmlElement.Content[1]; Assert.AreEqual("Ajax", nvReference.Designator.Name); Assert.AreEqual(1, nvReference.Designator.Selectors.Count); AssertPosition(new Position(1, 1, 3, 7), xmlElement.Position); AssertPosition(new Position(2, 3, 2, 9), nvReference.Position); AssertPosition(new Position(2, 3, 2, 9), nvReference.Designator.Position); AssertPosition(new Position(2, 8, 2, 9), nvReference.Designator.Selectors[0].Position); }
public async Task <IEnumerable <File> > GetUserFile(string userKey, bool?isDelete = null) { List <FileHistory> fileHistory = new List <FileHistory>(); //throw new System.NotImplementedException(); var scannerOptions = new ScannerOptions { TableName = "dewey_files", Filter = new PrefixFilter(userKey), }; using (IScanner scanner = await StargateApi.CreateScannerAsync(scannerOptions)) { // int count = scanner.Count(); foreach (CellSet result in scanner) { fileHistory.AddRange( result.GroupBy(a => a.Identifier.Row).Select(a => new FileHistory(a.Key, new CellSet(a)) )); } IEnumerable <File> files = fileHistory .GroupBy(a => a.KeyUserFile) .Select(a => File.CreateFile(a.ToList())); if (isDelete.HasValue) { files = files.Where(a => a.IsDeleted == isDelete); } return(files); } }
/// <summary> /// Converts the specified options to an XML document with /// filter options as embedded JSON. /// </summary> /// <param name="options">The options.</param> public string Convert(ScannerOptions options) { var xml = new XElement(_scannerName); if (!string.IsNullOrEmpty(options.StartRow)) { xml.Add(new XAttribute(_startRowName, _codec.Encode(options.StartRow))); } if (!string.IsNullOrEmpty(options.StopRow)) { xml.Add(new XAttribute(_stopRowName, _codec.Encode(options.StopRow))); } if (options.BatchSize.HasValue) { xml.Add(new XAttribute(_batchSizeName, options.BatchSize)); } if (options.Filter != null) { xml.Add(new XElement(_filterName) { Value = options.Filter.ConvertToJson(_codec).ToString() }); } return(xml.ToString()); }
protected static Parser GetNewParser(ScannerOptions scannerOptions, string template) { Scanner scanner = new Scanner(new ErrorHandler()); scanner.Options = scannerOptions; scanner.SetSource(template); return new Parser(scanner, new ErrorHandler()); }
private static EnumerationOptions GetEnumerationOptions(ScannerOptions options) { return(new EnumerationOptions { RecurseSubdirectories = options.RecurseSubdirectories, IgnoreInaccessible = true, ReturnSpecialDirectories = false, }); }
protected static Parser GetNewParser(ScannerOptions scannerOptions, string template) { Scanner scanner = new Scanner(new ErrorHandler()); scanner.Options = scannerOptions; scanner.SetSource(template); return(new Parser(scanner, new ErrorHandler())); }
public void DefaultScannersIncludeAllScanners() { var scanners = new ScannerOptions().Scanners.Select(t => t.GetType()).OrderBy(t => t.FullName).ToArray(); var allScanners = typeof(ScannerOptions).Assembly.GetExportedTypes() .Where(type => !type.IsAbstract && type.IsAssignableTo(typeof(DependencyScanner)) && type != typeof(RegexScanner)) .OrderBy(t => t.FullName) .ToArray(); Assert.NotEmpty(scanners); Assert.Equal(allScanners, scanners); }
public void XmlElementsHaveParentElements() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<outer><inner></inner></outer>"); TemplateNode templateNode = parser.ParseTemplate(); Assert.AreEqual( templateNode.Content[0], ((XmlElement)((XmlElement)templateNode.Content[0]).Content[0]).Parent); AssertNoErrors(parser); }
public void ParseForeachDirectiveWithStartOfReference() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "text #foreach($item in $collection) $ #end text"); TemplateNode templateNode = parser.ParseTemplate(); // Check Position, it should get to just after the '$' AssertPosition(new Position(1, 6, 1, 38), templateNode.Content[1].Position); Assert.AreEqual(2, parser.Errors.Count); }
public void ReferenceFollowedByReference() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.InstallScripts()\n$Form."); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Designator NVSelector designator = (NVSelector)templateNode.GetNodeAt(2, 7); AssertPosition(new Position(2, 6, 2, 7), designator.Position); }
public void AtEndOfUnclosedXmlElementWithAtLeastOneAttribute() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<a name=\"\" "); // ^ TemplateNode templateNode = parser.ParseTemplate(); AstNode astNode = templateNode.GetNodeAt(1, 11); Assert.IsAssignableFrom(typeof(XmlElement), astNode); AssertPosition(new Position(1, 1, 1, 16), astNode.Position); }
public void ParseDirectiveStartWithNoNameFollowedByWhitespace() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "# "); TemplateNode templateNode = parser.ParseTemplate(); // Ensure the whole directive is included AssertPosition(new Position(1, 1, 1, 3), templateNode.GetNodeAt(1, 1).Position); Assert.AreEqual(1, parser.Errors.Count); AssertError("Expected directive name", new Position(1, 3, 1, 3), parser.Errors[0]); }
public void SecondDesignatorSelector() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.InstallScripts."); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Get node at position AstNode astNode = templateNode.GetNodeAt(1, 22); Assert.AreEqual(typeof(NVSelector), astNode.GetType()); AssertPosition(new Position(1, 21, 1, 22), astNode.Position); // selectors include '.' }
public void ParseXmlElementWithEmptyAttributeValue() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<tag attr=\"\" />"); TemplateNode templateNode = parser.ParseTemplate(); // Element has 1 attribute with no content nodes XmlAttribute xmlAttribute = ((XmlAttribute)((XmlElement)templateNode.Content[0]).Attributes[0]); Assert.AreEqual(0, xmlAttribute.Content.Count); AssertNoErrors(parser); }
public void ReferenceFollowedByText() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax.InstallScripts() text\n text"); // ^ ^ TemplateNode templateNode = parser.ParseTemplate(); // XmlTextNode, it is only one text node XmlTextNode point1 = (XmlTextNode)templateNode.GetNodeAt(1, 24); XmlTextNode point2 = (XmlTextNode)templateNode.GetNodeAt(2, 2); AssertPosition(new Position(1, 23, 2, 13), point1.Position); AssertPosition(new Position(1, 23, 2, 13), point2.Position); }
public void AtEndOfUnclosedXmlTagWithOneAttributeInsideXmlContent() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<div>\n" + " <a name=\"\" \n" + // ^ "</div>"); TemplateNode templateNode = parser.ParseTemplate(); AstNode astNode = templateNode.GetNodeAt(2, 16); Assert.IsAssignableFrom(typeof(XmlElement), astNode); AssertPosition(new Position(2, 5, 2, 16), astNode.Position); }
public void InsideStringLiteralInReference() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$obj.Method(\""); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Get node at position AstNode astNode = templateNode.GetNodeAt(1, 14); //TODO finish //NVStringExpression stringExpr = (NVStringExpression)astNode; //Assert.AreEqual("", stringExpr.Value); //AssertPosition(new Position(1, 14, 1, 14), stringExpr.Position); }
public void IncompleteDirectiveFollowedByAnotherDirectiveBreaksOutOfFirstDirectiveParams() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "#component(\n" + "#component(MyComponent)"); TemplateNode templateNode = parser.ParseTemplate(); // Ensure that both directives have been parsed as separate directives Assert.AreEqual(2, templateNode.Content.Count); Assert.IsInstanceOfType(typeof(NVDirective), templateNode.Content[0]); Assert.IsInstanceOfType(typeof(NVDirective), templateNode.Content[1]); // Check the error about the incomplete directive Assert.AreEqual(1, parser.Errors.Count); AssertError("Incomplete directive.", new Position(2, 2, 2, 2), parser.Errors[0]); }
public void ParseXmlElementWithTwoAttributes() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "<tag attr1=\"\" attr2=\"\" />"); TemplateNode templateNode = parser.ParseTemplate(); // XML Element has 2 attributes XmlElement xmlElement = (XmlElement)templateNode.Content[0]; Assert.AreEqual(2, xmlElement.Attributes.Count); Assert.AreEqual("attr1", ((XmlAttribute)xmlElement.Attributes[0]).Name); Assert.AreEqual("attr2", ((XmlAttribute)xmlElement.Attributes[1]).Name); AssertNoErrors(parser); }
public void ParsePartialNVReferenceOnlyWithDollar() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$"); TemplateNode template = parser.ParseTemplate(); // Check errors Assert.AreEqual(1, parser.Errors.Count); Error error0 = parser.Errors[0]; Assert.AreEqual("Expected reference identifier", error0.Description); AssertPosition(new Position(1, 2, 1, 2), error0.Position); Assert.AreEqual(ErrorSeverity.Error, error0.Severity); // Check the TemplateNode Assert.AreEqual(1, template.Content.Count); Assert.AreEqual(typeof(NVReference), template.Content[0].GetType()); }
public void StartOfDesignator() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$"); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Check template Assert.AreEqual(1, templateNode.Content.Count); Assert.AreEqual(typeof(NVReference), templateNode.Content[0].GetType()); // Get node at position AstNode astNode = templateNode.GetNodeAt(1, 2); Assert.AreEqual(typeof(NVDesignator), astNode.GetType()); AssertPosition(new Position(1, 1, 1, 2), astNode.Position); }
public void ScanTest_MultiLineComment() { string content = @"/* comment */"; string vocabulary = @" \s WHITE_SPACE \$ NEW_LINE /\*(\.|\$)*\*/ MULTI_LINE_COMMENT"; var table = TransitionTable.FromVocabularyString(vocabulary); var options = new ScannerOptions { Transitions = table, BlackList = Empty <TokenTag> .Array }; var tokens = Scanner.Scan(content, options); tokens.Should().Be(new[] { MULTI_LINE_COMMENT("/* comment */"), }); }
public void InsideWhitespacePrecededByXmlElement() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, " <p>inside</p> "); // ^ ^ TemplateNode templateNode = parser.ParseTemplate(); AstNode astNode; // Get the first XmlTextNode astNode = templateNode.GetNodeAt(1, 2); Assert.AreEqual(" ", ((XmlTextNode)astNode).Text); // Get the second XmlTextNode astNode = templateNode.GetNodeAt(1, 17); Assert.AreEqual(" ", ((XmlTextNode)astNode).Text); }
public void InsideComponent() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "#component("); // ^ TemplateNode templateNode = parser.ParseTemplate(); // Check template NVDirective nvDirective = (NVDirective)templateNode.Content[0]; Assert.AreEqual("component", nvDirective.Name); // Get node at position AstNode astNode = templateNode.GetNodeAt(1, 12); Assert.AreEqual(typeof(NVDirective), astNode.GetType()); AssertPosition(new Position(1, 1, 1, 12), astNode.Position); }
public void ParsePartialNVReferenceWithDollarIdentDot() { ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; Parser parser = GetNewParser(scannerOptions, "$Ajax."); TemplateNode template = parser.ParseTemplate(); // Check errors Assert.AreEqual(1, parser.Errors.Count); Error error0 = parser.Errors[0]; Assert.AreEqual("Expected identifier", error0.Description); AssertPosition(new Position(1, 7, 1, 7), error0.Position); // Check the TemplateNode Assert.AreEqual(1, template.Content.Count); NVReference nvReference = (NVReference)template.Content[0]; Assert.AreEqual("Ajax", nvReference.Designator.Name); Assert.AreEqual(1, nvReference.Designator.Selectors.Count); AssertPosition(new Position(1, 6, 1, 7), nvReference.Designator.Selectors[0].Position); }
public void IncompleteXmlTagWithNoNameInsideXmlTagBreaksOutOfXmlTagWhenInIntelliSenseMode() { Scanner scanner = new Scanner(new ErrorHandler()); ScannerOptions scannerOptions = new ScannerOptions(); scannerOptions.EnableIntelliSenseTriggerTokens = true; scanner.Options = scannerOptions; scanner.SetSource( "<div>\n" + " < \n" + "</div>"); AssertMatchToken(scanner, TokenType.XmlTagStart); AssertMatchToken(scanner, TokenType.XmlTagName, "div"); AssertMatchToken(scanner, TokenType.XmlTagEnd); AssertMatchToken(scanner, TokenType.XmlText, "\n "); AssertMatchToken(scanner, TokenType.XmlTagStart); AssertMatchToken(scanner, TokenType.XmlAttributeMemberSelect, " "); AssertMatchToken(scanner, TokenType.XmlAttributeMemberSelect, "\n"); // When in IntelliSense mode the scanner should drop out of a tag if it finds a '<' AssertMatchToken(scanner, TokenType.XmlTagStart); AssertMatchToken(scanner, TokenType.XmlForwardSlash); AssertMatchToken(scanner, TokenType.XmlTagName, "div"); AssertMatchToken(scanner, TokenType.XmlTagEnd); AssertEOF(); }