public string Encode(string marker, TR? HIV = null, TR? HCV_Ab = null, TR? HBs_Ag = null, TR? Syphilis = null, TR? Malaria = null)
        {
            if (HIV.HasValue)
            {
                //BR Business Requirement: As CR user requirement, value for both test result are always the same.
                marker = Infection.HIV_Ab.Encode(marker, HIV.Value);
                marker = Infection.HIV_Ag.Encode(marker, HIV.Value);
            }

            if (HCV_Ab.HasValue)
            {
                marker = Infection.HCV_Ab.Encode(marker, HCV_Ab.Value);
            }

            if (HBs_Ag.HasValue)
            {
                marker = Infection.HBs_Ag.Encode(marker, HBs_Ag.Value);
            }

            if (Malaria.HasValue)
            {
                marker = Infection.Malaria.Encode(marker, Malaria.Value);
            }

            if (Syphilis.HasValue)
            {
                marker = Infection.Syphilis.Encode(marker, Syphilis.Value);
            }

            return marker;
        }
예제 #2
0
 /// <summary>
 /// 当区块被写入到硬盘后调用
 /// </summary>
 /// <param name="block">区块</param>
 protected void OnPersistCompleted(Block block)
 {
     TR.Enter();
     PersistCompleted?.Invoke(this, block);
     TR.Exit();
 }
예제 #3
0
 /// <summary>
 /// 根据指定的区块高度,返回对应区块及之前所有区块中包含的系统费用的总量
 /// </summary>
 /// <param name="height">区块高度</param>
 /// <returns>返回对应的系统费用的总量</returns>
 public virtual long GetSysFeeAmount(uint height)
 {
     TR.Enter();
     return(TR.Exit(GetSysFeeAmount(GetBlockHash(height))));
 }
예제 #4
0
        public virtual IEnumerable <ECPoint> GetValidators(IEnumerable <Transaction> others)
        {
            TR.Enter();
            DataCache <UInt160, AccountState>    accounts         = GetStates <UInt160, AccountState>();
            DataCache <ECPoint, ValidatorState>  validators       = GetStates <ECPoint, ValidatorState>();
            MetaDataCache <ValidatorsCountState> validators_count = GetMetaData <ValidatorsCountState>();

            foreach (Transaction tx in others)
            {
                foreach (TransactionOutput output in tx.Outputs)
                {
                    AccountState account = accounts.GetAndChange(output.ScriptHash, () => new AccountState(output.ScriptHash));
                    if (account.Balances.ContainsKey(output.AssetId))
                    {
                        account.Balances[output.AssetId] += output.Value;
                    }
                    else
                    {
                        account.Balances[output.AssetId] = output.Value;
                    }
                    if (output.AssetId.Equals(GoverningToken.Hash) && account.Votes.Length > 0)
                    {
                        foreach (ECPoint pubkey in account.Votes)
                        {
                            validators.GetAndChange(pubkey, () => new ValidatorState(pubkey)).Votes += output.Value;
                        }
                        validators_count.GetAndChange().Votes[account.Votes.Length - 1] += output.Value;
                    }
                }
                foreach (var group in tx.Inputs.GroupBy(p => p.PrevHash))
                {
                    Transaction tx_prev = GetTransaction(group.Key, out int height);
                    foreach (CoinReference input in group)
                    {
                        TransactionOutput out_prev = tx_prev.Outputs[input.PrevIndex];
                        AccountState      account  = accounts.GetAndChange(out_prev.ScriptHash);
                        if (out_prev.AssetId.Equals(GoverningToken.Hash))
                        {
                            if (account.Votes.Length > 0)
                            {
                                foreach (ECPoint pubkey in account.Votes)
                                {
                                    ValidatorState validator = validators.GetAndChange(pubkey);
                                    validator.Votes -= out_prev.Value;
                                    if (!validator.Registered && validator.Votes.Equals(Fixed8.Zero))
                                    {
                                        validators.Delete(pubkey);
                                    }
                                }
                                validators_count.GetAndChange().Votes[account.Votes.Length - 1] -= out_prev.Value;
                            }
                        }
                        account.Balances[out_prev.AssetId] -= out_prev.Value;
                    }
                }
                switch (tx)
                {
#pragma warning disable CS0612
                case EnrollmentTransaction tx_enrollment:
                    validators.GetAndChange(tx_enrollment.PublicKey, () => new ValidatorState(tx_enrollment.PublicKey)).Registered = true;
                    break;

#pragma warning restore CS0612
                case StateTransaction tx_state:
                    foreach (StateDescriptor descriptor in tx_state.Descriptors)
                    {
                        switch (descriptor.Type)
                        {
                        case StateType.Account:
                            ProcessAccountStateDescriptor(descriptor, accounts, validators, validators_count);
                            break;

                        case StateType.Validator:
                            ProcessValidatorStateDescriptor(descriptor, validators);
                            break;
                        }
                    }
                    break;
                }
            }
            int count = (int)validators_count.Get().Votes.Select((p, i) => new
            {
                Count = i,
                Votes = p
            }).Where(p => p.Votes > Fixed8.Zero).ToArray().WeightedFilter(0.25, 0.75, p => p.Votes.GetData(), (p, w) => new
            {
                p.Count,
                Weight = w
            }).WeightedAverage(p => p.Count, p => p.Weight);
            count = Math.Max(count, StandbyValidators.Length);
            HashSet <ECPoint>     sv      = new HashSet <ECPoint>(StandbyValidators);
            ECPoint[]             pubkeys = validators.Find().Select(p => p.Value).Where(p => (p.Registered && p.Votes > Fixed8.Zero) || sv.Contains(p.PublicKey)).OrderByDescending(p => p.Votes).ThenBy(p => p.PublicKey).Select(p => p.PublicKey).Take(count).ToArray();
            IEnumerable <ECPoint> result;
            if (pubkeys.Length == count)
            {
                result = pubkeys;
            }
            else
            {
                HashSet <ECPoint> hashSet = new HashSet <ECPoint>(pubkeys);
                for (int i = 0; i < StandbyValidators.Length && hashSet.Count < count; i++)
                {
                    hashSet.Add(StandbyValidators[i]);
                }
                result = hashSet;
            }
            return(TR.Exit(result.OrderBy(p => p)));
        }
