public JsonResult DeleteStoreOption(string id)
        {
            TransactionMessage model = new TransactionMessage();

            model = _storeoption.Delete(id);
            return(Json(model, JsonRequestBehavior.DenyGet));
        }
        public JsonResult DeleteUserStore(string id, string UserId)
        {
            TransactionMessage model = new TransactionMessage();

            model = _store.DeleteUserStore(id, UserId);
            return(Json(model, JsonRequestBehavior.DenyGet));
        }
예제 #3
0
        public JsonResult DeleteDocument(string id)
        {
            TransactionMessage model = new TransactionMessage();

            model = _document.Delete(id);
            return(Json(model, JsonRequestBehavior.DenyGet));
        }
예제 #4
0
        /// <summary>
        ///     Process a transaction message.
        /// </summary>
        /// <param name="transactionMessage"></param>
        private Task ProcessTransactionMessage(TransactionMessage transactionMessage)
        {
            if (transactionMessage.State == TransactionState.Start)
            {
                if (!_awaitedTransactions.ContainsKey(transactionMessage.TransactionId))
                {
                    _awaitedTransactions[transactionMessage.TransactionId]       = new TaskCompletionSource <Task>();
                    _awaitedTransactionCounter[transactionMessage.TransactionId] = 1;
                }

                else
                {
                    _awaitedTransactionCounter[transactionMessage.TransactionId]++;
                }
            }

            else if (transactionMessage.State == TransactionState.End)
            {
                if (--_awaitedTransactionCounter[transactionMessage.TransactionId] == 0)
                {
                    _awaitedTransactions[transactionMessage.TransactionId].SetResult(TaskDone.Done);
                }
            }

            return(TaskDone.Done);
        }
예제 #5
0
 public async Task Visit(TransactionMessage transactionMessage)
 {
     if (StreamTransactionReceivedFunc != null)
     {
         await StreamTransactionReceivedFunc(transactionMessage);
     }
 }
