public void Add_Multiple_AddedToForward_UpdatedInverted() { var query = Guid.NewGuid().ToString(); var values = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var forward = new Mock <IIndex <string, string> >(); forward .Setup(x => x.Add(query, values)) .Raises(x => x.Added += null, query, values); var inverted = new Mock <IIndex <string, string> >(); foreach (var value in values) { inverted.Setup(x => x.Add(value, query)); } using var indexer = new Indexer <string, string>(forward.Object, inverted.Object); indexer.Add(query, values); forward.Verify(x => x.Add(query, values), Times.Once); foreach (var value in values) { inverted.Verify(x => x.Add(value, query), Times.Once); } }
private void OnFileCreated(object source, FileSystemEventArgs e) { using (new WriteLockCookie(_queueLock)) { var normalized = PathExtensions.NormalizePath(e.FullPath); var directory = Path.GetDirectoryName(normalized); _backgroundTaskQueue.QueueTask(directory, () => { var tokens = ParseTokens(normalized); Debug.WriteLine($"\"{e.FullPath}\" created, indexing. Thread = {Thread.CurrentThread.ManagedThreadId}"); Indexer.Add(normalized, tokens); }, normalized); } }
public void Reload() { Options.Clear(); Indexer.Clear(); Dictionary <string, KeyCode> config = Controls.GetConfig(); ResetPos(); Options.Add("Reset Controls", new ButtonOption(() => { Controls.ResetConfig(); Reload(); return(true); })); Indexer.Add("Reset Controls"); foreach (var c in config) { Options.Add(c.Key, new KeyOption(c.Key, c.Value)); Indexer.Add(c.Key); } }
public void Add_Null_DoNothing() { var dummy = new[] { Guid.NewGuid().ToString() }; var forward = new Mock <IIndex <string, string> >(); forward .Setup(x => x.Add(It.IsAny <string>(), It.IsAny <IEnumerable <string> >())) .Raises(x => x.Added += null, It.IsAny <string>(), dummy); var inverted = new Mock <IIndex <string, string> >(); inverted.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <string>())); using var indexer = new Indexer <string, string>(forward.Object, inverted.Object); indexer.Add(null, new string[0]); forward.Verify(x => x.Add(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()), Times.Never); inverted.Verify(x => x.Add(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void Add_Single_AddedToForward_UpdatedInverted() { var text = Guid.NewGuid().ToString(); var query = Guid.NewGuid().ToString(); var forward = new Mock <IIndex <string, string> >(); forward .Setup(x => x.Add(query, text)) .Raises(x => x.Added += null, query, new [] { text }); var inverted = new Mock <IIndex <string, string> >(); inverted.Setup(x => x.Add(text, query)); using var indexer = new Indexer <string, string>(forward.Object, inverted.Object); indexer.Add(query, text); forward.Verify(x => x.Add(query, text), Times.Once); inverted.Verify(x => x.Add(text, query), Times.Once); }
public void Run() { var ds = new DataSet(); Query batchQ = new Query(SourceName); batchQ.RecordCount = BatchSize; do { if (ds.Tables.Contains(SourceName)) { ds.Tables[SourceName].Clear(); } Dalc.Load(ds, batchQ); if (Transaction != null) { Transaction.Begin(); } foreach (DataRow r in ds.Tables[SourceName].Rows) { Indexer.Add(r); if (Indexer.DelayedIndexing) { Indexer.RunDelayedIndexing(); } } if (Transaction != null) { Transaction.Commit(); } // next batch batchQ.StartRecord += BatchSize; } while (ds.Tables[SourceName].Rows.Count >= BatchSize); }
public async Task Subscribe(string path, string pattern = null) { var normalizedFolder = PathExtensions.NormalizePath(path); if (!Directory.Exists(normalizedFolder)) { Debug.WriteLine($"Directory \"{path}\" not exists. Thread = {Thread.CurrentThread.ManagedThreadId}"); return; } var filter = string.IsNullOrWhiteSpace(pattern) ? DefaultFilePattern : pattern.ToLowerInvariant(); using (new UpgradeableReadLockCookie(_subscriptionLock)) { if (!_watchers.TryGetValue(normalizedFolder, out var watcher)) { using (new WriteLockCookie(_subscriptionLock)) { if (TryGetAndSubscribeWatcher(normalizedFolder, filter, out watcher)) { _watchers[normalizedFolder] = watcher; } else { return; } } } else { if (watcher.Filters.Contains(filter, StringComparer.InvariantCultureIgnoreCase)) { return; } using (new WriteLockCookie(_subscriptionLock)) watcher.Filters.Add(filter); } } var tasks = new List <Task>(); using (new WriteLockCookie(_queueLock)) { tasks.AddRange(DirectoryExtensions .GetFilesSafe(normalizedFolder, filter) .Select(x => { var normalizedFile = PathExtensions.NormalizePath(x); return(_backgroundTaskQueue.QueueTask(normalizedFolder, () => { var tokens = ParseTokens(normalizedFile); Debug.WriteLine($"Start indexing \"{x}\". Thread = {Thread.CurrentThread.ManagedThreadId}"); Indexer.Add(normalizedFile, tokens); }, normalizedFile)); })); } await Task.WhenAll(tasks).IgnoreExceptions(); await Task.Yield(); }
public void Rebuild() { // If there's an existing MeshGroup object, get rid of it if (transform.FindChild("MeshGroup") != null) { DestroyImmediate(transform.FindChild("MeshGroup").gameObject); } if (brushes != null && brushes.Count > 0) { // Ensure any brush objects that have been deleted by the user are removed from the brush sequence for (int i = 0; i < brushes.Count; i++) { if (brushes[i] == null) { brushes.RemoveAt(i); i--; } } CSG current = null; // Iterate through each brush in sequence for (int i = 0; i < brushes.Count; i++) { Brush.CSGMode mode = brushes[i].Mode; // Generate the CSG geometry for the brush CSG brushGeometry = brushes[i].GenerateCSG(); brushGeometry.SetShared(brushes[i].SharedBrushData); if (i == 0) { // The first brush is always added to the space (rather than subtracted) current = brushGeometry; } else { // For every brush after the first one, carry out the correct operation if (mode == Brush.CSGMode.Subtract) { current = current.Subtract(brushGeometry); } else if (mode == Brush.CSGMode.Union) { current = current.Union(brushGeometry); } else if (mode == Brush.CSGMode.Intersect) { current = current.Intersect(brushGeometry); } } } // Now that the final CSG has been calculated, fetch the polygons (mixture of triangles and quads) Polygon[] polygons = current.Polygons; // Create polygon subsets for each material Dictionary <Material, List <Polygon> > polygonMaterialTable = new Dictionary <Material, List <Polygon> >(); // Iterate through every polygon adding it to the appropiate material list foreach (Polygon polygon in current.Polygons) { Material material = ((SharedBrushData)polygon.Shared).Material; if (!polygonMaterialTable.ContainsKey(material)) { polygonMaterialTable.Add(material, new List <Polygon>()); } polygonMaterialTable[material].Add(polygon); } // Create a grouping object which will act as a parent for all the per material meshes meshGroup = new GameObject("MeshGroup"); meshGroup.transform.parent = this.transform; // Create a separate mesh for polygons of each material so that we batch by material foreach (KeyValuePair <Material, List <Polygon> > polygonMaterialGroup in polygonMaterialTable) { Mesh mesh = new Mesh(); List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <Color> colors = new List <Color>(); List <int> triangles = new List <int>(); // Setup an indexer that tracks unique vertices, so that we reuse vertex data appropiately Indexer indexer = new Indexer(); // Iterate through every polygon and triangulate foreach (Polygon polygon in polygonMaterialGroup.Value) { List <int> indices = new List <int>(); for (int i = 0; i < polygon.Vertices.Length; i++) { // Each vertex must know about its shared data for geometry tinting polygon.Vertices[i].Shared = polygon.Shared; // If the vertex is already in the indexer, fetch the index otherwise add it and get the added index int index = indexer.Add(polygon.Vertices[i]); // Put each vertex index in an array for use in the triangle generation indices.Add(index); } // Triangulate the n-sided polygon and allow vertex reuse by using indexed geometry for (int i = 2; i < indices.Count; i++) { triangles.Add(indices[0]); triangles.Add(indices[i - 1]); triangles.Add(indices[i]); } } // Create the relevant buffers from the vertex array for (int i = 0; i < indexer.Vertices.Count; i++) { vertices.Add(indexer.Vertices[i].Position); normals.Add(indexer.Vertices[i].Normal); uvs.Add(indexer.Vertices[i].UV); colors.Add(((SharedBrushData)indexer.Vertices[i].Shared).BrushTintColor); } // Set the mesh buffers mesh.vertices = vertices.ToArray(); mesh.normals = normals.ToArray(); mesh.colors = colors.ToArray(); mesh.uv = uvs.ToArray(); mesh.triangles = triangles.ToArray(); // Optionally you can turn these on to ensure normals are correct and also generate tangents // mesh.RecalculateNormals(); // GenerateTangents(mesh); GameObject materialMesh = new GameObject("MaterialMesh", typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider)); materialMesh.transform.parent = meshGroup.transform; // Set the mesh to be rendered materialMesh.GetComponent <MeshFilter>().mesh = mesh; // Set the collision mesh materialMesh.GetComponent <MeshCollider>().sharedMesh = mesh; materialMesh.renderer.material = polygonMaterialGroup.Key; } } }
public IActionResult Add(IndexRequest request) { _indexer.Add(request); return(NoContent()); }