예제 #5
0
 public bool ContainsUnspent(CoinReference input)
 {
     TR.Enter();
     return(TR.Exit(ContainsUnspent(input.PrevHash, input.PrevIndex)));
 }
예제 #6
0
        public new ActionResult Profile(UserProfileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            User user = null;

            try
            {
                user = AppContext.Instance.CurrentUser(User.Identity);
            }
            catch (Exception)
            {
                return(RedirectToAction("Logout", "Account"));
            }
            if (model.Photo != null)
            {
                var filename = Guid.NewGuid().ToString() + '-' + Guid.NewGuid().ToString() + ".jpg";
                model.Photo.SaveAs(Server.MapPath("~/Uploads/" + filename));
                if (!string.IsNullOrEmpty(user.PhotoPath))
                {
                    try
                    {
                        System.IO.File.Delete(Server.MapPath("~/Uploads/" + user.PhotoPath));
                    }
                    catch (Exception)
                    {
                    }
                }
                user.PhotoPath = filename;

                var bitmap          = new Bitmap(Server.MapPath("~/Uploads/" + user.PhotoPath));
                var previewImage    = ImageHelper.ResizeImage(bitmap, 64, 64);
                var previewFilename = Guid.NewGuid().ToString() + '-' + Guid.NewGuid().ToString() + ".jpg";
                previewImage.Save(Server.MapPath("~/Uploads/" + previewFilename));
                user.PhotoPreviewPath = previewFilename;
            }

            user.BirthDate = model.BirthDate;
            user.Name      = model.Name;
            user.Surname   = model.Surname;
            user.Phone     = model.Phone;
            user.IsAdmin   = false;

            var manager = ManagerProvider.Instance.
                          Get <User>();

            if (manager == null)
            {
                throw new Exception(TR.T("Менеджер для сущности %1 не зарегистрирован в системе!", "User"));
            }

            try
            {
                manager.CreateEntity(user);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Photo", TR.T("Не удалось обновить данные профиля! %1", ex.Message));
            }
            return(RedirectToAction("Index"));
        }
