public AddRelationCommand(string requesterUserAuthId, TreeId treeId, PersonId from, PersonId to, RelationType relationType) : base(requesterUserAuthId, treeId) { From = from; To = to; RelationType = relationType; }
public static void TreeId_equality() { var treeId1 = new TreeId(Sha1.Hash("abc")); var treeId2 = new TreeId(Sha1.Hash("abc")); var treeId3 = new TreeId(Sha1.Hash("def")); Assert.True(treeId1 == treeId2); Assert.False(treeId1 != treeId2); Assert.True(treeId1.Equals((object)treeId2)); Assert.Equal(treeId1.Sha1.ToString(), treeId1.ToString()); Assert.Equal(treeId2.Sha1.ToString(), treeId2.ToString()); Assert.Equal(treeId3.Sha1.ToString(), treeId3.ToString()); Assert.Equal(treeId1, treeId2); Assert.Equal(treeId1.GetHashCode(), treeId2.GetHashCode()); Assert.Equal(treeId1.ToString(), treeId2.ToString()); Assert.NotEqual(TreeId.Empty, treeId1); Assert.NotEqual(TreeId.Empty.GetHashCode(), treeId1.GetHashCode()); Assert.NotEqual(TreeId.Empty.ToString(), treeId1.ToString()); Assert.NotEqual(treeId3, treeId1); Assert.NotEqual(treeId3.GetHashCode(), treeId1.GetHashCode()); Assert.NotEqual(treeId3.ToString(), treeId1.ToString()); }
/// <summary> /// Helper method to create a root model for a tree /// </summary> /// <returns></returns> protected virtual TreeNode CreateRootNode(FormCollection queryStrings) { var jsonUrl = Url.GetTreeUrl(GetType(), RootNodeId, queryStrings); var isDialog = queryStrings.GetValue <bool>(TreeQueryStringParameters.DialogMode); var node = new TreeNode(RootNodeId, BackOfficeRequestContext.RegisteredComponents.MenuItems, jsonUrl) { HasChildren = true, EditorUrl = queryStrings.HasKey(TreeQueryStringParameters.OnNodeClick) //has a node click handler? ? queryStrings.Get(TreeQueryStringParameters.OnNodeClick) //return node click handler : isDialog //is in dialog mode without a click handler ? ? "#" //return empty string, otherwise, return an editor URL: : Url.GetCurrentDashboardUrl(), Title = NodeDisplayName }; //add the tree id to the root node.AdditionalData.Add("treeId", TreeId.ToString("N")); //add the tree-root css class node.Style.AddCustom("tree-root"); //node.AdditionalData.Add("id", node.HiveId.ToString()); //node.AdditionalData.Add("title", node.Title); AddQueryStringsToAdditionalData(node, queryStrings); //check if the tree is searchable and add that to the meta data as well if (this is ISearchableTree) { node.AdditionalData.Add("searchable", "true"); } return(node); }
//#region ISearchableTree Members //public virtual TreeSearchJsonResult Search(string searchText) //{ // //TODO: do the searching! // //for now, i'm just going to return dummy data that i know is in demo data just to get the ui working // var result = new TreeSearchJsonResult(new[] // { // new SearchResultItem { Id = new HiveId(1050).ToString(), Rank = 0, Title = "Go further", Description="this is a node" }, // new SearchResultItem { Id = new HiveId(1060).ToString(), Rank = 0, Title = "Functionality", Description="this is a node" } // }); // return result; //} //#endregion /// <summary> /// Customize the root node /// </summary> /// <param name="queryStrings"></param> /// <returns></returns> protected override TreeNode CreateRootNode(FormCollection queryStrings) { if (RootNodeId == ActualRootNodeId) { var n = base.CreateRootNode(queryStrings); AddMenuItemsToRootNode(n, queryStrings); return(n); } else { var hiveProvider = GetHiveProvider(RootNodeId, queryStrings); using (var securityUow = hiveProvider.CreateReadonly <ISecurityStore>()) using (var uow = hiveProvider.CreateReadonly <IContentStore>()) { //Get the items and ensure Browse permissions are applied var childIds = new[] { RootNodeId }; using (DisposableTimer.TraceDuration <ContentTreeController>("FilterWithPermissions", "FilterWithPermissions")) { childIds = childIds.FilterWithPermissions( BackOfficeRequestContext.Application.Security, ((UmbracoBackOfficeIdentity)User.Identity).Id, uow, securityUow, new ViewPermission().Id ).ToArray(); } if (childIds.Length == 1) { var node = uow.Repositories.Get <TypedEntity>(childIds[0]); var treeNode = ConvertEntityToTreeNode(node, RootNodeId, queryStrings, uow); //add the tree id to the root treeNode.AdditionalData.Add("treeId", TreeId.ToString("N")); treeNode.HasChildren = true; // Force true so that recycle bin is displayed //add the tree-root css class treeNode.Style.AddCustom("tree-root"); //node.AdditionalData.Add("id", node.HiveId.ToString()); //node.AdditionalData.Add("title", node.Title); //check if the tree is searchable and add that to the meta data as well if (this is ISearchableTree) { treeNode.AdditionalData.Add("searchable", "true"); } AddMenuItemsToNode(treeNode, queryStrings); return(treeNode); } } } return(null); }
public FsFolder(string fullPath, TreeId treeId, CloudFolderType cloudFolderType, FsFolder parent, ulong?size) { FullPath = fullPath; _treeId = treeId; Type = cloudFolderType; Parent = parent; Size = size; }
public virtual async ValueTask <TreeNodeMap?> ReadTreeAsync(TreeId treeId, CancellationToken cancellationToken) { // Read bytes var buffer = await ReadObjectAsync(treeId.Sha1, cancellationToken).ConfigureAwait(false); if (buffer == null) { return(default);
public virtual async ValueTask <TreeNodeMap?> ReadTreeAsync(TreeId treeId, ChasmRequestContext requestContext = default, CancellationToken cancellationToken = default) { requestContext = ChasmRequestContext.Ensure(requestContext); // Read bytes IChasmBlob blob = await ReadObjectAsync(treeId.Sha1, requestContext, cancellationToken) .ConfigureAwait(false); if (blob == null || blob.Content.IsEmpty) { return(default);
private async Task <Uri> AddExampleFile(TreeId treeId) { var file = new Document(Stream.Null, "image/png", "ASDF.png"); _applicationFixture.FileSaver .UploadFile(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Stream>(), Arg.Any <CancellationToken>()) .Returns(_uriExample); return(await CommandsExecutor.Execute( new AddOrChangeTreePhotoCommand(AuthId, treeId, file))); }
/// <summary>Format this builder's state as a commit object.</summary> /// <remarks>Format this builder's state as a commit object.</remarks> /// <returns> /// this object in the canonical commit format, suitable for storage /// in a repository. /// </returns> /// <exception cref="Sharpen.UnsupportedEncodingException"> /// the encoding specified by /// <see cref="Encoding()">Encoding()</see> /// is not /// supported by this Java runtime. /// </exception> public virtual byte[] Build() { ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStreamWriter w = new OutputStreamWriter(os, Encoding); try { os.Write(htree); os.Write(' '); TreeId.CopyTo(os); os.Write('\n'); foreach (ObjectId p in ParentIds) { os.Write(hparent); os.Write(' '); p.CopyTo(os); os.Write('\n'); } os.Write(hauthor); os.Write(' '); w.Write(Author.ToExternalString()); w.Flush(); os.Write('\n'); os.Write(hcommitter); os.Write(' '); w.Write(Committer.ToExternalString()); w.Flush(); os.Write('\n'); if (Encoding != Constants.CHARSET) { os.Write(hencoding); os.Write(' '); os.Write(Constants.EncodeASCII(Encoding.Name())); os.Write('\n'); } os.Write('\n'); if (Message != null) { w.Write(Message); w.Flush(); } } catch (IOException err) { // This should never occur, the only way to get it above is // for the ByteArrayOutputStream to throw, but it doesn't. // throw new RuntimeException(err); } return(os.ToByteArray()); }
public async Task <TreeDto> GetTree(TreeId treeId, CancellationToken cancellationToken = default) { var trees = await _treesContext.Trees .AsSplitQuery() .Where(t => t.Id == treeId) .SelectMany(t => t.TreeOwners, (t, profile) => new { tree = t, profileId = profile.UserId }) .Join(_treesContext.Users, arg => arg.profileId, profile => profile.Id, (arg, userProfile) => new { arg.tree, userProfile }) .ToListAsync(cancellationToken); var tree = trees.FirstOrDefault()?.tree; return(tree is null ? null : new TreeDto(tree, trees.Select(t => t.userProfile))); }
public UpdatePersonCommand(string requesterUserAuthId, TreeId treeId, PersonId personId, string?name, string?lastName, Gender gender, DateTime?birthDate, DateTime?deathDate, string?description, string?biography, IEnumerable <Relation> relations = null) : base(requesterUserAuthId, treeId) { PersonId = personId; Name = name; LastName = lastName; Gender = gender; BirthDate = birthDate; DeathDate = deathDate; Description = description; Biography = biography; Relations = relations ?? new List <Relation>(); }
private async Task Init() { _treeId = await CreateTree(); _queenId = await CommandsExecutor.Execute( new AddPersonCommand( AuthId, _treeId, "Elżbieta", "II", Gender.Female, new DateTime(1926, 4, 21), null, "Queen", "Some biography")); }
public static void TreeId_Compare() { var comparer = TreeIdComparer.Default; var treeId1 = new TreeId(Sha1.Hash("abc")); var treeId2 = new TreeId(Sha1.Hash("abc")); var treeId3 = new TreeId(Sha1.Hash("def")); var list = new[] { treeId1, treeId2, treeId3 }; Assert.True(treeId1.CompareTo(treeId2) == 0); Assert.True(treeId1.CompareTo(treeId3) != 0); Array.Sort(list, comparer.Compare); Assert.True(list[0] <= list[1]); Assert.True(list[2] >= list[1]); }
public void MergeFrom(CommitWire other) { if (other == null) { return; } parents_.Add(other.parents_); if (other.treeId_ != null) { if (treeId_ == null) { treeId_ = new global::SourceCode.Chasm.IO.Proto.Wire.Sha1Wire(); } TreeId.MergeFrom(other.TreeId); } if (other.author_ != null) { if (author_ == null) { author_ = new global::SourceCode.Chasm.IO.Proto.Wire.AuditWire(); } Author.MergeFrom(other.Author); } if (other.committer_ != null) { if (committer_ == null) { committer_ = new global::SourceCode.Chasm.IO.Proto.Wire.AuditWire(); } Committer.MergeFrom(other.Committer); } if (other.message_ != null) { if (message_ == null) { message_ = new global::Google.Protobuf.WellKnownTypes.StringValue(); } Message.MergeFrom(other.Message); } }
public override int GetHashCode() { int hash = 1; hash ^= parents_.GetHashCode(); if (treeId_ != null) { hash ^= TreeId.GetHashCode(); } if (author_ != null) { hash ^= Author.GetHashCode(); } if (committer_ != null) { hash ^= Committer.GetHashCode(); } if (Message.Length != 0) { hash ^= Message.GetHashCode(); } return(hash); }
public void MergeFrom(CommitWire other) { if (other == null) { return; } parents_.Add(other.parents_); if (other.treeId_ != null) { if (treeId_ == null) { treeId_ = new global::SourceCode.Chasm.IO.Proto.Wire.Sha1Wire(); } TreeId.MergeFrom(other.TreeId); } if (other.author_ != null) { if (author_ == null) { author_ = new global::SourceCode.Chasm.IO.Proto.Wire.AuditWire(); } Author.MergeFrom(other.Author); } if (other.committer_ != null) { if (committer_ == null) { committer_ = new global::SourceCode.Chasm.IO.Proto.Wire.AuditWire(); } Committer.MergeFrom(other.Committer); } if (other.Message.Length != 0) { Message = other.Message; } }
public TreeOwnerAddedEvent(TreeId tree, UserProfile invited, UserProfile invitor) { Tree = tree; Invited = invited; Invitor = invitor; }
/// <summary> /// Return a serialized string of values for the pre value editor model /// </summary> /// <returns></returns> public override string GetSerializedValue() { var xml = new XElement("preValues", new XElement("preValue", new XAttribute("name", "TreeId"), new XCData(TreeId.ToString("N"))), new XElement("preValue", new XAttribute("name", "IsRequired"), new XCData(IsRequired.ToString()))); return(xml.ToString()); }
public AddPersonsFileCommand(string requesterUserAuthId, TreeId treeId, Document document, PersonId personId) : base(requesterUserAuthId, treeId) { Document = document; PersonId = personId; }
public RemoveMyselfFromTreeOwnersCommand(string requesterUserAuthId, TreeId treeId) : base(requesterUserAuthId, treeId) { }
protected TreeQueryBase(string requesterUserAuthId, TreeId treeId) { RequesterUserAuthId = requesterUserAuthId; TreeId = treeId; }
private static async Task TestRepository(IChasmRepository repository) { var g = Guid.NewGuid(); var cx = new ChasmRequestContext { CorrelationId = Guid.NewGuid().ToString("D") }; byte[] buffer = g.ToByteArray(); Sha1 sha = s_hasher.HashData(buffer); // Unknown SHA Sha1 usha1 = s_hasher.HashData(Guid.NewGuid().ToByteArray()); Sha1 usha2 = s_hasher.HashData(Guid.NewGuid().ToByteArray()); // Blob var metadata = new ChasmMetadata("application/json", "file123.txt"); Sha1 sha2 = await repository.WriteObjectAsync(new ReadOnlyMemory <byte>(buffer), metadata, false, cx, default); Assert.Equal(sha, sha2); IChasmBlob rdata = await repository.ReadObjectAsync(sha, default); Assert.True(rdata != null); Assert.Equal(16, rdata.Content.Length); Assert.Equal(g, new Guid(rdata.Content.ToArray())); Assert.Equal("application/json", rdata.Metadata.ContentType); Assert.Equal("file123.txt", rdata.Metadata.Filename); IChasmBlob urdata = await repository.ReadObjectAsync(usha1, default); Assert.False(urdata != null); // metadata = new ChasmMetadata("application/text", null); sha2 = await repository.WriteObjectAsync(buffer, metadata, true, cx, default); Assert.Equal(sha, sha2); IChasmBlob cnt2 = await repository.ReadObjectAsync(sha2, default); Assert.Equal(buffer, cnt2.Content.ToArray()); Assert.Equal("application/text", cnt2.Metadata.ContentType); Assert.Null(cnt2.Metadata.Filename); using (IChasmStream stream2 = await repository.ReadStreamAsync(sha2, cx, default)) using (var ms = new MemoryStream()) { stream2.Content.CopyTo(ms); Assert.Equal(buffer, ms.ToArray()); } using (Stream stream2 = new MemoryStream(buffer)) { sha2 = await repository.WriteObjectAsync(stream2, null, true, cx, default); } Assert.Equal(sha, sha2); using (IChasmStream stream2 = await repository.ReadStreamAsync(sha2, cx, default)) using (var ms = new MemoryStream()) { stream2.Content.CopyTo(ms); Assert.Equal(buffer, ms.ToArray()); } // Tree var tree = new TreeNodeMap( new TreeNode("firstItem", NodeKind.Blob, sha), new TreeNode("secondItem", NodeKind.Blob, sha) ); TreeId treeId = await repository.WriteTreeAsync(tree, cx, default); TreeNodeMap?rtree = await repository.ReadTreeAsync(treeId, cx, default); Assert.True(rtree.HasValue); Assert.Equal(tree, rtree.Value); TreeNodeMap?urtree = await repository.ReadTreeAsync(new TreeId(usha1), cx, default); Assert.False(urtree.HasValue); }
public UpdateTreeNameCommand(string requesterUserAuthId, TreeId treeId, string treeName) : base( requesterUserAuthId, treeId) { TreeName = treeName; }
public RemoveTreeOwnerCommand(string requesterUserAuthId, TreeId treeId, UserId userToRemoveId) : base(requesterUserAuthId, treeId) { UserToRemoveId = userToRemoveId; }
public AddOrChangeTreePhotoCommand(string requesterUserAuthId, TreeId treeId, Document document) : base(requesterUserAuthId, treeId) { Document = document; }
public RemovePersonCommand(string requesterUserAuthId, TreeId treeId, PersonId personId) : base(requesterUserAuthId, treeId) { PersonId = personId; }
protected TreeOperationCommandBase(string requesterUserAuthId, TreeId treeId) : base(requesterUserAuthId, treeId) { }
public async Task <Tree?> GetByIdAsync(TreeId id, CancellationToken cancellationToken = default) { return(await _treesContext.Trees .FirstOrDefaultAsync(t => t.Id == id, cancellationToken)); }
public RemoveRelationCommand(string requesterUserAuthId, TreeId treeId, PersonId first, PersonId second) : base( requesterUserAuthId, treeId) { First = first; Second = second; }
public GetTreeFileExportQuery(string requesterUserAuthId, TreeId treeId) : base(requesterUserAuthId, treeId) { }