コード例 #1
0
        public static JournalQueryResponseItem ToResponse(this PersistenceItem persistenceItem)
        {
            if (persistenceItem == null)
            {
                throw new ArgumentNullException(nameof(persistenceItem));
            }

            var retVal = new JournalQueryResponseItem {
                Operation = persistenceItem.Name,
                Date      = persistenceItem.TimeStamp
            };

            switch (persistenceItem.Name)
            {
            case CalculatorServiceConstants.AddOperation:
                retVal.Calculation = $"{string.Join(" + ", persistenceItem.Values)} = {persistenceItem.Result}";
                break;

            case CalculatorServiceConstants.DivOperation:
                retVal.Calculation = $"{persistenceItem.Values[0]} / {persistenceItem.Values[1]} = {persistenceItem.Result}";
                break;

            case CalculatorServiceConstants.MultOperation:
                retVal.Calculation = $"{string.Join(" * ", persistenceItem.Values)} = {persistenceItem.Result}";
                break;

            case CalculatorServiceConstants.SqrtOperation:
                retVal.Calculation = $"x ^ {persistenceItem.Values[0]} = {persistenceItem.Result}";
                break;

            case CalculatorServiceConstants.SubOperation:
                retVal.Calculation = $"{persistenceItem.Values[0]} - {persistenceItem.Values[1]} = {persistenceItem.Result}";
                break;
            }

            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Stores a operation on the cache
        /// </summary>
        /// <param name="name">Operation name</param>
        /// <param name="values">Array of values</param>
        /// <param name="result">Operation result</param>
        public void SaveOperation(string trackingID, string name, int[] values, object result)
        {
            var operation = new PersistenceItem(trackingID, name, values, result);

            _cache.Enqueue(operation);
        }