예제 #6
0
        /// <summary>
        /// to delete page
        /// </summary>
        /// <param name="encryptedId">encrypted page id</param>
        /// <returns></returns>
        public TransactionMessage Delete(string encryptedId)
        {
            TransactionMessage model = new TransactionMessage();

            model.Status  = MessageStatus.Error;
            model.Message = utilityHelper.ReadGlobalMessage("ManageUser", "InvalidRequest");
            try
            {
                if (encryptedId.IsValidEncryptedID())
                {
                    int UserStoreId = Convert.ToInt32(encryptedId.ToDecrypt());
                    var item        = UnitofWork.RepoUserStore.Where(x => x.UserStoreID == UserStoreId).FirstOrDefault();
                    if (item != null)
                    {
                        UnitofWork.RepoUserStore.Delete(item);
                        UnitofWork.Commit();
                        model.Message = utilityHelper.ReadGlobalMessage("ManageStoreOption", "Delete");
                        model.Status  = MessageStatus.Success;
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogHandler.WriteLog(ex);
            }
            return(model);
        }
        public async void ShouldThrowExceptionWhenHardCapUsdExceeded()
        {
            // Arrange
            var message = new TransactionMessage
            {
                Email      = "*****@*****.**",
                CreatedUtc = DateTime.Now.AddDays(10).ToUniversalTime(),
                UniqueId   = "111"
            };

            var messageJson = message.ToJson();

            var svc = Init(message.Email, Decimal.ToDouble(1M));

            _campaignInfoRepository
            .Setup(m => m.GetValueAsync(It.Is <CampaignInfoType>(t => t == CampaignInfoType.AmountInvestedUsd)))
            .Returns(() => Task.FromResult("1000001"));

            await svc.Process(message);

            // Assert
            _investorRefundRepository.Verify(m => m.SaveAsync(
                                                 It.Is <string>(v => v == message.Email),
                                                 It.Is <InvestorRefundReason>(v => v == InvestorRefundReason.HardCapUsdExceeded),
                                                 It.Is <string>(v => v == messageJson)));
        }
예제 #8
0
        private void RequestMorePeersLoop()
        {
            while (true)
            {
                if (_peerTracker.NeedsMoreConnectedPeers)
                {
                    foreach (var remoteNode in _peerTracker.GetConnectedPeers())
                    {
                        if (!remoteNode.QueueContainsMessageType <RequestPeerAddressesMessage>())
                        {
                            remoteNode.QueueMessage(new RequestPeerAddressesMessage());
                            var transMessage = new TransactionMessage(new TransferTransaction());
                            remoteNode.QueueMessage(transMessage);
                        }
                    }

                    foreach (var endpoint in _peerTracker.GetNotConnectedEndPoints(Int32.MaxValue, 0))
                    {
                        Task.Run(() => ConnectToPeer(endpoint));
                    }

                    for (int i = 0; i < 50; i++)
                    {
                        Thread.Sleep(100);
                    }
                }
            }
        }
예제 #9
0
        public async Task Process(TransactionMessage msg)
        {
            await _log.WriteInfoAsync(nameof(Process),
                $"msg: {msg.ToJson()}", $"New transaction");

            await ValidateMessage(msg);

            var txProcessed = await WasTxAlreadyProcessed(msg);
            if (txProcessed)
            {
                return;
            }

            var settings = await GetCampaignSettings();
            var soldTokensAmount = await GetSoldTokensAmount();

            var validTx = await IsTxValid(msg, settings, soldTokensAmount);
            if (validTx)
            {
                var transaction = await SaveTransaction(msg, settings, soldTokensAmount);

                await UpdateCampaignAmounts(transaction);
                await UpdateInvestorAmounts(transaction);
                await UpdateLatestTransactions(transaction);
                await UpdateInvestorReferralCode(transaction, settings);
                await SendConfirmationEmail(transaction, msg.Link, settings);
            }
        }
        public ActionResult Save(AdMonthModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.EncryptedID.IsValidEncryptedID() && model.EncryptedID.ToDecrypt().IsNumber())
                    {
                        model.AdMonthID = Convert.ToInt32(model.EncryptedID.ToDecrypt());
                    }


                    model = _AdMonth.Save(model);
                    if (model.TransMessage.Status == MessageStatus.Success)
                    {
                        SuccessNotification(model.TransMessage.Message);
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
        public JsonResult DeleteCouponAdMonth(string id, string MonthId)
        {
            TransactionMessage model = new TransactionMessage();

            model = _coupon.DeleteCouponAdMonth(id, MonthId);
            return(Json(model, JsonRequestBehavior.DenyGet));
        }
        public JsonResult DeleteAdMonth(string id)
        {
            TransactionMessage model = new TransactionMessage();

            model = _AdMonth.Delete(id);
            return(Json(model, JsonRequestBehavior.DenyGet));
        }
예제 #13
0
        public ActionResult SaveUser(UsersModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    bool isNew = true;

                    model.UserID = SessionHelper.UserId;
                    isNew        = false;

                    model = _user.Save(model);
                    if (model.TransMessage.Status == MessageStatus.Success)
                    {
                        SessionHelper.UserName = model.OwnerName;
                        SuccessNotification(model.TransMessage.Message);
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageUser", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
        public ActionResult SaveCouponAdMonth(CouponAdMonthModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    model = _coupon.CouponAdMonthSave(model);
                    if (model.TransMessage.Status == MessageStatus.Success)
                    {
                        SuccessNotification(model.TransMessage.Message);
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(model.TransMessage, JsonRequestBehavior.DenyGet));
        }
        public async void ShouldDoIgnoreAlreadySavedTranscation()
        {
            // Arrange
            var message = new TransactionMessage
            {
                Email      = "*****@*****.**",
                CreatedUtc = DateTime.Now.ToUniversalTime(),
                UniqueId   = "111"
            };

            var svc = Init(message.Email, Decimal.ToDouble(1M));

            _investorTransactionRepository
            .Setup(m => m.GetAsync(
                       It.Is <string>(v => v == message.Email),
                       It.Is <string>(v => v == message.UniqueId)))
            .Returns(() => Task.FromResult(_investorTransaction));

            // Act
            await svc.Process(message);

            // Assert
            _investorTransactionRepository.Verify(m => m.GetAsync(
                                                      It.IsAny <string>(),
                                                      It.IsAny <string>()));
        }
예제 #16
0
        public ActionResult Save(DocumentModel model, HttpPostedFileBase files)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid && files != null)
                {
                    model.FileName = files.FileName;
                    model.FilePath = utilityHelper.UploadFile(files);
                    model          = _document.Save(model);
                    if (model.TransMessage.Status == MessageStatus.Success)
                    {
                        SuccessNotification(model.TransMessage.Message);
                    }
                }
                else
                {
                    ErrorNotification(utilityHelper.ReadGlobalMessage("Document", "ErrorMessage"));
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(RedirectToAction("Index", new { id = model.MonthID }));
        }
예제 #17
0
        private async Task<bool> IsTxValid(TransactionMessage msg, ICampaignSettings settings, decimal soldTokensAmount)
        {
            var preSalePhase = settings.IsPreSale(msg.CreatedUtc);
            var crowdSalePhase = settings.IsCrowdSale(msg.CreatedUtc);
            var amountInvestedUsd = await GetInvestedUsdAmount();

            if (!preSalePhase && !crowdSalePhase)
            {
                await _log.WriteInfoAsync(nameof(Process),
                    $"msg: {msg}, settings: {settings.ToJson()}",
                    $"Transaction is out of campaign dates");

                await _investorRefundRepository.SaveAsync(msg.Email, 
                    InvestorRefundReason.OutOfDates, 
                    msg.ToJson());

                return false;
            }
            if (preSalePhase && soldTokensAmount > settings.PreSaleTotalTokensAmount)
            {
                await _log.WriteInfoAsync(nameof(Process),
                    $"soldTokensAmount: {soldTokensAmount}, settings: {settings.ToJson()}, msg: {msg.ToJson()}",
                    $"All presale tokens were sold out");

                await _investorRefundRepository.SaveAsync(msg.Email, 
                    InvestorRefundReason.PreSaleTokensSoldOut, 
                    msg.ToJson());

                return false;
            }
            if (crowdSalePhase && soldTokensAmount > settings.GetTotalTokensAmount())
            {
                await _log.WriteInfoAsync(nameof(Process),
                    $"soldTokensAmount: {soldTokensAmount}, totalTokensAmount: {settings.GetTotalTokensAmount()}, " +
                    $"settings: {settings.ToJson()}, msg: {msg.ToJson()}",
                    $"All tokens were sold out");

                await _investorRefundRepository.SaveAsync(msg.Email,
                    InvestorRefundReason.TokensSoldOut,
                    msg.ToJson());

                return false;
            }
            if (crowdSalePhase && amountInvestedUsd > settings.HardCapUsd)
            {
                await _log.WriteInfoAsync(nameof(Process),
                    $"amountInvestedUsd: {amountInvestedUsd}, hardCapUsd: {settings.HardCapUsd}, " +
                    $"settings: {settings.ToJson()}, msg: {msg.ToJson()}",
                    $"HardCapUsd was exceeded");

                await _investorRefundRepository.SaveAsync(msg.Email,
                    InvestorRefundReason.HardCapUsdExceeded,
                    msg.ToJson());

                return false;
            }

            return true;
        }
예제 #18
0
 public async Task Visit(TransactionMessage transactionMessage)
 {
     TransactionMessageArrived(transactionMessage);
     if (_streamMessageVisitor != null)
     {
         await _streamMessageVisitor.Visit(transactionMessage);
     }
 }
예제 #19
0
        public void Broadcast(Message message)
        {
            if (Args.Instance.IsFastForward &&
                !(message is BlockMessage))
            {
                return;
            }

            if (this.inventory_spread.Count > this.max_spread_size)
            {
                Logger.Warning(
                    string.Format("Drop message, type: {0}, ID: {1}.",
                                  message.Type,
                                  message.MessageId));
                return;
            }

            Item item = null;

            if (message is BlockMessage)
            {
                BlockMessage block_message = (BlockMessage)message;

                item = new Item(block_message.MessageId, InventoryType.Block);
                Logger.Info("Ready to broadcast block " + block_message.Block.Id.GetString());

                block_message.Block.Transactions.ForEach(tx =>
                {
                    var find = this.inventory_spread.FirstOrDefault(pair => pair.Key.Hash == tx.Id);
                    if (!find.Equals(default(KeyValuePair <Item, long>)))
                    {
                        this.inventory_spread.TryRemove(find.Key, out _);
                        this.transaction_cache.Add(new Item(find.Key.Hash, InventoryType.Trx).ToString(), new TransactionMessage(tx.Instance));
                    }
                });

                this.block_cache.Add(item.ToString(), message);
            }
            else if (message is TransactionMessage)
            {
                TransactionMessage tx_message = (TransactionMessage)message;
                item = new Item(tx_message.MessageId, InventoryType.Trx);

                this.tx_count.Add();
                this.transaction_cache.Add(item.ToString(), new TransactionMessage(((TransactionMessage)message).Transaction.Instance));
            }
            else
            {
                Logger.Error("Adv item is neither block nor trx, type : " + message.Type.ToString());
                return;
            }

            this.inventory_spread.TryAdd(item, Helper.CurrentTimeMillis());
            if (item.Type == InventoryType.Block)
            {
                ConsumerInventoryToSpread();
            }
        }
        public void CreateMessageWithTransaction()
        {
            Transaction transaction = FactoryHelper.CreateTransaction(100);

            TransactionMessage message = new TransactionMessage(transaction);

            Assert.AreSame(transaction, message.Transaction);
            Assert.AreEqual(MessageType.TransactionMessage, message.MessageType);
        }
예제 #21
0
        /// <summary>
        /// Processes the initial echo message
        /// </summary>
        /// <param name="session"></param>
        /// <param name="message"></param>
        public override void ProcessInitialMessage(IDSPExSession session, TransactionInitialMessage message)
        {
            // Echo the message's data
            Logger.L(LoggerLevel.Info, "Sending echo response of length " + message.DataLength);
            var response = new TransactionMessage(TransactionID, message.DataBuffer, message.DataOffset, message.DataLength);

            session.SendMessage(response);
            session.DeregisterRITransactionHandler(this);
        }
 protected async Task ProcessTransactionMessage(TransactionMessage transactionMessage)
 {
     if (transactionMessage.State == TransactionState.End)
     {
         await StreamSender.AwaitSendingComplete();
     }
     // TODO: Make sure all items prior to sending the end message are processed when implementing methods not running on grain thread.
     await StreamSender.SendMessage(transactionMessage);
 }
예제 #23
0
        public ActionResult DoLogin(LoginModel model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status = MessageStatus.Error;
            try
            {
                if (ModelState.IsValid)
                {
                    string password = model.Password.ToEnctyptedPassword();
                    // check user credential
                    var user = UnitofWork.RepoUser.Where(x => x.Email.ToLower() == model.Email.ToLower() && x.Password == password && x.IsAdmin == true && x.IsActive == true).FirstOrDefault();
                    if (user != null)
                    {
                        SessionHelper.UserId   = user.UserID;
                        SessionHelper.UserName = user.Ownername ?? "";
                        SessionHelper.IsAdmin  = user.IsAdmin;

                        if (model.RememberMe)
                        {
                            SessionHelper.UserCookie = user.UserID.ToString().ToEnctypt();
                        }

                        #region Add to History
                        var browser = Request.Browser;

                        UnitofWork.RepoLoginHistory.Add(new LoginHistory()
                        {
                            Browser   = browser.Browser,
                            TimeStamp = utilityHelper.CurrentDateTime,
                            UserID    = user.UserID,
                            IPaddress = utilityHelper.IpAddress(),
                            Device    = browser.IsMobileDevice ? "Mobile" : "Web",
                        });
                        UnitofWork.Commit();
                        #endregion

                        TransMessage.Status  = MessageStatus.Success;
                        TransMessage.Message = string.IsNullOrEmpty(model.ReturnUrl) ? Url.Action("Index", "Dashboard") : model.ReturnUrl;
                    }
                    else
                    {
                        TransMessage.Message = utilityHelper.ReadGlobalMessage("Login", "ErrorMessage");
                    }
                }
                else
                {
                    TransMessage.Message = utilityHelper.ReadGlobalMessage("Login", "ErrorMessage");
                }
            }
            catch (Exception ex)
            {
                // write exception log
                EventLogHandler.WriteLog(ex);
            }
            return(Json(TransMessage, JsonRequestBehavior.DenyGet));
        }
 public override void ProcessMessage(IDSPExSession session, TransactionMessage message)
 {
     throw new InvalidOperationException(
        "ProcessMessage invoked on stateless rith! " +
        $"TID: {message.TransactionId} " +
        $"OFF: {message.DataOffset} " +
        $"LEN: {message.DataLength} " +
        $"DAT: {message.DataBuffer.ToHex()} "
     );
 }
예제 #25
0
 public Task <TransactionResponse> ResponseMessage(TransactionMessage request, ServerCallContext context)
 {
     Console.WriteLine($"Received: {request.OwnerCardId} {request.RecipientCardId} {request.Ccy} {request.TransactionType} " +
                       $"{request.TransactionSumm} {request.AditionalComment}");
     return(Task.FromResult(new TransactionResponse()
     {
         Status = true,
         Message = "Transaction successful arrived."
     }));
 }
예제 #26
0
 public override void ProcessMessage(IDSPExSession session, TransactionMessage message)
 {
     throw new InvalidOperationException(
               "ProcessMessage invoked on stateless rith! " +
               $"TID: {message.TransactionId} " +
               $"OFF: {message.DataOffset} " +
               $"LEN: {message.DataLength} " +
               $"DAT: {message.DataBuffer.ToHex()} "
               );
 }
예제 #27
0
        private void SaveTransaction(TransactionMessage txnMessage)
        {
            _accountBalance.Update(txnMessage.Amount);

            _repository.Add(new Transaction
            {
                AccountNumber = txnMessage.Account,
                Amount        = txnMessage.Amount,
                StartDate     = txnMessage.StartDate
            });
        }
 public async Task Visit(TransactionMessage transactionMessage)
 {
     // TODO: Make sure all items prior to sending the end message are processed when implementing methods not running on grain thread.
     if (transactionMessage.State == TransactionState.Start)
     {
         await StreamProvider.StartTransaction(transactionMessage.TransactionId);
     }
     else if (transactionMessage.State == TransactionState.End)
     {
         await StreamProvider.EndTransaction(transactionMessage.TransactionId);
     }
 }
예제 #29
0
        public ActionResult PopulateEntryConformed()
        {
            TransactionMessage model = new TransactionMessage();

            if (SessionHelper.SessionForModel != null && SessionHelper.SessionForModel.GetType() == typeof(StoreAdChoiceListModel))
            {
                StoreAdChoiceListModel storeAdChoiceListModel = (StoreAdChoiceListModel)SessionHelper.SessionForModel;
                model = _store.UpdateMissingEntry(storeAdChoiceListModel.storAdChoiceList);
                SessionHelper.SessionForModel = null;
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public void TxnCompleted(string Id, object t, string state)
        {
            var point = GetPoint();
            var msg   = new TransactionMessage();

            msg.StartTime  = point.StartTime;
            msg.Offset     = point.Offset;
            msg.Connection = Id;
            msg.Kind       = Kind.Commit | Kind.V2;
            msg.Text       = state;
            Publish2(msg);
        }
예제 #31
0
        public ActionResult SaveUserAdChoice(List <StoreAdChoiceModel> model)
        {
            TransactionMessage TransMessage = new TransactionMessage();

            TransMessage.Status  = MessageStatus.Error;
            TransMessage.Message = "Redirecting to next step";

            string msg     = "";
            int    counter = 0;
            int    i       = 0;

            try
            {
                if (model != null)
                {
                    List <StoreAdChoiceModel> list = new List <StoreAdChoiceModel>();
                    if (SessionHelper.SessionForModel != null && SessionHelper.SessionForModel.GetType() == typeof(List <StoreAdChoiceModel>))
                    {
                        list = (List <StoreAdChoiceModel>)SessionHelper.SessionForModel;
                    }

                    #region Validation
                    foreach (var item in model)
                    {
                        list[i++].ChoiceInitials = item.ChoiceInitials;
                    }
                    SessionHelper.SessionForModel = list;
                    #endregion

                    if (counter > 0)
                    {
                        TransMessage.Status  = MessageStatus.Error;
                        TransMessage.Message = msg;
                    }
                    else // save to database
                    {
                        TransMessage = _storeadchoice.Save(list);
                        if (TransMessage.Status == MessageStatus.Success)
                        {
                            // TransMessage.Message = utilityHelper.ReadGlobalMessage("Store", "Save");
                            SessionHelper.SessionForModel = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TransMessage.Message = utilityHelper.ReadGlobalMessage("Store", "Error");
                EventLogHandler.WriteLog(ex);
            }

            return(Json(TransMessage, JsonRequestBehavior.DenyGet));
        }
예제 #32
0
 public override void ProcessMessage(IDSPExSession session, TransactionMessage message)
 {
     throw new System.NotImplementedException();
 }
 public void SendMessage(TransactionMessage message) {
    innerSession.SendMessage(message);
 }