예제 #7
0
 public override bool Equals(object obj)
 {
     TR.Enter();
     return(TR.Exit(Equals(obj as KeyPair)));
 }
        public static DonationErr Update(string DIN, Infection infection, TR? TR = null, string note = "")
        {
            if (infection == null)
            {
                return DonationErrEnum.NonTR;
            }
            else
            {
                Func<Infection, Infection, TR?, TR?> f = (infecIn, infecOut, TRValue) =>
                {
                    return infecIn == infecOut ? TRValue : null;
                };

                return Update(DIN,
                    f(infection, Infection.HIV_Ab, TR),
                    f(infection, Infection.HCV_Ab, TR),
                    f(infection, Infection.HBs_Ag, TR),
                    f(infection, Infection.Syphilis, TR),
                    f(infection, Infection.Malaria, TR),
                    note);
            }
        }
예제 #9
0
 public SliceBuilder Add(string value)
 {
     TR.Enter();
     data.AddRange(Encoding.UTF8.GetBytes(value));
     return(TR.Exit(this));
 }
예제 #10
0
 public SliceBuilder Add(IEnumerable <byte> value)
 {
     TR.Enter();
     data.AddRange(value);
     return(TR.Exit(this));
 }
예제 #11
0
 public SliceBuilder Add(long value)
 {
     TR.Enter();
     data.AddRange(BitConverter.GetBytes(value));
     return(TR.Exit(this));
 }
