Beispiel #1
0
        public FluentResults.Result <string> QueryWithVars(string queryString, Dictionary <string, string> varMap)
        {
            AssertNotDisposed();

            if (transactionState != TransactionState.OK)
            {
                return(Results.Fail <string>(new TransactionFinished(transactionState.ToString())));
            }

            try {
                Api.Request request = new Api.Request();
                request.Query = queryString;
                request.Vars.Add(varMap);
                request.StartTs = context.StartTs;
                request.LinRead = context.LinRead;

                lastQueryResponse = client.Query(request);

                var err = MergeContext(lastQueryResponse.Txn);

                if (err.IsSuccess)
                {
                    return(Results.Ok <string>(lastQueryResponse.Json.ToStringUtf8()));
                }
                else
                {
                    return(err.ConvertToResultWithValueType <string>());
                }
            } catch (RpcException rpcEx) {
                return(Results.Fail <string>(new FluentResults.ExceptionalError(rpcEx)));
            }
        }
Beispiel #2
0
        public void Transaction(Newtonsoft.Json.Linq.JObject transactionData, TransactionState state)
        {
            var log = LoggerCommon(string.Format("Transaction State:{0}", state.ToString()), transactionData, Loglevels.Transaction.ToString());

            log[CommonConst.CommonField.TRANSACTION_STATE] = state.ToString();
            WriteLog(log);
        }
Beispiel #3
0
 public void Transaction(JObject transactionData, TransactionState state)
 {
     if (LogLevels.Contains("Transaction"))
     {
         var log = LoggerCommon(string.Format("Transaction State:{0}", state.ToString()), transactionData, "Transaction");
         log[CommonConst.CommonField.TRANSACTION_STATE] = state.ToString();
         WriteLog(log);
     }
 }
 public long CreateTransaction(long senderId, long recipientId, bool isAnonymous, TransactionState state, string comment, bool?fromPool = null)
 {
     if (senderId == recipientId)
     {
         throw new Exception("Sender and receiver can't be the same");
     }
     try
     {
         using (var context = new GritCoinEntities())
         {
             var SENDER = context.EMPLOYEE.FirstOrDefault(EMP => EMP.EMPLOYEE_ID == senderId);
             if (!fromPool.HasValue || fromPool.Value == false)
             {
                 fromPool = SENDER != null && SENDER.ELIGIBLE_FLAG == "N" ? true : false;
             }
             var TRANSACTION = new TRANSACTIONS
             {
                 TRANSACTION_ID     = GetSequenceNextValue(context, "GRITCOIN.TRANSACTIONS_SEQ"),
                 ANONYMOUS_FLAG     = isAnonymous ? "Y" : "N",
                 EFFECTIVE_DATE     = DateTime.Now,
                 CYCLE_ID           = CurrentCycle.CycleId,
                 RECIPIENT          = recipientId,
                 SENDER             = senderId,
                 SYSTEM_CHANGE_DATE = DateTime.Now,
                 TRANSACTION_STATE  = state.ToString(),
                 NOTE           = comment,
                 FROM_POOL_FLAG = fromPool.HasValue && fromPool.Value ? "Y" : "N"
             };
             context.AddToTRANSACTIONS(TRANSACTION);
             context.SaveChanges();
             return(TRANSACTION.TRANSACTION_ID);
         }
     }
     catch { throw; }
 }
Beispiel #5
0
        public async Task <Result <Response> > Mutate(
            RequestBuilder request,
            CallOptions?options = null
            )
        {
            AssertNotDisposed();

            CallOptions opts = options ?? new CallOptions();

            if (TransactionState != TransactionState.OK)
            {
                return(Results.Fail <Response>(new TransactionNotOK(TransactionState.ToString())));
            }

            var req = request.Request;

            if (req.Mutations.Count == 0)
            {
                return(Results.Ok <Response>(new Response(new Api.Response())));
            }

            HasMutated = true;

            req.StartTs = Context.StartTs;
            req.Hash    = Context.Hash;

            var response = await Client.DgraphExecute(
                async (dg) => Results.Ok <Response>(new Response(await dg.QueryAsync(req, opts))),
                (rpcEx) => Results.Fail <Response>(new ExceptionalError(rpcEx))
                );

            if (response.IsFailed)
            {
                await Discard();                           // Ignore error - user should see the original error.

                TransactionState = TransactionState.Error; // overwrite the aborted value
                return(response);
            }

            if (req.CommitNow)
            {
                TransactionState = TransactionState.Committed;
            }

            var err = MergeContext(response.Value.DgraphResponse.Txn);

            if (err.IsFailed)
            {
                // The WithReasons() here will turn this Ok, into a Fail.  So the result
                // and an error are in there like the Go lib.  But this can really only
                // occur on an internal Dgraph error, so it's really an error
                // and there's no need to code for cases to dig out the value and the
                // error - just
                //   if (...IsFailed) { ...assume mutation failed...}
                // is enough.
                return(Results.Ok <Response>(response.Value).WithReasons(err.Reasons));
            }

            return(Results.Ok <Response>(response.Value));
        }
