Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nChain">The peptide that will be constitute the N-terminal region of the resultant spliced peptide</param>
        /// <param name="cChain">The peptide that will be constitute the C-terminal region of the resultant spliced peptide</param>
        /// <param name="nInclude">The included portion of the N-terminal peptide</param>
        /// <param name="cInclude">The included portion of hte C-terminal peptide</param>
        /// <param name="nAlignNullable">The region to align on prior to splicing</param>
        /// <param name="cAlignNullable">The region to align on prior to splicing</param>
        /// <returns></returns>
        public static IChain GetPeptide(IChain nChain, IChain cChain, Range nInclude, Range cInclude, Range?nAlignNullable = null, Range?cAlignNullable = null)
        {
            bool  performAlignment = nAlignNullable != null && cAlignNullable != null;
            Range nAlign           = performAlignment ? new Range((Range)nAlignNullable) : new Range();
            Range cAlign           = performAlignment ? new Range((Range)cAlignNullable) : new Range();

            if (performAlignment && ((Range)nAlignNullable).Length != ((Range)cAlignNullable).Length)
            {
                throw new ArgumentException("Splice ranges must be of equal length");
            }
            if (nInclude.Start < 0 || nChain.Count <= nInclude.End || cInclude.Start < 0 || cChain.Count <= cInclude.End)
            {
                throw new IndexOutOfRangeException("Splice ranges exceed the peptide ranges");
            }

            IChain chain = new Chain();
            //float rmsd = Rmsd.GetRmsd(cTerminus[cAlign.Start, cAlign.End], nTerminus[nAlign.Start, nAlign.End]);
            Matrix cTerminusTransform = performAlignment ? Rmsd.GetRmsdTransform(cChain[cAlign.Start, cAlign.End], nChain[nAlign.Start, nAlign.End]) : Matrix.Identity;

            cTerminusTransform.Rotation.Normalize();
            //Quaternion rotation = cTerminusTransform.Rotation;
            //rotation.Normalize();
            //cTerminusTransform.Rotation = rotation;
            for (int i = nInclude.Start; i <= nInclude.End; i++)
            {
                chain.Add(new Aa(nChain[i]));
            }
            for (int i = cInclude.Start; i <= cInclude.End; i++)
            {
                IAa residue = new Aa(cChain[i]);
                residue.Transform(cTerminusTransform);
                chain.Add(residue);
            }
            return(chain);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            byte effort = 0;
            var  chain  = new Chain(effort);
            var  block1 = chain.Add(new Coin(300F));
            var  block2 = chain.Add(new Coin(400F));
            var  block3 = chain.Add(new Coin(500F));

            var separator = (new string('-', 10)) + "\n";

            Console.WriteLine("Genesis Block");
            Console.WriteLine(chain.GenesisBlock.Dump());
            Console.WriteLine(separator);

            foreach (var block in chain.Blocks)
            {
                Console.WriteLine(block.Dump());
                Console.WriteLine("---");
            }

            Console.WriteLine($"Check Integrity: {chain.CheckIntegrity()}");
            Console.WriteLine(separator);

            Console.WriteLine("Simulates a change in the immutable structure of Block");
            Console.WriteLine("Set block1.Data to new Coin(666F)");
            SetPrivatePropertyValue(block1, "Data", new Coin(666F));
            Console.WriteLine(separator);

            Console.WriteLine($"Check Integrity: {chain.CheckIntegrity()}");
            Console.WriteLine(separator);

            Console.Read();
        }
Exemplo n.º 3
0
    void Decomposite(int from, int cur, int lv)
    {
        var chain = new Chain(from, lv);

        chains.Add(chain);
        chain.Add(cur);
        while (cur != from)
        {
            var next = cur;
            go[cur]  = chain;
            pos[cur] = chain.Count;
            foreach (var to in G[cur])
            {
                if (to == from)
                {
                    continue;
                }
                if (maxsize[cur] == subtreeSize[to])
                {
                    maxsize[cur] = -1;
                    next         = to;
                    chain.Add(to);
                }
                else
                {
                    Decomposite(cur, to, lv + 1);
                }
            }

            from = cur;
            cur  = next;
        }
        chain.Init();
    }
Exemplo n.º 4
0
        public void CheckTest()
        {
            var chain = new Chain();

            chain.Add("hello, world", "Admin");
            chain.Add("code blog", "developer");
            Assert.IsTrue(chain.Check());
        }
Exemplo n.º 5
0
        public void CheckTest()
        {
            var chain = new Chain();

            chain.Add("Hello, world!", "Admin");
            chain.Add("Code blog", "Shwanov");

            Assert.IsTrue(chain.Check());
        }
