Exemple #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            double max, min;
            double d;

            if (Max.Equals(""))
            {
                max = double.MaxValue;
            }
            else if (!(double.TryParse(Max, out d)))
            {
                return;
            }
            else
            {
                max = d;
            }

            if (Min.Equals(""))
            {
                min = double.MinValue;
            }
            else if (!(double.TryParse(Min, out d)))
            {
                return;
            }
            else
            {
                min = d;
            }

            List <Res> l = new List <Res>( );

            listRes.Clear( );
            for (int i = 0; i < MainWindow.Resources.Len( ); i++)
            {
                WpfApp3.Res r = MainWindow.Resources.GetResourceAtI(i);

                String ek = r.eksploatisanje ? "DA" : "NE";
                String o  = r.obnovljiv ? "DA" : "NE";
                String s  = r.strateskiVazan ? "DA" : "NE";

                Regex match = new Regex(Ime, RegexOptions.IgnoreCase);
                Match mIme  = match.Match(r.ime);

                match = new Regex(Oznaka, RegexOptions.IgnoreCase);
                Match mOznaka = match.Match(r.oznaka);

                String etiketeStr = "";
                for (int j = 0; j < r.etikete.Count; j++)
                {
                    etiketeStr += r.etikete[j].oznaka + " ";
                }
                Double cena = double.Parse(r.cena);
                if (((mIme.Success && mIme.Value.Length == r.ime.Length) || Ime.Equals("")) &&
                    ((mOznaka.Success && mOznaka.Value.Length == r.oznaka.Length) || Oznaka.Equals("")) &&
                    (Tip.Equals("") || Tip.Equals(r.tip)) &&
                    cena <= max && cena >= min)
                {
                    l.Add(new Res( )
                    {
                        Ime = r.ime, Opis = r.opis, Oznaka = r.oznaka, Tip = r.tip, Slika = r.tipImg, Frekvencija = r.frekvencija, Ikonica = r.oznaka, Obnovljiv = o, Eksploatisanje = ek, StrateskiVazan = s, Mera = r.mera, Cena = r.cena, Datum = r.datum, Etikete = etiketeStr
                    });
                    listRes.Add(new Res( )
                    {
                        Ime = r.ime, Opis = r.opis, Oznaka = r.oznaka, Tip = r.tip, Slika = r.tipImg, Frekvencija = r.frekvencija, Ikonica = r.oznaka, Obnovljiv = o, Eksploatisanje = ek, StrateskiVazan = s, Mera = r.mera, Cena = r.cena, Datum = r.datum, Etikete = etiketeStr
                    });
                }
            }

            /*this.Close( );
             * var tablefil = new Table(l);
             * tablefil.ShowDialog( );*/
        }
        internal System.Action Swap(
            BlockChain <T> other,
            bool render,
            StateCompleterSet <T>?stateCompleters = null)
        {
            if (other is null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            // As render/unrender processing requires every step's states from the branchpoint
            // to the new/stale tip, incomplete states need to be complemented anyway...
            StateCompleterSet <T> completers = stateCompleters ?? StateCompleterSet <T> .Recalculate;

            if (Tip.Equals(other.Tip))
            {
                // If it's swapped for a chain with the same tip, it means there is no state change.
                // Hence render is unnecessary.
                render = false;
            }
            else
            {
                _logger.Debug(
                    "The blockchain was reorged from " +
                    "{OldChainId} (#{OldTipIndex} {OldTipHash}) " +
                    "to {NewChainId} (#{NewTipIndex} {NewTipHash}).",
                    Id,
                    Tip.Index,
                    Tip.Hash,
                    other.Id,
                    other.Tip.Index,
                    other.Tip.Hash);
            }

            System.Action renderSwap = () => { };

            _rwlock.EnterUpgradeableReadLock();
            try
            {
                // Finds the branch point.
                Block <T> branchpoint = FindTopCommon(this, other);

                if (branchpoint is null)
                {
                    const string msg =
                        "A chain cannot be reorged into a heterogeneous chain with a " +
                        "different genesis.";
                    throw new InvalidGenesisBlockException(Genesis.Hash, other.Genesis.Hash, msg);
                }

                _logger.Debug(
                    "The branchpoint is #{BranchpointIndex} {BranchpointHash}.",
                    branchpoint.Index,
                    branchpoint
                    );

                Block <T> oldTip = Tip, newTip = other.Tip;

                ImmutableList <Block <T> > rewindPath      =
                    GetRewindPath(this, branchpoint.Hash);
                ImmutableList <Block <T> > fastForwardPath =
                    GetFastForwardPath(other, branchpoint.Hash);

                // If there is no rewind, it is not considered as a reorg.
                bool reorg = rewindPath.Count > 0;

                _rwlock.EnterWriteLock();
                try
                {
                    IEnumerable <long> LongRange(long start, long count)
                    {
                        for (long i = 0; i < count; i++)
                        {
                            yield return(start + i);
                        }
                    }

                    ImmutableHashSet <Transaction <T> >
                    GetTxsWithRange(BlockChain <T> chain, Block <T> start, Block <T> end) =>
                    LongRange(start.Index + 1, end.Index - start.Index)
                    .SelectMany(index => chain[index].Transactions)
                    .ToImmutableHashSet();

                    // It assumes reorg is small size. If it was big, this may be heavy task.
                    ImmutableHashSet <Transaction <T> > txsToStage =
                        GetTxsWithRange(this, branchpoint, Tip);
                    ImmutableHashSet <Transaction <T> > txsToUnstage =
                        GetTxsWithRange(other, branchpoint, other.Tip);
                    foreach (Transaction <T> tx in txsToStage)
                    {
                        StagePolicy.Stage(this, tx);
                    }

                    Guid obsoleteId = Id;
                    Id = other.Id;
                    Store.SetCanonicalChainId(Id);
                    _blocks = new BlockSet <T>(Policy.GetHashAlgorithm, Store);
                    foreach (Transaction <T> tx in txsToUnstage)
                    {
                        StagePolicy.Unstage(this, tx.Id);
                    }

                    TipChanged?.Invoke(this, (oldTip, newTip));

                    Store.DeleteChainId(obsoleteId);
                }
                finally
                {
                    _rwlock.ExitWriteLock();
                }

                renderSwap = () => RenderSwap(
                    render: render,
                    oldTip: oldTip,
                    newTip: newTip,
                    branchpoint: branchpoint,
                    rewindPath: rewindPath,
                    fastForwardPath: fastForwardPath,
                    stateCompleters: completers);
            }
            finally
            {
                _rwlock.ExitUpgradeableReadLock();
            }

            return(renderSwap);
        }
Exemple #3
0
        private void filter()
        {
            if (chack_filter.IsChecked.Equals(true))
            {
                double max, min;
                double d;
                if (Max.Equals(""))
                {
                    max = double.MaxValue;
                }
                else if (!(double.TryParse(Max, out d)))
                {
                    return;
                }
                else
                {
                    max = d;
                }

                if (Min.Equals(""))
                {
                    min = double.MinValue;
                }
                else if (!(double.TryParse(Min, out d)))
                {
                    return;
                }
                else
                {
                    min = d;
                }

                List <Res> l = new List <Res>( );
                listRes.Clear( );
                for (int i = 0; i < MainWindow.Resources.Len( ); i++)
                {
                    WpfApp3.Res r = MainWindow.Resources.GetResourceAtI(i);

                    String ek = r.eksploatisanje ? "DA" : "NE";
                    String o  = r.obnovljiv ? "DA" : "NE";
                    String s  = r.strateskiVazan ? "DA" : "NE";

                    Regex match = new Regex(Ime, RegexOptions.IgnoreCase);
                    Match mIme  = match.Match(r.ime);

                    match = new Regex(Oznaka, RegexOptions.IgnoreCase);
                    Match mOznaka = match.Match(r.oznaka);

                    String etiketeStr = "";
                    for (int j = 0; j < r.etikete.Count; j++)
                    {
                        etiketeStr += r.etikete[j].oznaka + " ";
                    }
                    Double cena = double.Parse(r.cena);
                    if ((r.ime.StartsWith(Ime) || Ime.Equals("")) &&
                        (r.oznaka.StartsWith(Oznaka) || Oznaka.Equals("")) &&
                        (Tip.Equals("") || Tip.Equals(r.tip)) &&
                        cena <= max && cena >= min)
                    {
                        l.Add(new Res( )
                        {
                            Ime = r.ime, Opis = r.opis, Oznaka = r.oznaka, Tip = r.tip, Slika = r.tipImg, Frekvencija = r.frekvencija, Ikonica = r.oznaka, Obnovljiv = o, Eksploatisanje = ek, StrateskiVazan = s, Mera = r.mera, Cena = r.cena, Datum = r.datum, Etikete = etiketeStr
                        });
                        listRes.Add(new Res( )
                        {
                            Ime = r.ime, Opis = r.opis, Oznaka = r.oznaka, Tip = r.tip, Slika = r.tipImg, Frekvencija = r.frekvencija, Ikonica = r.oznaka, Obnovljiv = o, Eksploatisanje = ek, StrateskiVazan = s, Mera = r.mera, Cena = r.cena, Datum = r.datum, Etikete = etiketeStr
                        });
                    }
                }
            }
        }
Exemple #4
0
        // FIXME it's very dangerous because replacing Id means
        // ALL blocks (referenced by MineBlock(), etc.) will be changed.
        internal System.Action Swap(
            BlockChain <T> other,
            bool render,
            StateCompleterSet <T>?stateCompleters = null)
        {
            if (other is null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            // As render/unrender processing requires every step's states from the branchpoint
            // to the new/stale tip, incomplete states need to be complemented anyway...
            StateCompleterSet <T> completers = stateCompleters ?? StateCompleterSet <T> .Recalculate;

            if (Tip.Equals(other.Tip))
            {
                // If it's swapped for a chain with the same tip, it means there is no state change.
                // Hence render is unnecessary.
                render = false;
            }
            else
            {
                _logger.Debug(
                    "The blockchain was reorged from " +
                    "{OldChainId} (#{OldTipIndex} {OldTipHash}) " +
                    "to {NewChainId} (#{NewTipIndex} {NewTipHash}).",
                    Id,
                    Tip.Index,
                    Tip.Hash,
                    other.Id,
                    other.Tip.Index,
                    other.Tip.Hash);
            }

            System.Action renderSwap = () => { };

            _rwlock.EnterUpgradeableReadLock();
            try
            {
                // Finds the branch point.
                Block <T> branchpoint = FindTopCommon(this, other);

                if (branchpoint is null)
                {
                    const string msg =
                        "A chain cannot be reorged into a heterogeneous chain with a " +
                        "different genesis.";
                    throw new InvalidGenesisBlockException(Genesis.Hash, other.Genesis.Hash, msg);
                }

                _logger.Debug(
                    "The branchpoint is #{BranchpointIndex} {BranchpointHash}.",
                    branchpoint.Index,
                    branchpoint
                    );

                Block <T> oldTip = Tip, newTip = other.Tip;

                ImmutableList <Block <T> > rewindPath      =
                    GetRewindPath(this, branchpoint.Hash);
                ImmutableList <Block <T> > fastForwardPath =
                    GetFastForwardPath(other, branchpoint.Hash);

                // If there is no rewind, it is not considered as a reorg.
                bool reorg = rewindPath.Count > 0;

                _rwlock.EnterWriteLock();
                try
                {
                    IEnumerable <Transaction <T> >
                    GetTxsWithRange(BlockChain <T> chain, Block <T> start, Block <T> end)
                    => Enumerable
                    .Range((int)start.Index + 1, (int)(end.Index - start.Index))
                    .SelectMany(x =>
                    {
                        // FIXME: Change the type of IBlockContent<T>.Transactions to
                        // IImmutableSet<Transaction<T>>, and define a distinct property
                        // to Block<T> for this ordering.
                        Block <T> block = chain[x];
                        return(ActionEvaluator <T> .OrderTxsForEvaluation(
                                   block.ProtocolVersion,
                                   block.Transactions,
                                   block.PreEvaluationHash
                                   ));
                    });

                    // It assumes reorg is small size. If it was big, this may be heavy task.
                    ImmutableHashSet <Transaction <T> > unstagedTxs =
                        GetTxsWithRange(this, branchpoint, Tip).ToImmutableHashSet();
                    ImmutableHashSet <Transaction <T> > stageTxs =
                        GetTxsWithRange(other, branchpoint, other.Tip).ToImmutableHashSet();
                    ImmutableHashSet <Transaction <T> > restageTxs = unstagedTxs.Except(stageTxs);
                    foreach (Transaction <T> restageTx in restageTxs)
                    {
                        StagePolicy.Stage(this, restageTx);
                    }

                    Guid obsoleteId = Id;
                    Id = other.Id;
                    Store.SetCanonicalChainId(Id);
                    _blocks = new BlockSet <T>(Policy.GetHashAlgorithm, Store);
                    TipChanged?.Invoke(this, (oldTip, newTip));

                    Store.DeleteChainId(obsoleteId);
                }
                finally
                {
                    _rwlock.ExitWriteLock();
                }

                renderSwap = () => RenderSwap(
                    render: render,
                    oldTip: oldTip,
                    newTip: newTip,
                    branchpoint: branchpoint,
                    rewindPath: rewindPath,
                    fastForwardPath: fastForwardPath,
                    stateCompleters: completers);
            }
            finally
            {
                _rwlock.ExitUpgradeableReadLock();
            }

            return(renderSwap);
        }