Beispiel #6
0
        public async Task <Result> Commit(CallOptions?options = null)
        {
            AssertNotDisposed();

            if (TransactionState != TransactionState.OK)
            {
                return(Results.Fail(new TransactionNotOK(TransactionState.ToString())));
            }

            TransactionState = TransactionState.Committed;

            if (!HasMutated)
            {
                return(Results.Ok());
            }

            return(await Client.DgraphExecute(
                       async (dg) => {
                await dg.CommitOrAbortAsync(
                    Context,
                    options ?? new CallOptions(null, null, default(CancellationToken)));
                return Results.Ok();
            },
                       (rpcEx) => Results.Fail(new ExceptionalError(rpcEx))
                       ));
        }
Beispiel #7
0
 public void WriteXml(System.Xml.XmlWriter writer)
 {
     writer.WriteAttributeString("transactionId", TransactionId.ToString());
     writer.WriteAttributeString("name", _name.ToString());
     writer.WriteAttributeString("isolationLevel", IsolationLevel.ToString());
     writer.WriteAttributeString("createdOn", CreatedOn.ToString());
     writer.WriteAttributeString("transactionState", TransactionState.ToString());
 }
Beispiel #8
0
        public static void TransactionUpdated(string productID, TransactionState state, string transactionID, string receipt, Int32 quantity)
        {
            UtilsLog.Info("IAPMsgSwitch", "[TransactionUpdated] ProductID:{0}({1}) State:{2} TransactionID:{3} Receipt:{4}",
                          ((true == string.IsNullOrEmpty(productID)) ? "null" : productID),
                          quantity, state.ToString(),
                          ((true == string.IsNullOrEmpty(transactionID)) ? "null" : transactionID),
                          ((true == string.IsNullOrEmpty(receipt)) ? "null" : receipt));
            switch (state)
            {
            case TransactionState.Purchasing:
                if ((null != IAPInstance) && (null != IAPInstance.OnTransactionPurchasing))
                {
                    IAPInstance.OnTransactionPurchasing(productID, quantity);
                }
                break;

            case TransactionState.Purchased:
            {
                if ((null != IAPInstance) && (null != IAPInstance.OnTransactionPurchased))
                {
                    IAPInstance.OnTransactionPurchased(productID, quantity, transactionID, receipt);
                }
            }
            break;

            case TransactionState.Canceled:
            {
                if ((null != IAPInstance) && (null != IAPInstance.OnTransactionCanceled))
                {
                    IAPInstance.OnTransactionCanceled(productID, quantity);
                }
            }
            break;

            case TransactionState.Restored:
                if (IAPVerifyTransaction(transactionID))
                {
                    if ((null != IAPInstance) && (null != IAPInstance.OnTransactionRestored))
                    {
                        IAPInstance.OnTransactionRestored(productID, quantity, transactionID, receipt);
                    }
                }
                break;

            case TransactionState.Deferred:
            {
                if ((null != IAPInstance) && (null != IAPInstance.OnTransactionDeferred))
                {
                    IAPInstance.OnTransactionDeferred(productID);
                }
            }
            break;
            }
        }
 public void UpdateStatus(long transactionId, TransactionState state)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 TRANSACTION.TRANSACTION_STATE = state.ToString();
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
 public void UpdateTransaction(long transactionId, TransactionState state, long coinSerialNumber)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 TRANSACTION.TRANSACTION_STATE = state.ToString();
                 TRANSACTION.GRITCOIN_ID       = GetOrCreateCoinId(coinSerialNumber);
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
        public IVersionedObject Add(IVersionedObject @object, bool ignoreDublicates = false)
        {
            if (_transactionState != TransactionState.Running)
            {
                throw new OperationCanceledException($"Cannot add objects when transaction state = {_transactionState.ToString() }");
            }

            if (_objectManager.GetObject(@object.Id) != null)
            {
                if (ignoreDublicates)
                {
                    return(@object);
                }
                else
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} is already present in the object manager. If you want to update an existing object, please use Update instead.");
                }
            }

            if (_addedObjects.ContainsKey(@object.Id))
            {
                if (ignoreDublicates)
                {
                    return(@object);
                }
                else
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} is already added in this transaction.");
                }
            }

            // Check if pointer to same object has been added before
            if (_objectManager._objectAdditionStates.ContainsKey(@object.Id))
            {
                var objVersions = _objectManager._objectAdditionStates[@object.Id];

                if (objVersions.Contains(@object))
                {
                    throw new OperationCanceledException($"An object with id: {@object.Id} referencing the same object already exists inside the object manager. You cannot add the same object instance twice. You need to create a new object instance everytime you add an object.");
                }
            }

            _addedObjects.Add(@object.Id, @object);

            return(@object);
        }