Exemplo n.º 6
0
        public void CheckTest()
        {
            var chain = new Chain();

            chain.Add("Approach", "Leski");
            chain.Add("Appear", "Leski");

            Assert.IsTrue(chain.Check());
        }
Exemplo n.º 7
0
        public void CheckTest()
        {
            var chain = new Chain();

            chain.Add("hello world", "admin");
            chain.Add("code blog", "kirill");

            Assert.IsTrue(chain.Check());
        }
Exemplo n.º 8
0
        public void CheckTest()
        {
            var chain = new Chain();

            chain.Add("bla", "Michael");
            chain.Add("bla bla", "Alex");
            chain.Add("bla bla bla", "Tom");

            Assert.IsTrue(chain.Check());
        }
Exemplo n.º 9
0
        public void ChainAddTest()
        {
            Chain chain = new Chain(new Election("Выборы на пост главного дворника", DateTime.Parse("10.10.2019 20:00:00"), DateTime.Parse("10.12.2019 20:00:00")));

            Assert.IsFalse(chain.Add(null, new Candidate()));

            Assert.IsFalse(chain.Add(new User(), null));

            //Assert.IsTrue(chain.Add(new User(), new Candidate()));
        }
Exemplo n.º 10
0
        public void ProcessPendingTransactions(string minerAddress)
        {
            PendingTransactions.Insert(0, Transaction.GetCoinBaseTransaction(minerAddress, (_reward * PendingTransactions.Count) / (32 - _difficulty)));
            var createdBlock = CreateBlock();

            Chain.Add(createdBlock);
        }
        public void AddGenesisBlock(string type)
        {
            switch (type)
            {
            case "credentrails":
                BlockchainCredentials bcCredentials = new BlockchainCredentials();
                Chain.Add(new Block(DateTime.Now, null, bcCredentials));
                break;

            case "data":
                BlockchainData bcData = new BlockchainData();
                Chain.Add(new Block(DateTime.Now, null, bcData));
                break;

            case "reports":
                BlockchainReports bcReports = new BlockchainReports();
                Chain.Add(new Block(DateTime.Now, null, bcReports));
                break;

            case "ratings":
                BlockchainRatings bcRatings = new BlockchainRatings();
                Chain.Add(new Block(DateTime.Now, null, bcRatings));
                break;
            }
        }
Exemplo n.º 12
0
        public void BlockVerify(Block block)
        {
            lock (Chain)
            {
                Chain.Add(block);
            }

            lock (TransactionPool)
            {
                var ids = block.Transactions.Select(x => x.Id).ToArray();
                TransactionPool.RemoveTxs(ids);
            }

            lock (Utxos)
            {
                var inEntries = block.Transactions.SelectMany(x => x.Inputs);
                Utxos.RemoveAll(x =>
                                inEntries.Any(inEntry =>
                                              inEntry.OutputIndex == x.OutIndex &&
                                              inEntry.TransactionId.Equals(x.TransactionId)));
                var utxos =
                    block.Transactions
                    .Select(x => (x.Outputs, x.Id))
                    .SelectMany(x => ToTxO(x.Outputs, x.Id));

                Utxos.AddRange(utxos);
            }

            //if(Chain.Count % 100 == 0) Difficulty.CalculateNextDifficulty()

            Applied?.Invoke();
        }
Exemplo n.º 13
0
        public void ChainTest()
        {
            var chain = new Chain();

            chain.Add("Code blog", "Admin");
            Assert.AreEqual("Code blog", chain.Last.Data);
        }
Exemplo n.º 14
0
        public void CreateInitialBlock()
        {
            var block = new Block(DateTime.Now, null, null);

            block.Mine(Difficulty);
            Chain.Add(block);
        }