예제 #12
0
        public override Task Render(RequestContext ctx, StringWriter stream, IDummy authObj)
        {
            #if MONO
            AddResource(new JsResource(Constants.kWebRoot, "/js/marketsPageCompiled.js", true));
            #endif

            AddResource(new CssResource(Constants.kWebRoot, "/css/markets.css", true));

            ImgResource logo = CreateLogo();
            AddResource(logo);

            // render head
            base.Render(ctx, stream, authObj);

            using (new DivContainer(stream, "ng-app", "myApp", "ng-controller", "MarketsController", HtmlAttributes.id, "rootId"))
            {
                using (new DivContainer(stream, HtmlAttributes.@class, "jumbotron clearfix no-padding-bottom-top"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "container"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                        {
                            using (new DivContainer(stream, HtmlAttributes.@class, "col-xs-12"))
                            {
                                RenderJumbo(stream, logo);
                            }
                        }
                    }
                }

                using (new DivContainer(stream, HtmlAttributes.@class, "container"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-12"))
                        {
                            using (new Table(stream, "", 4, 4, "table table-striped table-hover noMargin", new string[]
                                { "",		"hidden-sm hidden-xs hidden-md",	"",			"",						"",			"hidden-xs",		"hidden-xs",	"hidden-xs hidden-sm",	"hidden-xs hidden-sm" },
                                "Market",	"Currency",						"Price",	"Volume (BTC)", "Spread %", "Ask",				"Bid",				"Buy fee (%)",	"Sell fee (%)"))
                            {
                                using (var tr = new TR(stream, "ng-if", "!t.flipped", "ng-repeat", "t in allMarkets", HtmlAttributes.@class, "clickable-row",
                                                                                                "ng-click",
                                                                                                "go(t)"))
                                {
                                    tr.TD("{{renameSymbolPair(t.symbol_pair)}}");
                                    tr.TD("{{t.asset_name}}", HtmlAttributes.@class, "hidden-sm hidden-xs hidden-md");

                                    tr.TD("{{t.last_price}} <i class=\"glyphicon glyphicon-arrow-up text-success\"/>", "ng-if", "t.price_delta>0");
                                    tr.TD("{{t.last_price}} <i class=\"glyphicon glyphicon-arrow-down text-danger\"/>", "ng-if", "t.price_delta<0");
                                    tr.TD("{{t.last_price}} <i class=\"glyphicon glyphicon glyphicon-minus text-info\"/>", "ng-if", "t.price_delta==0");

                                    tr.TD("{{t.btc_volume_24h | number:2}}");
                                    tr.TD("{{t.realised_spread_percent | number:2}}");
                                    tr.TD("{{t.ask}}", HtmlAttributes.@class, "hidden-xs");
                                    tr.TD("{{t.bid}}", HtmlAttributes.@class, "hidden-xs");
                                    tr.TD("{{t.ask_fee_percent | number:2}}", HtmlAttributes.@class, "hidden-sm hidden-xs");
                                    tr.TD("{{t.bid_fee_percent | number:2}}", HtmlAttributes.@class, "hidden-sm hidden-xs");
                                }
                            }
                        }
                    }
                }

                //
                // bullet points
                //
                using (new DivContainer(stream, HtmlAttributes.@class, "container",
                                                    HtmlAttributes.style, "margin-top:20px"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-4"))
                        {
                            H4("<i class=\"glyphicon glyphicon-ok text-info\"></i>  No registration required");
                            P("There is no need to register an account, just tell us where you'd like to receive the coins that you buy or sell.");
                        }

                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-4"))
                        {
                            H4("<i class=\"glyphicon glyphicon-flash text-info\"></i>  Fast transactions");
                            P("Only one confirmation is neccessary for buying or selling, which is around 7 minutes for a buy and around 3 seconds for a sell.");
                        }

                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-4"))
                        {
                            H4("<i class=\"glyphicon glyphicon-lock text-info\"></i>  Safe");
                            P("We don't hold any of our customer's funds, so there is nothing to get lost or stolen.");
                        }
                    }
                }

                using (new DivContainer(stream, HtmlAttributes.@class, "bg-primary hidden-xs",
                                                HtmlAttributes.style, "margin-top:20px"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "container"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.style, "margin:30px 0px 30px 0px"))
                        {
                            using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                            {
                                using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-12"))
                                {
                                    H3("Recent transactions");

                                    using (new Table(stream, "", 4, 4, "table noMargin", "Market", "Type", "Price", "Amount", "Fee", "Date"))
                                    {
                                        using (var tr = new TR(stream, "ng-repeat", "t in transactions"))
                                        {
                                            tr.TD("{{renameSymbolPair(t.symbol_pair)}}");
                                            tr.TD("{{t.order_type}}");
                                            tr.TD("{{t.price}}");
                                            tr.TD("{{t.amount}}");
                                            tr.TD("{{t.fee}}");
                                            tr.TD("{{t.date*1000 | date:'MMM d, HH:mm'}}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
        public static void UpdateNegative(string DIN, TR from = TR.non, string note = "UpdateNegative")
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Func<TR, TR?> f = x => { return x == from ? TR.neg : new Nullable<TR>(); };
            var v = DonationDAL.Get(db, DIN);

            Update(DIN, f(v.TR_HIV.Value), f(v.TR_HCV_Ab.Value), f(v.TR_HBs_Ag.Value), f(v.TR_Syphilis.Value), f(v.TR_Malaria.Value), note);
        }
예제 #14
0
 public DataCache <TKey, TValue> CreateSnapshot()
 {
     TR.Enter();
     return(TR.Exit(new CloneCache <TKey, TValue>(this)));
 }
예제 #15
0
 public SliceBuilder Add(ISerializable value)
 {
     TR.Enter();
     data.AddRange(value.ToArray());
     return(TR.Exit(this));
 }
예제 #16
0
 public IEnumerator <T> GetEnumerator()
 {
     TR.Enter();
     return(TR.Exit(list.GetEnumerator()));
 }
예제 #17
0
 public static SliceBuilder Begin()
 {
     TR.Enter();
     return(TR.Exit(new SliceBuilder()));
 }
예제 #18
0
 public override string ToString()
 {
     TR.Enter();
     return(TR.Exit(PublicKey.ToString()));
 }
예제 #19
0
 public static SliceBuilder Begin(byte prefix)
 {
     TR.Enter();
     return(TR.Exit(new SliceBuilder().Add(prefix)));
 }
예제 #20
0
 public override string ToString()
 {
     TR.Enter();
     return(TR.Exit(GetName()));
 }
예제 #21
0
    public static TR GetDefault(string name)
    {
        TR tr = TRList.Where(r => r.Name == name.Trim()).FirstOrDefault();

        return(tr == null ? na : tr);
    }
예제 #22
0
 static Blockchain()
 {
     TR.Enter();
     GenesisBlock.RebuildMerkleRoot();
     TR.Exit();
 }
예제 #23
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     TR.Enter();
     Headers = reader.ReadSerializableArray <Header>(2000);
     TR.Exit();
 }
예제 #24
0
 /// <summary>
 /// 获取记账人的合约地址
 /// </summary>
 /// <param name="validators">记账人的公钥列表</param>
 /// <returns>返回记账人的合约地址</returns>
 public static UInt160 GetConsensusAddress(ECPoint[] validators)
 {
     TR.Enter();
     return(TR.Exit(Contract.CreateMultiSigRedeemScript(validators.Length - (validators.Length - 1) / 3, validators).ToScriptHash()));
 }
예제 #25
0
 void ISerializable.Serialize(BinaryWriter writer)
 {
     TR.Enter();
     writer.Write(Headers);
     TR.Exit();
 }
예제 #26
0
 byte[] IScriptTable.GetScript(byte[] script_hash)
 {
     TR.Enter();
     return(TR.Exit(GetContract(new UInt160(script_hash)).Script));
 }
예제 #27
0
 protected MetaDataCache(Func <T> factory)
 {
     TR.Enter();
     this.factory = factory;
     TR.Exit();
 }
예제 #28
0
 /// <summary>
 /// 根据指定的散列值,返回对应的交易信息
 /// </summary>
 /// <param name="hash">散列值</param>
 /// <returns>返回对应的交易信息</returns>
 public Transaction GetTransaction(UInt256 hash)
 {
     TR.Enter();
     return(TR.Exit(GetTransaction(hash, out _)));
 }
예제 #29
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     TR.Enter();
     this.AddressList = reader.ReadSerializableArray <NetworkAddressWithTime>(200);
     TR.Exit();
 }
예제 #30
0
 protected internal IEnumerable <Trackable> GetChangeSet()
 {
     TR.Enter();
     return(TR.Exit(dictionary.Values.Where(p => p.State != TrackState.None)));
 }
예제 #31
0
 void ISerializable.Serialize(BinaryWriter writer)
 {
     TR.Enter();
     writer.Write(AddressList);
     TR.Exit();
 }
예제 #32
0
 public void Clear()
 {
     TR.Enter();
     list.Clear();
     TR.Exit();
 }
예제 #33
0
 public override int GetHashCode()
 {
     TR.Enter();
     return(TR.Exit(PublicKey.GetHashCode()));
 }
예제 #34
0
 IEnumerator IEnumerable.GetEnumerator()
 {
     TR.Enter();
     return(TR.Exit(GetEnumerator()));
 }
        public static DonationErr Update(string DIN,
            TR? HIV = null, TR? HCV_Ab = null, TR? HBs_Ag = null, TR? Syphilis = null, TR? Malaria = null,
            string note = "")
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation e = DonationDAL.Get(db, DIN);

            if (e == null) return DonationErrEnum.NonExist;
            if (e.Status != Donation.StatusX.HasPack_UnLock) return DonationErrEnum.TRLocked;

            string old = e.InfectiousMarkers;

            if (HIV.HasValue)
            {
                //BR: Should be update even thought the value are the same
                e.TR_HIV = HIV.Value;
            }

            if (HBs_Ag.HasValue)
            {
                e.TR_HBs_Ag = HBs_Ag.Value;
            }

            if (HCV_Ab.HasValue)
            {
                e.TR_HCV_Ab = HCV_Ab.Value;
            }

            if (Malaria.HasValue)
            {
                e.TR_Malaria = Malaria.Value;
            }

            if (Syphilis.HasValue)
            {
                e.TR_Syphilis = Syphilis.Value;
            }

            InfectiousMarkerBLL markerBLL = new InfectiousMarkerBLL();
            markerBLL.Encode(e);

            //Have to save before update TestResult Status
            db.SubmitChanges();

            DonationTestLogBLL.Insert(db, e, PropertyName.For<Donation>(r => r.InfectiousMarkers), note);

            UpdateTestResultStatus(e);
            db.SubmitChanges();

            return DonationErrEnum.Non;
        }