Beispiel #12
0
 private static Exception CreateTransitionException(TransactionState current, TransactionState requested, [CallerMemberName] string method = "")
 {
     return(new InvalidOperationException("Cannot " + method + " from " + current.ToString() + " to " + requested.ToString() + "."));
 }
 public List <TransactionModel> RetrieveTransactionByStateAndCycle(TransactionState state, long?cycleId)
 {
     if (!cycleId.HasValue)
     {
         cycleId = CurrentCycle.CycleId;
     }
     try
     {
         using (var context = new GritCoinEntities())
         {
             return(context.TRANSACTIONS.Where(TRANSACTION => TRANSACTION.TRANSACTION_STATE == state.ToString() && TRANSACTION.CYCLE_ID == cycleId).ToList().Select(
                        TRANSACTION => new TransactionModel
             {
                 TransactionId = TRANSACTION.TRANSACTION_ID,
                 CycleId = TRANSACTION.CYCLE_ID,
                 EffectiveDate = TRANSACTION.EFFECTIVE_DATE,
                 GritCoin = TRANSACTION.COINS == null ? null : new GCMS.Oracle.DataTransferObjects.GritCoinModel
                 {
                     CoinId = TRANSACTION.COINS.GRITCOIN_ID,
                     CoinNumber = TRANSACTION.COINS.SERIAL_NUMBER
                 },
                 IsAnonymous = TRANSACTION.ANONYMOUS_FLAG == "Y" ? true : false,
                 Recipient = new EmployeeModel
                 {
                     DisplayName = TRANSACTION.EMPLOYEE_RECIPIENT.DISPLAY_NAME,
                     EmployeeId = TRANSACTION.EMPLOYEE_RECIPIENT.EMPLOYEE_ID
                 },
                 Sender = new EmployeeModel
                 {
                     DisplayName = TRANSACTION.EMPLOYEE_SENDER.DISPLAY_NAME,
                     EmployeeId = TRANSACTION.EMPLOYEE_SENDER.EMPLOYEE_ID,
                 },
                 SystemChangeDate = TRANSACTION.SYSTEM_CHANGE_DATE,
                 TransactionState = (TransactionState)Enum.Parse(typeof(TransactionState), TRANSACTION.TRANSACTION_STATE),
                 Comment = TRANSACTION.NOTE,
                 FromPool = TRANSACTION.FROM_POOL_FLAG == "Y" ? true : false,
                 SpentDate = TRANSACTION.SPENT_DATE,
                 SpendComment = TRANSACTION.SPENT_NOTE
             }).ToList());
         }
     }
     catch { throw; }
 }
Beispiel #14
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var paymentProvider = (IPaymentProvider)validationContext
                                  .GetService(typeof(IPaymentProvider));
            var expectedSignature = paymentProvider.GetSignature(MerchantId.ToString(), ReferenceCode, TotalValue, Currency, TransactionState.ToString());

            if (!expectedSignature.Equals(Signature, StringComparison.OrdinalIgnoreCase))
            {
                yield return(ValidationResult.Success);
                //yield return new ValidationResult("This request is not verified by the payment provider");
            }
        }