Exemplo n.º 15
0
        public void ChainingTest()
        {
            Person person0 = new Person("", "", DateTime.Now);
            Wallet wallet0 = new Wallet();

            Data.Data data0 = new Data.Data(person0, wallet0);

            //First Data
            Person person1 = new Person("Monroe Jamal", "Budapest",
                                        new DateTime(1979, 1, 21));
            Wallet wallet1 = new Wallet();

            Data.Data data1 = new Data.Data(person1, wallet1);

            //Second Data
            Person person2 = new Person("Wood Dario", "Debrecen",
                                        new DateTime(1997, 4, 2));
            Wallet wallet2 = new Wallet();

            Data.Data data2 = new Data.Data(person2, wallet2);

            //Third Data
            Person person3 = new Person("Weiss Ella", "Debrecen",
                                        new DateTime(1993, 10, 10));
            Wallet wallet3 = new Wallet();

            Data.Data data3 = new Data.Data(person3, wallet3);

            //Fourth Data
            Person person4 = new Person("Patricia T. Smith", "Pécs",
                                        new DateTime(1999, 2, 7));
            Wallet wallet4 = new Wallet();

            Data.Data data4 = new Data.Data(person4, wallet4);

            Block genesis = new Block(data0);

            Chain.Add(genesis);

            Block block1 = new Block(data1);

            Chain.Add(block1);

            Block block2 = new Block(data2);

            Chain.Add(block2);

            Block block3 = new Block(data3);

            Chain.Add(block3);

            Block block4 = new Block(data4);

            Chain.Add(block4);

            List <Block> chain = IO.IO.Read <Block>();

            Assert.AreEqual(block2.Hash, chain[2].Hash);
        }
Exemplo n.º 16
0
        // add genesis block on chain
        public void AddGenesisBlock()
        {
            Block block = new Block(DateTimeOffset.Now, null, PendingTransactions);

            block.Mine(Difficulty);
            PendingTransactions = new List <Transaction>();
            Chain.Add(block);
        }
Exemplo n.º 17
0
        public void ChainTest()
        {
            var chain = new Chain();

            chain.Add("Impossible", "Leski");

            Assert.AreEqual("Impossible", chain.Last.Data);
        }
Exemplo n.º 18
0
        public void AddGenesisBlock()
        {
            Block genesisBlock = new Block(null, null);

            genesisBlock.BlockHash = genesisBlock.CalculateBlockHash();

            Chain.Add(genesisBlock);
        }
Exemplo n.º 19
0
        public void ChainTest()
        {
            var chain = new Chain();

            chain.Add("bla bla bla", "Vlad");

            Assert.AreEqual(chain.Last.Data, "bla bla bla");
            Assert.AreEqual(chain.Last.User, "Vlad");
        }
Exemplo n.º 20
0
        public BlockChain(DateTime?genesisDate = null, int difficulty = 2, int reward = 1_000_000)
        {
            Block genesisBlock = new Block(genesisDate ?? DateTime.UtcNow, null, null);

            genesisBlock.Mine(difficulty);
            Difficulty = difficulty;
            Reward     = reward;
            Chain.Add(genesisBlock);
        }
Exemplo n.º 21
0
        public void AddBlock(Block block)
        {
            Block latestBlock = GetLatestBlock();

            block.index        = latestBlock.index + 1;
            block.previousHash = latestBlock.hash;
            block.Mine(this.difficulty);
            Chain.Add(block);
        }
