private static ITestEntry CreateTestEntry(string value, RegexFactory regexFactory, StringMatchMode mode) { if (value.Length > 1) { if (value[0] == '"' && value[value.Length - 1] == '"') { return(new StringTestEntry(value.Substring(1, value.Length - 2), mode)); } if (value[0] == '\'' && value[value.Length - 1] == '\'') { return(new StringTestEntry(value.Substring(1, value.Length - 2), StringMatchMode.CompleteMatch)); } if (value[0] == '`' && value[value.Length - 1] == '`') { try { var regex = new Regex(value.Substring(1, value.Length - 2), RegexOptions.Compiled | RegexOptions.IgnoreCase); return(new RegexTestEntry(regex)); } catch (Exception) { return(new ConstTestEntry(false)); } } } if (RegexFromQuery.IsQuery(value)) { return(new RegexTestEntry(regexFactory(value, mode))); } return(new StringTestEntry(value, mode)); }
/// <summary> /// Enumerates the given directory and filters based on specified searchPattern /// </summary> /// <param name="blobContainerClient">Directory to enumerate on</param> /// <param name="searchPattern">Search pattern to apply</param> /// <param name="prefix">Prefix to apply</param> /// <returns>Enumerable of strings which contains all found blobs</returns> public static IEnumerable <string> EnumerateDirectory(this BlobContainerClient blobContainerClient, string searchPattern, string prefix) { #region validation if (blobContainerClient == null) { throw new ArgumentNullException(nameof(blobContainerClient)); } if (string.IsNullOrEmpty(searchPattern)) { throw new ArgumentNullException(nameof(searchPattern)); } #endregion var result = new List <string>(); Regex blobNameRegex = RegexFactory.CreateRegexFromSearchPattern(searchPattern); foreach (var listBlobItem in blobContainerClient.GetBlobs(prefix: prefix)) { string itemName = listBlobItem.Name; if (!string.IsNullOrEmpty(itemName) && blobNameRegex.IsMatch(itemName[(itemName.LastIndexOf(DIRECTORY_SEPARATOR_CHAR + prefix + DIRECTORY_SEPARATOR_CHAR) + prefix.Length + 2)..]))
private static ITestEntry CreateTestEntry(string value, RegexFactory regexFactory, bool wholeMatch, bool strictMode) { if (value.Length > 1) { if (value[0] == '"' && value[value.Length - 1] == '"') { return(new StringTestEntry(value.Substring(1, value.Length - 2), wholeMatch, true)); } if (value[0] == '`' && value[value.Length - 1] == '`') { try { var regex = new Regex(value.Substring(1, value.Length - 2), RegexOptions.Compiled | RegexOptions.IgnoreCase); return(new RegexTestEntry(regex)); } catch (Exception) { return(new ConstTestEntry(false)); } } } if (value.Contains("*") || value.Contains("?")) { return(new RegexTestEntry(regexFactory(value, wholeMatch, strictMode))); } return(new StringTestEntry(value, wholeMatch, strictMode)); }
public static void Main(string[] args) { string dados = "O numero de celular da Ana: (95) 99167-8545"; RegexFactory factory = new RegexFactory(); var numeros = factory.GetResult(dados); numeros.ForEach(Console.WriteLine); }
/// <summary> /// Initializes the Path Element with the given Match /// </summary> /// <param name="match">Match object</param> /// <param name="index">Index of the path element in the Path data.</param> public override void Initialize(Match match, int index) { Index = index; var main = match.Groups["Main"]; Data = main.Value; var elements = new List <ICanvasPathElement>(); foreach (PathElementType type in Enum.GetValues(typeof(PathElementType))) { foreach (Capture elementCapture in match.Groups[type.ToString()].Captures) { var elementRootIndex = elementCapture.Index; var regex = RegexFactory.GetRegex(type); var elementMatch = regex.Match(elementCapture.Value); var isRelative = false; // Process the 'Main' Group which contains the Path Command and // corresponding attributes if (elementMatch.Groups["Main"].Captures.Count == 1) { var figure = PathElementFactory.CreatePathElement(type, elementMatch, elementRootIndex); elements.Add(figure); isRelative = figure.IsRelative; } // Process the 'Additional' Group which contains just the attributes elements.AddRange(from Capture capture in elementMatch.Groups["Additional"].Captures select PathElementFactory.CreateAdditionalPathElement(type, capture, elementRootIndex + capture.Index, isRelative)); } } // Sort the path elements based on their index value _elements.AddRange(elements.OrderBy(e => e.Index)); if (_elements.Count <= 0) { return; } // Check if the last path element in the figure is an ClosePathElement // which would indicate that the path needs to be closed. Otherwise, // add a default ClosePathElement at the end to indicate that the path // is not closed. var lastElement = _elements.ElementAt(_elements.Count - 1); if ((lastElement as ClosePathElement) == null) { _elements.Add(PathElementFactory.CreateDefaultPathElement(PathElementType.ClosePath)); } // Validation Count will be the cumulative sum of the validation count // of child elements of the PathFigure ValidationCount = _elements.Sum(x => x.ValidationCount); }
public void CreateJob() { int serviceTaskId = -1; AutoResetEvent serviceReady = new AutoResetEvent(false); // Just using this to wait for vehicle at node. using (ClientWrapper clientWrapper = new ClientWrapper()) { clientWrapper.Configure(endpointSettings); // Inline delegate just for demo. Don't shoot the messenger. // Here we just tell the servicing client we have finished interracting with the vehicle and // it can do other jobs. clientWrapper.ServicingClient.ServiceRequest += delegate(ServiceStateData serviceStateData) { if (serviceTaskId >= 0 && serviceStateData.TaskId == serviceTaskId) { // This is basically acknowledging the vehicle is at the node, so we can release the tote clientWrapper.ServicingClient.SetServiceComplete(serviceTaskId); serviceReady.Set(); } }; JobData jobData = clientWrapper.JobBuilderClient.CreateJob(); // Creating the pick task NodeData pickNode = clientWrapper.NodeCache.GetRandomNode(RegexFactory.ContainsSubStringCaseInvariant("A-Pickup")); // We are assumming the vehicle is at the node, but it might not be, so just in case lets just make sure it is. // Create a service task serviceTaskId = clientWrapper.JobBuilderClient.CreateManualLoadHandling(jobData.RootOrderedListTaskId, pickNode.MapItemId); // Now lets create an actual receive task, with a '4' to passively receive a load int picktaskId = clientWrapper.JobBuilderClient.CreateExecution(jobData.RootOrderedListTaskId, pickNode.MapItemId); clientWrapper.JobBuilderClient.IssueDirective(picktaskId, "DockType", (byte)4); // Creating the drop task NodeData dropNode = clientWrapper.NodeCache.GetRandomNode(RegexFactory.ContainsSubStringCaseInvariant("Dropoff")); int dropTaskId = clientWrapper.JobBuilderClient.CreateExecution(jobData.RootOrderedListTaskId, dropNode.MapItemId); // '3' is passively drop a load clientWrapper.JobBuilderClient.IssueDirective(dropTaskId, "DockType", (byte)3); // It is ideal to wait at the pick node - sends the vehicle back to the pick node. The job will be complete once it is here // so if it has to do something else (like charge) it is free to get other jobs. clientWrapper.JobBuilderClient.CreateMovingTask(jobData.RootOrderedListTaskId, pickNode.MapItemId); clientWrapper.JobBuilderClient.Commit(jobData.JobId); if (!serviceReady.WaitOne(TimeSpan.FromSeconds(20))) { throw new TimeoutException("timeout on waiting for vehicle at the pick node"); } } }
/// <summary> /// Determines if a a property with given specification is public settable or not /// </summary> /// <param name="propertyName"></param> /// <param name="propertyCondition"></param> /// <param name="propertyContent"></param> /// <returns></returns> /// ToDo: Make less complex public static bool HasPropertyPublicSetter(string propertyName, string propertyCondition, string propertyContent) { if (string.IsNullOrWhiteSpace(propertyContent) && string.IsNullOrEmpty(propertyCondition)) { return(false); } if (propertyContent != null && string.IsNullOrEmpty(propertyCondition) && propertyContent.Contains( string.Format(MsBuildStringUtilities.FormatProvider, "{0:Property}", propertyName))) { return(true); } if (string.IsNullOrEmpty(propertyCondition)) { return(false); } RegexFactory factory = new RegexFactory(); Regex selfIsEmptyCheck = factory.CreatePropertyConditionSelfCheckEmptyRegex(propertyName); if (selfIsEmptyCheck.IsMatch(propertyCondition)) { return(true); } Regex selfIsNotEmptyCheck = factory.CreatePropertyConditionSelfCheckIsNotEmptyEmptyRegex(propertyName); return(selfIsNotEmptyCheck.IsMatch(propertyCondition) && !string.IsNullOrWhiteSpace(propertyContent) && propertyContent.Contains(string.Format(MsBuildStringUtilities.FormatProvider, "{0:Property}", propertyName))); }
/// <inheritdoc cref="Solver{T}.Convert"/> protected override IngredientList[] Convert(string[] rawInput) => RegexFactory <IngredientList> .ConstructObjects(IngredientList.PATTERN, rawInput, RegexOptions.Compiled);
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathFigureType.RoundedRectangleFigure)); }
/// <summary> /// Gets the Brush Element Attributes from the Match /// </summary> /// <param name="match">Match object</param> protected override void GetAttributes(Match match) { float startX, startY, endX, endY; // Start Point Single.TryParse(match.Groups["StartX"].Value, out startX); Single.TryParse(match.Groups["StartY"].Value, out startY); _startPoint = new Vector2(startX, startY); // End Point Single.TryParse(match.Groups["EndX"].Value, out endX); Single.TryParse(match.Groups["EndY"].Value, out endY); _endPoint = new Vector2(endX, endY); // Opacity (optional) var group = match.Groups["Opacity"]; if (group.Success) { Single.TryParse(group.Value, out _opacity); } // Alpha Mode (optional) group = match.Groups["AlphaMode"]; if (group.Success) { Enum.TryParse(group.Value, out _alphaMode); } // Buffer Precision (optional) group = match.Groups["BufferPrecision"]; if (group.Success) { Enum.TryParse(group.Value, out _bufferPrecision); } // Edge Behavior (optional) group = match.Groups["EdgeBehavior"]; if (group.Success) { Enum.TryParse(group.Value, out _edgeBehavior); } // Pre Interpolation ColorSpace (optional) group = match.Groups["PreColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _preInterpolationColorSpace); } // Post Interpolation ColorSpace (optional) group = match.Groups["PostColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _postInterpolationColorSpace); } // GradientStops group = match.Groups["GradientStops"]; if (group.Success) { _gradientStops.Clear(); foreach (Capture capture in group.Captures) { var gradientMatch = RegexFactory.GradientStopRegex.Match(capture.Value); if (!gradientMatch.Success) { continue; } float position; Color color; // Main Attributes var main = gradientMatch.Groups["Main"]; if (main.Success) { var mainMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Main).Match(main.Value); Single.TryParse(mainMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(mainMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } // Additional Attributes var additional = gradientMatch.Groups["Additional"]; if (!additional.Success) { continue; } foreach (Capture addCapture in additional.Captures) { var addMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Additional).Match(addCapture.Value); Single.TryParse(addMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(addMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } } // Sort the stops based on their position if (_gradientStops.Any()) { _gradientStops = _gradientStops.OrderBy(g => g.Position).ToList(); } } }
/// <summary> /// Parses the Path data in string format and converts it to <see cref="CanvasGeometry"/>. /// </summary> /// <param name="resourceCreator">ICanvasResourceCreator</param> /// <param name="pathData">Path data</param> /// <returns><see cref="CanvasGeometry"/></returns> internal static CanvasGeometry Parse(ICanvasResourceCreator resourceCreator, string pathData) { var pathFigures = new List <ICanvasPathElement>(); var matches = RegexFactory.CanvasGeometryRegex.Matches(pathData); // If no match is found or no captures in the match, then it means // that the path data is invalid. if (matches.Count == 0) { ThrowForZeroCount(); } // If the match contains more than one captures, it means that there are multiple FillRuleElements present in the path data. // There can be only one FillRuleElement in the path data (at the beginning). if (matches.Count > 1) { ThrowForNotOneCount(); } var figures = new List <ICanvasPathElement>(); foreach (PathFigureType type in Enum.GetValues(typeof(PathFigureType))) { foreach (Capture figureCapture in matches[0].Groups[type.ToString()].Captures) { var figureRootIndex = figureCapture.Index; var regex = RegexFactory.GetRegex(type); var figureMatch = regex.Match(figureCapture.Value); if (!figureMatch.Success) { continue; } // Process the 'Main' Group which contains the Path Command and // corresponding attributes var figure = PathElementFactory.CreatePathFigure(type, figureMatch, figureRootIndex); figures.Add(figure); // Process the 'Additional' Group which contains just the attributes figures.AddRange(from Capture capture in figureMatch.Groups["Additional"].Captures select PathElementFactory.CreateAdditionalPathFigure(type, capture, figureRootIndex + capture.Index, figure.IsRelative)); } } // Sort the figures by their indices pathFigures.AddRange(figures.OrderBy(f => f.Index)); if (pathFigures.Count > 0) { // Check if the first element in the _figures list is a FillRuleElement // which would indicate the fill rule to be followed while creating the // path. If it is not present, then insert a default FillRuleElement at // the beginning. if ((pathFigures.ElementAt(0) as FillRuleElement) == null) { pathFigures.Insert(0, PathElementFactory.CreateDefaultPathElement(PathFigureType.FillRule)); } } else { return(null); } // Perform validation to check if there are any invalid characters in the path data that were not captured var preValidationCount = RegexFactory.ValidationRegex.Replace(pathData, string.Empty).Length; var postValidationCount = pathFigures.Sum(x => x.ValidationCount); // If there are invalid characters, extract them and add them to the ArgumentException message if (preValidationCount != postValidationCount) {
/// <summary> /// Gets the Brush Element Attributes from the Match /// </summary> /// <param name="match">Match object</param> protected override void GetAttributes(Match match) { float centerX, centerY; // RadiusX Single.TryParse(match.Groups["RadiusX"].Value, out _radiusX); // Sanitize by taking the absolute value _radiusX = Math.Abs(_radiusX); // RadiusY Single.TryParse(match.Groups["RadiusY"].Value, out _radiusY); // Sanitize by taking the absolute value _radiusY = Math.Abs(_radiusY); // CenterX Single.TryParse(match.Groups["CenterX"].Value, out centerX); // CenterY Single.TryParse(match.Groups["CenterY"].Value, out centerY); _center = new Vector2(centerX, centerY); // Opacity (optional) var group = match.Groups["Opacity"]; if (group.Success) { Single.TryParse(group.Value, out _opacity); } // Origin Offset (optional) group = match.Groups["OriginOffset"]; if (group.Success) { float offsetX, offsetY; Single.TryParse(match.Groups["OffsetX"].Value, out offsetX); Single.TryParse(match.Groups["OffsetY"].Value, out offsetY); _originOffset = new Vector2(offsetX, offsetY); } // Alpha Mode (optional) group = match.Groups["AlphaMode"]; if (group.Success) { Enum.TryParse(group.Value, out _alphaMode); } // Buffer Precision (optional) group = match.Groups["BufferPrecision"]; if (group.Success) { Enum.TryParse(group.Value, out _bufferPrecision); } // Edge Behavior (optional) group = match.Groups["EdgeBehavior"]; if (group.Success) { Enum.TryParse(group.Value, out _edgeBehavior); } // Pre Interpolation ColorSpace (optional) group = match.Groups["PreColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _preInterpolationColorSpace); } // Post Interpolation ColorSpace (optional) group = match.Groups["PostColorSpace"]; if (group.Success) { Enum.TryParse(group.Value, out _postInterpolationColorSpace); } // Gradient Stops group = match.Groups["GradientStops"]; if (group.Success) { _gradientStops.Clear(); foreach (Capture capture in group.Captures) { var gradientMatch = RegexFactory.GradientStopRegex.Match(capture.Value); if (!gradientMatch.Success) { continue; } float position; Color color; // Main Attributes var main = gradientMatch.Groups["Main"]; if (main.Success) { var mainMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Main).Match(main.Value); Single.TryParse(mainMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(mainMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } // Additional Attributes var additional = gradientMatch.Groups["Additional"]; if (!additional.Success) { continue; } foreach (Capture addCapture in additional.Captures) { var addMatch = RegexFactory.GetAttributesRegex(GradientStopAttributeType.Additional).Match(addCapture.Value); Single.TryParse(addMatch.Groups["Position"].Value, out position); color = ColorParser.Parse(addMatch); _gradientStops.Add(new CanvasGradientStop() { Color = color, Position = position }); } } // Sort the stops based on their position if (_gradientStops.Any()) { _gradientStops = _gradientStops.OrderBy(g => g.Position).ToList(); } } }
/// <summary> /// Gets the Regex for extracting Brush Element Attributes /// </summary> /// <returns>Regex</returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(BrushType.LinearGradient)); }
/// <inheritdoc cref="Solver{T}.Convert"/> protected override Instruction[] Convert(string[] rawInput) => RegexFactory <Instruction> .ConstructObjects(Instruction.PATTERN, rawInput, RegexOptions.Compiled);
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathElementType.Line)); }
/// <summary> /// Gets the Regex for extracting Brush Element Attributes /// </summary> /// <returns>Regex</returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(BrushType.SolidColor)); }
private Regex AssertRegex(string regexText) { regexText.Should().NotBeNullOrWhiteSpace("null, empty or whitespace-only regex is not valid for step definitions"); return(RegexFactory.Create(regexText)); // uses the same regex creation as real step definitions }
/// <inheritdoc cref="Solver{T}.Convert"/> protected override PasswordData[] Convert(string[] rawInput) => RegexFactory <PasswordData> .ConstructObjects(PATTERN, rawInput, RegexOptions.Compiled);
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns>Instance of <see cref="Regex"/></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathFigureType.PolygonFigure)); }
/// <summary> /// Parses the Path data in string format and converts it to CanvasGeometry. /// </summary> /// <param name="resourceCreator">ICanvasResourceCreator</param> /// <param name="pathData">Path data</param> /// <param name="logger">(Optional) For logging purpose. To log the set of /// CanvasPathBuilder commands, used for creating the CanvasGeometry, in /// string format.</param> /// <returns>CanvasGeometry</returns> public static CanvasGeometry Parse(ICanvasResourceCreator resourceCreator, string pathData, StringBuilder logger = null) { var pathFigures = new List <ICanvasPathElement>(); var matches = RegexFactory.CanvasGeometryRegex.Matches(pathData); // If no match is found or no captures in the match, then it means // that the path data is invalid. if ((matches == null) || (matches.Count == 0)) { throw new ArgumentException($"Invalid Path data!\nPath Data: {pathData}", nameof(pathData)); } // If the match contains more than one captures, it means that there // are multiple FillRuleElements present in the path data. There can // be only one FillRuleElement in the path data (at the beginning). if (matches.Count > 1) { throw new ArgumentException("Multiple FillRule elements present in Path Data! " + "There should be only one FillRule within the Path Data. " + "You can either remove additional FillRule elements or split the Path Data " + "into multiple Path Data and call the CanvasObject.CreateGeometry() method on each of them." + $"\nPath Data: {pathData}"); } var figures = new List <ICanvasPathElement>(); foreach (PathFigureType type in Enum.GetValues(typeof(PathFigureType))) { foreach (Capture figureCapture in matches[0].Groups[type.ToString()].Captures) { var figureRootIndex = figureCapture.Index; var regex = RegexFactory.GetRegex(type); var figureMatch = regex.Match(figureCapture.Value); if (!figureMatch.Success) { continue; } // Process the 'Main' Group which contains the Path Command and // corresponding attributes var figure = PathElementFactory.CreatePathFigure(type, figureMatch, figureRootIndex); figures.Add(figure); // Process the 'Additional' Group which contains just the attributes figures.AddRange(from Capture capture in figureMatch.Groups["Additional"].Captures select PathElementFactory.CreateAdditionalPathFigure(type, capture, figureRootIndex + capture.Index, figure.IsRelative)); } } // Sort the figures by their indices pathFigures.AddRange(figures.OrderBy(f => f.Index)); if (pathFigures.Count > 0) { // Check if the first element in the _figures list is a FillRuleElement // which would indicate the fill rule to be followed while creating the // path. If it is not present, then insert a default FillRuleElement at // the beginning. if ((pathFigures.ElementAt(0) as FillRuleElement) == null) { pathFigures.Insert(0, PathElementFactory.CreateDefaultPathElement(PathFigureType.FillRule)); } } // Perform validation to check if there are any invalid characters in the path data that were not captured var preValidationCount = RegexFactory.ValidationRegex.Replace(pathData, string.Empty).Length; var postValidationCount = pathFigures.Sum(x => x.ValidationCount); if (preValidationCount != postValidationCount) { throw new ArgumentException($"Path data contains invalid characters!\nPath Data: {pathData}", nameof(pathData)); } if (pathFigures.Count == 0) { return(null); } ICanvasPathElement lastElement = null; var currentPoint = Vector2.Zero; using (var pathBuilder = new CanvasPathBuilder(resourceCreator)) { foreach (var pathFigure in pathFigures) { currentPoint = pathFigure.CreatePath(pathBuilder, currentPoint, ref lastElement, logger); } return(CanvasGeometry.CreatePath(pathBuilder)); } }
/// <summary> /// Get the Regex for extracting Path Element Attributes /// </summary> /// <returns>Instance of <see cref="Regex"/></returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(PathElementType.SmoothQuadraticBezier)); }
/// <summary> /// Gets the Regex for extracting Brush Element Attributes /// </summary> /// <returns>Regex</returns> protected override Regex GetAttributesRegex() { return(RegexFactory.GetAttributesRegex(BrushType.RadialGradientHdr)); }