Beispiel #15
0
        /// <summary>
        /// Commits the underlying EF transaction
        /// </summary>
        public void Complete()
        {
            switch (_transactionState)
            {
            case TransactionState.Open:
                _dbContextTransaction.Commit();
                _transactionState = TransactionState.Commited;
                break;

            case TransactionState.RolledBack:
                throw new ChildTransactionRolledBackException("Cannot complete the transaction because the transaction has already been rolled back by a child scope");

            case TransactionState.Closed:
            case TransactionState.Commited:
                throw new InvalidOperationException("Cannot complete the transaction because the transaction is already " + _transactionState.ToString().ToLower());

            default:
                throw new NotImplementedException("Unrecognised TransactionState: " + _transactionState);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Rolls back the transaction.
        /// </summary>
        /// <remarks>
        /// This is internal because it is only intended to be called by a ChildTransactionScope
        /// </remarks>
        internal void Rollback()
        {
            switch (_transactionState)
            {
            case TransactionState.Open:
                _dbContextTransaction.Rollback();
                _transactionState = TransactionState.RolledBack;
                break;

            case TransactionState.RolledBack:
                // The transaction has already been rolled back
                break;

            case TransactionState.Closed:
            case TransactionState.Commited:
                throw new InvalidOperationException("Cannot rollback the transaction because the transaction is already " + _transactionState.ToString().ToLower());

            default:
                throw new NotImplementedException("Unrecognised TransactionState: " + _transactionState);
            }
        }
Beispiel #17
0
        protected void RenderBrowserMode(ComponentController paComponentController)
        {
            String lcBase64TransactionSettingStr;
            String lcBase64SystemConfigStr;
            String lcBase64StaffPermissionStr;
            String lcBase64RegionalConfigStr;

            lcBase64SystemConfigStr       = General.Base64Encode(clSettingManager.SystemConfigStr);
            lcBase64RegionalConfigStr     = General.Base64Encode(clSettingManager.RegionalConfigStr);
            lcBase64StaffPermissionStr    = General.Base64Encode(clSettingManager.GetSettingValue(ctSETStaffPermissionSetting, "{}"));
            lcBase64TransactionSettingStr = General.Base64Encode(clSettingManager.GetSettingValue(ctSETTransactionSetting, "{}"));

            IncludeExternalLinkFiles(paComponentController);
            CreateReceiptManager();

            paComponentController.AddElementType(ComponentController.ElementType.Control);
            paComponentController.AddBareAttribute(ctSETSytemConfig, lcBase64SystemConfigStr);
            paComponentController.AddBareAttribute(ctSETRegionalConfig, lcBase64RegionalConfigStr);
            paComponentController.AddBareAttribute(ctSETTransactionSetting, lcBase64TransactionSettingStr);
            paComponentController.AddBareAttribute(ctSETStaffPermissionSetting, lcBase64StaffPermissionStr);

            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_TaxApplicable, clTaxApplicable.ToString().ToLower());
            paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_TransactionState, clTransactionState.ToString().ToLower());
            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_MultiPaymentMode, clMultiPaymentMode.ToString().ToLower());
            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_ReceiptPrintMode, clReceiptPrintMode.ToString().ToLower());

            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_AllowShortSell, General.ParseBoolean(clSettingManager.SystemConfig.GetData(ctKEYAllowShortSell), false).ToString().ToLower());
            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_TaxInclusive, clReceiptManager.ActiveRow.TaxInclusive.ToString().ToLower());
            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.gpos_TaxPercent, clReceiptManager.ActiveRow.TaxPercent.ToString());
            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.ea_LowerBound, GetLowerBoundDays().ToString());
            // paComponentController.AddElementAttribute(ComponentController.ElementAttribute.ea_UpperBound, GetUpperBoundDays().ToString());
            paComponentController.AddElementAttribute(ComponentController.ElementAttribute.ea_AdminMode, clAdminUser ? "true" : null);
            paComponentController.AddElementAttribute(ComponentController.ElementAttribute.ea_Mode, clMode.ToString().ToLower());
            paComponentController.AddElementAttribute(ComponentController.ElementAttribute.ea_DataID, clReceiptManager.ActiveRow.ReceiptID.ToString());
            paComponentController.AddElementAttribute(ComponentController.ElementAttribute.ea_Edition, clEdition.ToString().ToLower());
            paComponentController.AddAttribute(HtmlAttribute.Class, ctCLSWidControlPOSTransaction);
            paComponentController.RenderBeginTag(HtmlTag.Div);
            RenderTitleBar(paComponentController);
            RenderHeaderBar(paComponentController);
            RenderFields(paComponentController);

            RenderTransactionList(paComponentController);

            RenderKeyPad(paComponentController);

            paComponentController.RenderEndTag();

            RenderExternalComponentsContainer(paComponentController);


            // RenderPopUp(paComponentController, ctTIDReceiptDateInfo, ctIIGReceiptDateInfo);
            // RenderPopUp(paComponentController, ctTIDPaymentInfo, ctIIGPaymentInfo);
        }