Exemplo n.º 22
0
        public void AddBlock(DateTime date, IList <Transaction> transactions)
        {
            Block lastBlock = Chain.Last();
            Block newBlock  = new Block(date, lastBlock, transactions);

            newBlock.Mine(Difficulty);
            AddUsersOfBlock(newBlock);
            Chain.Add(newBlock);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Adds asequence operation.
 /// </summary>
 /// <param name="dps">digital pin state to be set</param>
 /// <param name="starttime">Time after the last operation or start</param>
 public void AddSequenceOperation(DPinState dps, TimeSpan duration)
 {
     Chain.Add(new SequenceOperation()
     {
         State    = dps,
         Duration = duration,
         Moment   = new TimeSpan(Chain.Sum(o => o.Duration.Ticks))
     });
 }
Exemplo n.º 24
0
        public void ChainTest()
        {
            var chain = new Chain();

            chain.Add("Code", "Admin");

            Assert.AreEqual(2, chain.Blocks.Count);
            Assert.AreEqual("Code", chain.Last.Data);
        }
Exemplo n.º 25
0
        public void AddBlock(Block block)
        {
            Block latestBlock = GetLatestBlock();

            block.Index        = latestBlock.Index + 1;
            block.PreviousHash = latestBlock.Hash;
            block.Mine(Difficulty);
            Chain.Add(block);
        }
Exemplo n.º 26
0
        public void AddBlock(Block block)
        {
            Block latestBlock = GetLatestBlock();

            block.Index        = latestBlock.Index + 1;
            block.PreviousHash = latestBlock.Hash;
            block.Hash         = block.CalculateHash();
            Chain.Add(block);
        }
Exemplo n.º 27
0
        public void Group(int left, int right)
        {
            Chain init = new Chain();

            for (int i = left; i <= right; i++)
            {
                init.Add(_chain.Devices[i].Clone());
            }

            List <int> path = Track.GetPath(_chain);

            Program.Project.Undo.Add($"Device Grouped", () => {
                Chain chain = Track.TraversePath <Chain>(path);

                chain.Remove(left);

                for (int i = left; i <= right; i++)
                {
                    chain.Insert(i, init[i - left].Clone());
                }

                Track track = Track.Get(chain);
                track?.Window?.Selection.Select(chain[left]);
                track?.Window?.Selection.Select(chain[right], true);
            }, () => {
                Chain chain = Track.TraversePath <Chain>(path);

                for (int i = right; i >= left; i--)
                {
                    chain.Remove(i);
                }

                chain.Insert(left, new Group(new List <Chain>()
                {
                    init.Clone()
                })
                {
                    Expanded = 0
                });
            }, () => {
                init.Dispose();
            });

            for (int i = right; i >= left; i--)
            {
                _chain.Remove(i);
            }

            _chain.Insert(left, new Group(new List <Chain>()
            {
                init.Clone()
            })
            {
                Expanded = 0
            });
        }
Exemplo n.º 28
0
        public void AddBlock(Block block)
        {
            Block latestBlock = GetLatestBlock();

            block.Index        = latestBlock.Index + 1;
            block.PreviousHash = latestBlock.Hash;
            //block.Hash = block.CalculateHash();
            block.Mine(this.Difficulty);
            Chain.Add(block);
        }
        /// <summary>
        /// Used to add the new block to chain
        /// </summary>
        /// <param name="block"></param>
        public void AddBlock(Block block)
        {
            Block latestBlock = GetLatestBlock();

            block.Index        = latestBlock.Index + 1;
            block.PreviousHash = latestBlock.Hash;
            block.Mine(this.Difficulty); // Generate the hash (work of proof)

            Chain.Add(block);
        }
Exemplo n.º 30
0
        public void AddBlock(Block block)
        {
            //Difficulty = GlobalVariables.Difficulty;
            Block latestBlock = GetLatestBlock();

            block.Index        = latestBlock.Index + 1;
            block.PreviousHash = latestBlock.Hash;
            block.Mine(GlobalVariables.Difficulty);
            Chain.Add(block);
        }
Exemplo n.º 31
0
 protected AbstractRule()
 {
     myChain = new Chain<char>();
     myChain.Add(new Handler<char>(Constants.ASCII_LF, HandleNewline, true));
     myChain.Add(new Handler<char>(StopIfBozo));
 }
Exemplo n.º 32
0
        private List<Chain> GetMatches()
        {
            var matches = new List<Chain>();

            for (var y = 0; y < Height; y++)
            {
                for (var x = 0; x < Width - 2;)
                {
                    var animal = GetAnimalAt(x, y);

                    if (animal == null || !SpeciesMatch(x + 1, y, animal.Species) || !SpeciesMatch(x + 2, y, animal.Species))
                    {
                        x++;
                        continue;
                    }

                    var chain = new Chain(ChainType.Horizontal);
                    do chain.Add(GetAnimalAt(x++, y));
                    while (x < Width && SpeciesMatch(x, y, animal.Species));
                    matches.Add(chain);
                }
            }

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height - 2;)
                {
                    var animal = GetAnimalAt(x, y);

                    if (animal == null || !SpeciesMatch(x, y + 1, animal.Species) || !SpeciesMatch(x, y + 2, animal.Species))
                    {
                        y++;
                        continue;
                    }

                    var chain = new Chain(ChainType.Vertical);
                    do chain.Add(GetAnimalAt(x, y++));
                    while (y < Height && SpeciesMatch(x, y, animal.Species));
                    matches.Add(chain);
                }
            }

            return matches;
        }
Exemplo n.º 33
0
        public Context()
        {
            rules = new List<IRule>();

            rules.Add(new HeightRule());
            rules.Add(new WidthRule());
            rules.Add(new OneStatementPerLineRule());
            rules.Add(new OneLinePerStatementRule());
            rules.Add(new MethodHeightRule());
            rules.Add(new VariableLenghtRule());

            setupChain = new Chain<char>();
            setupChain.Add(new Handler<char>('\'', HandleCharDefinition, true));
            setupChain.Add(new Handler<char>('"', HandleStringDefinition, true));
            setupChain.Add(new Handler<char>('#', HandleDirectiveDefinition, true));
            setupChain.Add(new Handler<char>('/', HandleSlash, true));
            setupChain.Add(new Handler<char>('*', HandleStar, true));

            teardownChain = new Chain<char>();
            teardownChain.Add(new Handler<char>(Constants.ASCII_LF, HandleNewLine, true));
        }