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; } }
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 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; } }
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 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; } }
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; } }