예제 #1
0
        private static void RoundtripTest(IDagNode a)
        {
            var ms = new MemoryStream();

            a.Write(ms);
            ms.Position = 0;
            var b = new DagNode(ms);

            Assert.AreEqual(a.DataBytes, b.DataBytes);
            Assert.AreEqual(a.ToArray(), b.ToArray());
            Assert.AreEqual(a.Links.Count(), b.Links.Count());
            foreach (var _ in a.Links.Zip(b.Links, (first, second) =>
            {
                Assert.AreEqual(first.Id, second.Id);
                Assert.AreEqual(first.Name, second.Name);
                Assert.AreEqual(first.Size, second.Size);
                return(first);
            }).ToArray())
            {
                using (var first = a.DataStream)
                {
                    using (var second = b.DataStream)
                    {
                        Assert.AreEqual(first.Length, second.Length);
                        for (var i = 0; i < first.Length; ++i)
                        {
                            Assert.AreEqual(first.ReadByte(), second.ReadByte());
                        }
                    }
                }
            }
        }
예제 #2
0
 public void SetInput(int index, IDagNode node)
 {
     //todo: what does c# do on out of bounds?
     while (_inputArray.Count <= index)
     {
         _inputArray.Add(null);
     }
     _inputArray[index] = node;
 }
예제 #3
0
        /// <summary>
        ///     Creates a new instance of the <see cref="ChunkedStream" /> class with
        ///     the specified <see cref="IBlockApi" /> and <see cref="DagNode" />.
        /// </summary>
        /// <param name="blockService"></param>
        /// <param name="keyChain"></param>
        /// <param name="dag"></param>
        internal ChunkedStream(IBlockApi blockService, IKeyApi keyChain, IDagNode dag)
        {
            BlockService = blockService;
            KeyChain     = keyChain;
            var links = dag.Links.ToArray();
            var dm    = Serializer.Deserialize <DataMessage>(dag.DataStream);

            if (dm.FileSize != null)
            {
                Length = (long)dm.FileSize;
            }

            ulong position = 0;

            for (var i = 0; i < dm.BlockSizes.Length; ++i)
            {
                blocks.Add(new BlockInfo
                {
                    Id       = links[i].Id,
                    Position = (long)position
                });
                position += dm.BlockSizes[i];
            }
        }
예제 #4
0
 public void RemoveUnorderedInput(IDagNode node)
 {
     _dagCalculateComponent.RemoveUnorderedInput(node);
 }
예제 #5
0
 public void AddUnorderedInput(IDagNode node)
 {
     _dagCalculateComponent.AddUnorderedInput(node);
 }
예제 #6
0
 public void SetInput(int index, IDagNode node)
 {
     _dagCalculateComponent.SetInput(index, node);
 }
예제 #7
0
        public async Task <IDagNode> PutAsync(IDagNode node, CancellationToken cancel = default)
        {
            node.Id = await _blockApi.PutAsync(node.ToArray(), cancel : cancel).ConfigureAwait(false);

            return(node);
        }
예제 #8
0
 public static void UnLinkUnordered(IDagNode input, IDagNodeCalculateBase output)
 {
     output.RemoveUnorderedInput(input);
     input.RemoveOutput(output);
     output.SetDirty();
 }
예제 #9
0
 public static void UnLink(int index, IDagNode input, IDagNodeCalculateBase output)
 {
     output.SetInput(index, null);
     input.RemoveOutput(output);
     output.SetDirty();
 }
예제 #10
0
 public static void Link(int index, IDagNode input, IDagNodeCalculateBase output)
 {
     output.SetInput(index, input);
     input.AddOutput(output);
     output.SetDirty();
 }
예제 #11
0
 public void RemoveUnorderedInput(IDagNode node)
 {
     _unorderedInputArray.Remove(node);
 }
예제 #12
0
 public void AddUnorderedInput(IDagNode node)
 {
     _unorderedInputArray.Add(node);
 }