예제 #1
0
        private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options)
        {
            var(path, left, error) = FunctionUtils.TryAccumulatePath(expression, state, options);

            if (error != null)
            {
                return(null, error);
            }

            if (left == null)
            {
                // fully converted to path, so we just delegate to memory scope
                return(FunctionUtils.WrapGetValue(state, path, options));
            }
            else
            {
                // stop at somewhere, so we figure out what's left
                var(newScope, err) = left.TryEvaluate(state, options);
                if (err != null)
                {
                    return(null, err);
                }

                return(FunctionUtils.WrapGetValue(MemoryFactory.Create(newScope), path, options));
            }
        }
예제 #2
0
        /// <summary>
        /// Check that the dataset built using the DataSetBuilder with default caches
        /// contains the same data as that built using the MemoryFactory
        /// </summary>
        public void DataSetBuilder_Compare()
        {
            // Arange
            string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".tmp");

            File.Copy(DataFile, tempFile);

            try
            {
                // Act
                using (IndirectDataSet fileDataset =
                           BuildDataset(
                               InitBuilder()
                               .ConfigureDefaultCaches()))
                {
                    using (DataSet memoryDataset = MemoryFactory.Create(tempFile))
                    {
                        // Assert
                        Assert.IsTrue(Utils.CompareDataSets(fileDataset, memoryDataset),
                                      "Data loaded by DataSetBuilder does not match that loaded by MemoryFactory from the same file");
                    }
                }
            }
            finally
            {
                // tidy up
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
예제 #3
0
파일: Memory.cs 프로젝트: chj853/51degrees
        public void CreateDataSet()
        {
            var start = DateTime.UtcNow;

            Utils.CheckFileExists(DataFile);
            _dataSet = MemoryFactory.Create(DataFile);
        }
 /// <summary>
 /// Validates the download for success and checks the data set can
 /// be loaded. Uses the memory factory as this validates more elements
 /// of the data file.
 /// </summary>
 /// <param name="result">Result of the download process.</param>
 private void ValidateDownload(AutoUpdate.AutoUpdateStatus result)
 {
     if (result != AutoUpdate.AutoUpdateStatus.AUTO_UPDATE_SUCCESS)
     {
         Assert.Fail(
             "Data file update process failed with status '{0}'.",
             result.ToString());
     }
     using (var dataSet = MemoryFactory.Create(TestDataFile.FullName))
     {
         if (dataSet.Name.Equals("Lite"))
         {
             Console.WriteLine("Data set name was: " + dataSet.Name);
             Assert.Fail("Data set name was 'Lite'.");
         }
     }
 }
        private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options)
        {
            object value = null;
            string error;
            object firstItem;
            object property;

            var children = expression.Children;

            (firstItem, error) = children[0].TryEvaluate(state, options);
            if (error == null)
            {
                if (children.Length == 1)
                {
                    // get root value from memory
                    if (!(firstItem is string))
                    {
                        error = $"Single parameter {children[0]} is not a string.";
                    }
                    else
                    {
                        (value, error) = FunctionUtils.WrapGetValue(state, (string)firstItem, options);
                    }
                }
                else
                {
                    // get the peoperty value from the instance
                    (property, error) = children[1].TryEvaluate(state, options);
                    if (error == null)
                    {
                        (value, error) = FunctionUtils.WrapGetValue(MemoryFactory.Create(firstItem), (string)property, options);
                    }
                }
            }

            return(value, error);
        }
        public override Task <IReadOnlyList <OnCondition> > SelectAsync(ActionContext context, CancellationToken cancellationToken = default)
        {
            var candidates = _conditionals;

            if (_evaluate)
            {
                candidates = new List <OnCondition>();
                foreach (var conditional in _conditionals)
                {
                    var expression = conditional.GetExpression();
                    var(value, error) = expression.TryEvaluate(context.State);
                    var eval = error == null && (bool)value;
                    if (eval == true)
                    {
                        candidates.Add(conditional);
                    }
                }
            }

            var result = new List <OnCondition>();

            if (candidates.Count > 0)
            {
                var memory         = MemoryFactory.Create(context.State);
                int?customizedSeed = null;
                if (Seed != -1)
                {
                    customizedSeed = Seed;
                }

                var selection = memory.RandomNext(0, candidates.Count, customizedSeed);

                result.Add(candidates[selection]);
            }

            return(Task.FromResult((IReadOnlyList <OnCondition>)result));
        }
예제 #7
0
 public void CreateDataSet()
 {
     Utils.CheckFileExists(DataFile);
     _dataSet = MemoryFactory.Create(DataFile);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomizedMemory"/> class.
 /// </summary>
 /// <param name="scope">scope.</param>
 public CustomizedMemory(object scope)
 {
     this.GlobalMemory = scope == null ? null : MemoryFactory.Create(scope);
     this.LocalMemory  = null;
 }
예제 #9
0
 public void CreateDataSet()
 {
     _memory = new Utils.MemoryMonitor();
     Utils.CheckFileExists(DataFile);
     _dataSet = MemoryFactory.Create(DataFile, true);
 }