/// <summary> /// Initializes a new instance of the <see cref="ProcessSharp" /> class. /// </summary> /// <param name="native">The native process.</param> /// <param name="type">The type of memory being manipulated.</param> public ProcessSharp(Process native, MemoryType type) { native.EnableRaisingEvents = true; native.Exited += (s, e) => { ProcessExited?.Invoke(s, e); HandleProcessExiting(); }; Native = native; Handle = MemoryHelper.OpenProcess(ProcessAccessFlags.AllAccess, Native.Id); switch (type) { case MemoryType.Local: Memory = new LocalProcessMemory(Handle); break; case MemoryType.Remote: Memory = new ExternalProcessMemory(Handle); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } native.ErrorDataReceived += OutputDataReceived; native.OutputDataReceived += OutputDataReceived; ThreadFactory = new ThreadFactory(this); ModuleFactory = new ModuleFactory(this); MemoryFactory = new MemoryFactory(this); WindowFactory = new WindowFactory(this); }
/// <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); } } }
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)); } }
public void MemoryCacheFactory() { var factory = new MemoryFactory(new Dictionary <string, string> { { "expiration-scan-frequency", "00:10:00" }, { "size-limit", "1048576" } }); Assert.That(factory, Is.Not.Null, "Factory not found"); Assert.That(factory, Is.InstanceOf <MemoryFactory>(), "Unexpected factory"); var cache1 = factory.BuildCache(); Assert.That(cache1, Is.Not.Null, "Factory has yielded null"); Assert.That(cache1, Is.InstanceOf <MemoryDistributedCache>(), "Unexpected cache"); var cache2 = factory.BuildCache(); Assert.That(cache2, Is.EqualTo(cache1), "The distributed cache factory is supposed to always yield the same instance"); var memCache = MemoryCacheField.GetValue(cache1); Assert.That(memCache, Is.Not.Null, "Underlying memory cache not found"); Assert.That(memCache, Is.InstanceOf <MemoryCache>(), "Unexpected memory cache"); var options = MemoryCacheOptionsField.GetValue(memCache); Assert.That(options, Is.Not.Null, "Memory cache options not found"); Assert.That(options, Is.InstanceOf <MemoryCacheOptions>(), "Unexpected options type"); var memOptions = (MemoryCacheOptions)options; Assert.That(memOptions.ExpirationScanFrequency, Is.EqualTo(TimeSpan.FromMinutes(10))); Assert.That(memOptions.SizeLimit, Is.EqualTo(1048576)); }
public void CreateDataSet() { var start = DateTime.UtcNow; Utils.CheckFileExists(DataFile); _dataSet = MemoryFactory.Create(DataFile); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> public virtual void Dispose() { ThreadFactory.Dispose(); ModuleFactory.Dispose(); MemoryFactory.Dispose(); WindowFactory.Dispose(); Handle.Close(); GC.SuppressFinalize(this); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> public virtual void Dispose() { if (!IsDisposed) { IsDisposed = true; OnDispose?.Invoke(this, EventArgs.Empty); ThreadFactory?.Dispose(); ModuleFactory?.Dispose(); MemoryFactory?.Dispose(); WindowFactory?.Dispose(); Handle?.Close(); GC.SuppressFinalize(this); } }
/// <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'."); } } }
/// <summary> /// Initializes a new instance of the <see cref="ProcessSharp" /> class. /// </summary> /// <param name="native">The native process.</param> public ProcessSharp(System.Diagnostics.Process native) { native.EnableRaisingEvents = true; native.Exited += (s, e) => { ProcessExited?.Invoke(s, e); HandleProcessExiting(); }; Native = native; Handle = MemoryHelper.OpenProcess(ProcessAccessFlags.AllAccess, Native.Id); native.ErrorDataReceived += OutputDataReceived; native.OutputDataReceived += OutputDataReceived; ThreadFactory = new ThreadFactory(this); ModuleFactory = new ModuleFactory(this); MemoryFactory = new MemoryFactory(this); WindowFactory = new WindowFactory(this); }
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)); }
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; }
public void CreateDataSet() { _memory = new Utils.MemoryMonitor(); Utils.CheckFileExists(DataFile); _dataSet = MemoryFactory.Create(DataFile, true); }