public Task <StorageStream> GetModelStream(string setId, string versionId, string detail, string xpos, string ypos, string zpos, string format) { LoaderResults setData = this.loadedSetData.Get(); if (setData == null) { throw new NotFoundException("setData"); } SetVersion setVersion = setData.FindSetVersion(setId, versionId); SetVersionLevelOfDetail lod; if (!setVersion.DetailLevels.TryGetValue(detail, out lod)) { throw new NotFoundException("detailLevel"); } ModelFormats modelFormat; if (format == null) { modelFormat = ModelFormats.Ebo; } else if (!ModelFormats.TryParse(format, true, out modelFormat)) { throw new NotFoundException("format"); } string modelPath = lod.ModelTemplate.ToString(); modelPath = ExpandCoordinatePlaceholders(modelPath, xpos, ypos, zpos, modelFormat); return(this.GetStorageStreamForPath(modelPath)); }
private static IEnumerable <SetVersion <T> > InternalGetAllItems() { var preRet = new List <SetVersion <T> >(); if (App.Current.Orchestrator?.Person?.Locator == null) { return(preRet); } if (SetVersion <T> .CanBrowse()) { preRet = SetVersion <T> .All().ToList(); if (SetVersion <T> .CanModify()) { preRet.Add(new SetVersion <T> { Code = Constants.CURRENT_LIVE_WORKSET_TAG, Id = Constants.CURRENT_LIVE_WORKSET_TAG, Name = "Workset", IsPublic = true, IsLocked = false, IsCurrent = !preRet.Any(i => i.IsCurrent) }); } } else { preRet = SetVersion <T> .Where(i => i.IsPublic).ToList(); } preRet = preRet.OrderBy(i => i.TimeStamp).Reverse().ToList(); return(preRet); }
public virtual object GetById(string id) { if (!SetVersion <T> .CanBrowse()) { throw new AuthenticationException("User is not authorized to download."); } var sw = new Stopwatch(); try { sw.Start(); var preRet = SetVersion <T> .Get(id); sw.Stop(); Log.Add <T>($"SetVersion : GetById [{id}] OK ({sw.ElapsedMilliseconds} ms)"); return(preRet); } catch (Exception e) { sw.Stop(); Log.Add <T>(e, $"SetVersion: GetById [{id}] ERR ({sw.ElapsedMilliseconds} ms)"); throw; } }
private SetVersion GetLargeDataSet() { SetVersion setVersion = new SetVersion(); setVersion.Name = "Test"; setVersion.Version = "v1"; OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(new BoundingBox(Vector3.Zero, Vector3.Zero), new CubeBounds[] { }, 2); using (Stream metadataStream = new FileStream(".\\data\\validdataset2\\v1\\metadata.json", FileMode.Open, FileAccess.Read)) { ocTree = MetadataLoader.Load(metadataStream, ocTree, "L1", new Vector3(1, 1, 1)); } ocTree.UpdateTree(); Assert.AreEqual(2, ocTree.MinimumSize); Assert.IsNotNull(ocTree); Assert.IsTrue(ocTree.HasChildren); SetVersionLevelOfDetail lod = new SetVersionLevelOfDetail { Name = "L1", Cubes = ocTree, SetSize = ocTree.Region.Max - ocTree.Region.Min, WorldBounds = new BoundingBox(Vector3.Zero, new Vector3(40, 40, 40)) }; setVersion.DetailLevels = new SortedDictionary <string, SetVersionLevelOfDetail>(new[] { lod }.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase)); return(setVersion); }
public virtual object DropSet(string tid) { if (!SetVersion <T> .CanModify()) { throw new AuthenticationException("User is not a Set Version Operator."); } var probe = SetVersion <T> .Get(tid); if (probe == null) { throw new InvalidDataException("Invalid ID."); } var sw = new Stopwatch(); try { sw.Start(); probe.Remove(); sw.Stop(); Log.Add <T>($"SetVersion: DropSet [{tid}] OK ({sw.ElapsedMilliseconds} ms)"); return(probe); } catch (Exception e) { sw.Stop(); Log.Add <T>(e, $"SetVersion: DropSet [{tid}] ERR ({sw.ElapsedMilliseconds} ms): {e.Message}"); throw; } }
public void RubiksCubeDataValidationCentered() { SetVersion rubikSetVersion = this.GenerateRubiksCubeLOD(new[] { 27, 9, 3 }, new Vector3(27, 27, 27)); IEnumerable <QueryDetailContract> results = rubikSetVersion.Query("L2", new Vector3(13, 13, 13)); Assert.AreEqual(3, results.Count()); foreach (QueryDetailContract lod in results) { Trace.WriteLine(lod.Name, "Level of Detail Name"); Assert.IsTrue(lod.Cubes.Count() <= 27); var allCubes = rubikSetVersion.DetailLevels[lod.Name].Cubes.AllItems(); var lookup = allCubes.ToDictionary(c => c.BoundingBox.Min.X + "," + c.BoundingBox.Min.Y + "," + c.BoundingBox.Min.Z); Trace.WriteLine(lookup.Count, "Lookups"); var cubes = lod.Cubes.ToArray(); foreach (var key in cubes) { var keyString = key[0] + "," + key[1] + "," + key[2]; Trace.WriteLine(keyString); CubeBounds hit; Assert.IsTrue(lookup.TryGetValue(keyString, out hit)); Assert.IsInstanceOfType(hit, typeof(ValidCube)); } } }
public SetVersionResultContract GetSetVersion(string setId, string versionId) { SetVersionResultContract result = new SetVersionResultContract(); LoaderResults setData = this.loadedSetData.Get(); if (setData == null) { throw new NotFoundException("setData"); } SetVersion setVersion = setData.FindSetVersion(setId, versionId); result.Set = setVersion.Name; result.Version = setVersion.Version; result.DetailLevels = setVersion.DetailLevels.Values.Select( l => new LevelOfDetailContract { Name = l.Name, SetSize = new Vector3Contract(l.SetSize), ModelBounds = new BoundingBoxContract(l.ModelBounds), WorldBounds = new BoundingBoxContract(l.WorldBounds), TextureSetSize = new Vector2Contract(l.TextureSetSize), WorldCubeScaling = new Vector3Contract(l.WorldToCubeRatio), VertexCount = l.VertexCount }).ToArray(); return(result); }
public virtual object PostItem(SetVersion <T> item) { var sw = new Stopwatch(); if (!SetVersion <T> .CanModify()) { throw new AuthenticationException("User is not a Set Version Operator."); } try { sw.Start(); var preRet = SetVersion <T> .Get(item.Save().Id); sw.Stop(); Log.Add <T>("SetVersion PostItem OK (" + sw.ElapsedMilliseconds + " ms)"); return(preRet); } catch (Exception e) { sw.Stop(); Log.Add <T>(e, "SetVersion PostItem ERR (" + sw.ElapsedMilliseconds + " ms): " + e.Message); throw; } }
public frmEditVersionInfo(CheckVersion chk_ver, SetVersion set_ver, string app_key) { InitializeComponent(); this.application_key = app_key; this.delgCheckVersion = chk_ver; this.delgSetVersion = set_ver; }
private FileContentResult GetZipPackage(string code = null) { if (!SetVersion <T> .CanModify()) { throw new AuthenticationException("User is not a Set Version Operator."); } var sw = new Stopwatch(); try { sw.Start(); var fullName = $"{App.Current.Orchestrator.Application.Code}.{typeof(T).Name}{(code!= null ? $".{code}" : "")}"; var package = SetVersion <T> .GetPackage(code); byte[] bytes; using (var memoryStream = new MemoryStream()) { using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { using (var zipEntry = archive.CreateEntry($"{fullName}.json", CompressionLevel.Optimal).Open()) using (var zipWriter = new StreamWriter(zipEntry)) { zipWriter.Write(package.ToJson()); zipWriter.Flush(); } memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.Position = 0; bytes = memoryStream.ToArray(); // memoryStream.Seek(0, SeekOrigin.End); } } sw.Stop(); Log.Add <T>($"GET: SetVersioning DOWNLOAD {fullName} OK - {sw.ElapsedMilliseconds} ms, {bytes.Length.ToByteSize()}"); var person = App.Current.Orchestrator.Person; new Log <T> { ReferenceId = package.Descriptor.Id, AuthorLocator = person?.Locator, Action = "DOWNLOAD", Type = App.Data.Log.Constants.Type.VERSIONING, Message = $"Version [{package.Descriptor.Code}] ({package.Descriptor.Name}) download{(person!= null ? $" by [{person.Locator}] {person.Name}" : "")}" }.Insert(); return(File(bytes, "application/zip", fullName + ".zip", true)); } catch (Exception e) { sw.Stop(); Log.Add <T>(e, $"GET: SetVersioning DOWNLOAD {code} ERR ({sw.ElapsedMilliseconds} ms): {e.Message}"); throw; } }
public void TestBoundingBox() { SetVersion setVersion = this.Get4x4x4DataSet1(); int[][] results = setVersion.Query("L1", new BoundingBox(new Vector3(10, 10, 10), new Vector3(20, 20, 20))).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("0,0,0", results.Select(i => String.Format("{0},{1},{2}", i[0], i[1], i[2])).First()); }
public virtual IActionResult WebApiDownloadWorkspace(string code) { if (!SetVersion <T> .CanBrowse()) { throw new AuthenticationException("User is not authorized to download."); } return(GetZipPackage(code)); }
private void RenderVersions([NotNull] Item item) { Debug.ArgumentNotNull(item, nameof(item)); Versions.Inlines.Clear(); var context = new ContentEditorContext(ContentEditor); var versions = item.Versions; var count = versions.Count; if (count > 0) { var selectedVersion = item.Uri.Version; if (selectedVersion == Version.Latest) { selectedVersion = new Version(item.Versions[count - 1]); } count = count > 3 ? 3 : count; for (var n = 0; n < count; n++) { var version = new Version(versions[versions.Count - n - 1]); var command = new SetVersion(version); var hyperlink = new HyperlinkBox { Text = version.ToString(), IsSelected = version == selectedVersion, CommandParameter = context, Command = command, ToolTip = Rocks.Resources.QuickInfo_RenderVersions_Version + @" " + version }; Versions.Inlines.Add(hyperlink); } } var more = new Hyperlink(new Run(@"...")) { Style = FindResource(@"HyperlinkValue") as Style }; more.Click += VersionsClick; var border = new Border { Child = new TextBlock(more), Margin = new Thickness(2) }; Versions.Inlines.Add(border); }
public virtual object GetStatus() { if (!SetVersion <T> .CanBrowse()) { throw new AuthenticationException("User is not authorized to download."); } var preret = new { count = Count() }; return(preret); }
public virtual object SetCurrent(string id) { if (!SetVersion <T> .CanBrowse()) { throw new AuthenticationException("User is not authorized."); } var sw = new Stopwatch(); try { sw.Start(); var probe = SetVersion <T> .Get(id); if (probe == null) { throw new InvalidDataException("Invalid ID."); } if (probe.IsCurrent) { return(probe); } var allCurrentSets = SetVersion <T> .Where(i => i.IsCurrent); foreach (var setVersion in allCurrentSets) { if (!setVersion.IsCurrent) { continue; } setVersion.IsCurrent = false; setVersion.Save(); } probe.IsCurrent = true; probe = SetVersion <T> .Get(probe.Save().Id); sw.Stop(); Log.Add <T>($"SetVersion : SetCurrent [{id}] OK ({sw.ElapsedMilliseconds} ms)"); return(probe); } catch (Exception e) { sw.Stop(); Log.Add <T>(e, $"SetVersion: SetCurrent [{id}] ERR ({sw.ElapsedMilliseconds} ms): {e.Message}"); throw; } }
public void LargeDataSetQueryPerformanceCube() { SetVersion setVersion = this.GetLargeDataSet(); SetVersionLevelOfDetail lod0 = setVersion.DetailLevels.Values.FirstOrDefault(); Stopwatch timer = new Stopwatch(); timer.Start(); int[][] results = setVersion.Query("L1", lod0.WorldBounds).ToArray(); Trace.WriteLine(results.Count(), "Elements"); timer.Stop(); Trace.WriteLine(timer.ElapsedMilliseconds, "Query Performance (ms)"); }
public IActionResult UploadToWorkspace(PostPayload upload) { if (!SetVersion <T> .CanModify()) { throw new AuthenticationException("User is not a Set Version Operator."); } var formFile = upload.file; try { var size = formFile.Length; var filePaths = new List <string>(); if (formFile.Length <= 0) { return(null); } // full path to file in temp location var filePath = Path.GetTempFileName(); filePaths.Add(filePath); var str = new StreamReader(formFile.OpenReadStream()).ReadToEnd(); var packageModel = str.FromJson <SetVersion <T> .Payload>(); var objs = packageModel.Items.ToJson().FromJson <List <T> >(); Data <T> .RemoveAll(); Data <T> .Save(objs, null, true); Data <T> .New().AfterSetUpdate(); return(Ok(new { size, filePaths })); } catch (Exception e) { Log.Add(e); throw; } }
private SetVersion GenerateRubiksCubeLOD(IEnumerable <int> scales, Vector3 worldBounds) { SetVersion setVersion = new SetVersion(); setVersion.Name = "RubiksCubeData"; setVersion.Version = "v1"; List <SetVersionLevelOfDetail> lods = new List <SetVersionLevelOfDetail>(); int index = 1; foreach (int scale in scales) { SetVersionLevelOfDetail lod = this.GenerateRubikLevelOfDetail("L" + index++, scale, worldBounds); lods.Add(lod); } setVersion.DetailLevels = new SortedDictionary <string, SetVersionLevelOfDetail>(lods.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase)); return(setVersion); }
private SetVersion Get4x4x4DataSet1() { SetVersion setVersion = new SetVersion(); setVersion.Name = "Test"; setVersion.Version = "v1"; List <CubeBounds> testBounds = new List <CubeBounds>(); testBounds.Add(new CubeBounds { BoundingBox = this.MakeCube(Vector3.Zero, 1) }); testBounds.Add(new CubeBounds { BoundingBox = this.MakeCube(new Vector3(1, 1, 1), 1) }); testBounds.Add(new CubeBounds { BoundingBox = this.MakeCube(new Vector3(2, 2, 2), 1) }); testBounds.Add(new CubeBounds { BoundingBox = this.MakeCube(new Vector3(3, 3, 3), 1) }); OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>(this.zeroBoundingBox, testBounds); ocTree.UpdateTree(); SetVersionLevelOfDetail lod = new SetVersionLevelOfDetail { Name = "L1", Cubes = ocTree, SetSize = ocTree.Region.Max - ocTree.Region.Min, WorldBounds = new BoundingBox(Vector3.Zero, new Vector3(40, 40, 40)) }; setVersion.DetailLevels = new SortedDictionary <string, SetVersionLevelOfDetail>(new[] { lod }.ToDictionary(l => l.Name, l => l, StringComparer.OrdinalIgnoreCase)); return(setVersion); }
public Task <StorageStream> GetTextureStream(string setId, string versionId, string detail, string xpos, string ypos) { LoaderResults setData = this.loadedSetData.Get(); if (setData == null) { throw new NotFoundException("setData"); } SetVersion setVersion = setData.FindSetVersion(setId, versionId); SetVersionLevelOfDetail lod; if (!setVersion.DetailLevels.TryGetValue(detail, out lod)) { throw new NotFoundException("detailLevel"); } string texturePath = lod.TextureTemplate.ToString(); texturePath = texturePath.Replace(X_PLACEHOLDER, xpos); texturePath = texturePath.Replace(Y_PLACEHOLDER, ypos); return(this.GetStorageStreamForPath(texturePath)); }
public virtual object PushFromWorkset(string id) { if (!SetVersion <T> .CanModify()) { throw new AuthenticationException("User is not a Set Version Operator."); } var sw = new Stopwatch(); try { sw.Start(); var probe = SetVersion <T> .PushFromWorkset(id); sw.Stop(); Log.Add <T>($"SetVersion: PushFromWorkset [{id}] OK ({sw.ElapsedMilliseconds} ms)"); return(probe); } catch (Exception e) { sw.Stop(); Log.Add <T>(e, $"SetVersion: PushFromWorkset [{id}] ERR ({sw.ElapsedMilliseconds} ms): {e.Message}"); throw; } }
private static long Count() { var dataSetVersion = (SetVersioningPrimitiveAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(SetVersioningPrimitiveAttribute)); if (App.Current.Orchestrator?.Person?.Locator == null) { return(0); } long preRet; if (dataSetVersion.CanBrowse()) { preRet = SetVersion <T> .Count(); } else { var personLocator = App.Current.Orchestrator?.Person?.Locator; preRet = SetVersion <T> .Where(i => i.OperatorLocator == personLocator).Count(); } return(preRet); }
public async Task <LoaderResults> LoadMetadata() { LoaderResults results = new LoaderResults(); List <LoaderException> exceptions = new List <LoaderException>(); Dictionary <string, Dictionary <string, SetVersion> > sets = new Dictionary <string, Dictionary <string, SetVersion> >(StringComparer.InvariantCultureIgnoreCase); SetContract[] setsMetadata = null; Uri storageRootUri = null; try { storageRootUri = new Uri(this.storageRoot, UriKind.Relative); setsMetadata = await this.Deserialize <SetContract[]>(storageRootUri); if (setsMetadata == null) { throw new SerializationException("Deserialization Failed"); } } catch (Exception ex) { exceptions.Add(new LoaderException("Sets", this.storageRoot, ex)); results.Errors = exceptions.ToArray(); results.Sets = sets; return(results); } List <SetVersion> setVersions = new List <SetVersion>(); foreach (SetContract set in setsMetadata) { try { foreach (SetVersionContract version in set.Versions) { Uri setMetadataUri = new Uri(storageRootUri, version.Url); Trace.WriteLine(String.Format("Set: {0}, Url {1}", set.Name, setMetadataUri)); SetMetadataContract setMetadata = await this.Deserialize <SetMetadataContract>(setMetadataUri); if (setMetadata == null) { throw new SerializationException("Set metadata deserialization Failed"); } Trace.WriteLine(String.Format("Discovered set {0}/{1} at {2}", set.Name, version.Name, version.Url)); Uri material = new Uri(setMetadataUri, setMetadata.Mtl); SetVersion currentSet = new SetVersion { SourceUri = setMetadataUri, Name = set.Name, Version = version.Name, Material = material }; List <SetVersionLevelOfDetail> detailLevels = await this.ExtractDetailLevels(setMetadata, setMetadataUri); currentSet.DetailLevels = new SortedDictionary <string, SetVersionLevelOfDetail>(detailLevels.ToDictionary(d => d.Name, d => d, StringComparer.OrdinalIgnoreCase)); setVersions.Add(currentSet); } } catch (Exception ex) { exceptions.Add(new LoaderException("Set", storageRootUri.ToString(), ex)); } } sets = setVersions.GroupBy(s => s.Name).ToDictionary(s => s.Key, this.GenerateVersionMap, StringComparer.OrdinalIgnoreCase); results.Errors = exceptions.ToArray(); results.Sets = sets; return(results); }
public IEnumerable <int[]> Query(string setId, string versionId, string detail, BoundingBox worldBox) { SetVersion setVersion = this.loadedSetData.Get().FindSetVersion(setId, versionId); return(setVersion.Query(detail, worldBox)); }
public IEnumerable <QueryDetailContract> Query(string setId, string versionId, string profile, BoundingSphere worldSphere) { SetVersion setVersion = this.loadedSetData.Get().FindSetVersion(setId, versionId); return(setVersion.Query(profile, worldSphere)); }
public IEnumerable <QueryDetailContract> Query(string setId, string versionId, string boundaryReferenceLoD, Vector3 worldCenter) { SetVersion setVersion = this.loadedSetData.Get().FindSetVersion(setId, versionId); return(setVersion.Query(boundaryReferenceLoD, worldCenter)); }