protected override async Task Handle(DeleteSharedListItem command) { var item = await WriteService.GetAsync <SharedBookListItem>(command.ItemId); if (item == null) { throw new ObjectNotExistException <SharedBookListItem>( new OnExceptionObjectDescriptor { ["Id"] = command.ItemId.ToString() }); } var accessSpecification = new BookListAccessSpecification(item.BookList); if (!accessSpecification.SatisfiedBy(command.UserId)) { throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor { ["Id"] = item.BookListId.ToString() }); } await WriteService.DeleteAsync <SharedBookListItem>(item.Id); }
protected override async Task Handle(SharePrivateList command) { var privateList = await _privateListFetchHandler.Handle(new GetPrivateListByUserId(command.UserId)); var sharedList = CreateSharedListFromPrivate(privateList, command); var user = await WriteService.GetAsync <User>(command.UserId); var listNameSpecification = new SharedListNameSpecification(user); if (!listNameSpecification.SatisfiedBy(sharedList.Name)) { throw new ObjectAlreadyExistsException <BookList>(new OnExceptionObjectDescriptor { ["Name"] = command.Name }); } await WriteService.SaveAsync(sharedList); var privateItems = await _privateItemsFetchHandler.Handle(new GetItemsByListId(privateList.Id)); var sharedItems = CreateSharedItemsFromPrivateItems(privateItems, sharedList.Id); await WriteService.SaveBatchAsync(sharedItems); }
/* * Response: * Responses of type <nok> indicate a problem with the received Write Service request. * The response <ok> indicates the Write Service was successfully completed and the data was successfully transmitted to the requesting device. * * <write-r> ::= <nok> | <ok> * */ protected virtual byte[] OnProcessWriteService(WriteService service, byte[] data) { byte[] request = null; return(request); }
void SlaPersonenOp(List <string[]> personenLijst, string bestandsPad, string separator) { WriteService schrijfBewerking = new WriteService(); schrijfBewerking.SchrijfListVanArrays(personenLijst, bestandsPad, separator); HaalInfoOp(leesBewerking.rootPad + "Personen.txt"); }
protected override async Task <int> GetBookListId(AddSharedListItem command) { var list = await WriteService.GetAsync <BookList>(command.ListId); if (list == null) { throw new ObjectNotExistException <BookList>( new OnExceptionObjectDescriptor { ["Id"] = command.ListId.ToString() }); } var accessSpecification = new BookListAccessSpecification(list); if (!accessSpecification.SatisfiedBy(command.UserId)) { throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor { ["Id"] = command.ListId.ToString() }); } return(command.ListId); }
private void btnSaveString_Click(object sender, RoutedEventArgs e) { personen1[indexListStrings] = txtPersoon.Text; WriteService schrijfBewerking = new WriteService(); schrijfBewerking.SchrijfListVanStrings(personen1, leesBewerking.rootPad + "Personen.txt"); HaalInfoOp(leesBewerking.rootPad + "Personen.txt"); }
/// <summary> /// Get the Write async client. /// </summary> /// <param name="mapper">the converter used for mapping to PointData</param> /// <returns>the new client instance for the Write API Async without batching</returns> public WriteApiAsync GetWriteApiAsync(IDomainObjectMapper mapper = null) { var service = new WriteService((Configuration)_apiClient.Configuration) { ExceptionFactory = _exceptionFactory }; return(new WriteApiAsync(_options, service, mapper ?? new DefaultDomainObjectMapper(), this)); }
/// <summary> /// Get the Write async client. /// </summary> /// <returns>the new client instance for the Write API Async without batching</returns> public WriteApiAsync GetWriteApiAsync() { var service = new WriteService((Configuration)_apiClient.Configuration) { ExceptionFactory = _exceptionFactory }; return(new WriteApiAsync(_options, service, this)); }
public LogHandler() { var logBookEntityModel = new LogBookEntityModel(); UpdateDatabase.Execute(); _writeService = new WriteService(logBookEntityModel); _readService = new ReadService(logBookEntityModel); }
public override Action <IRabbitMqReceiveEndpointConfigurator> Configure() { var dbConnection = new WriteService(new MongoDbContext(_configuration.GetConnectionString(Constants.DefaultConnection), _configuration.GetConnectionString(Constants.DefaultDatabaseName), false)); return(e => { e.Consumer(() => new LoggingConsumer(_configuration, dbConnection)); }); }
protected internal WriteApiAsync(InfluxDBClientOptions options, WriteService service, InfluxDBClient influxDbClient) { Arguments.CheckNotNull(service, nameof(service)); Arguments.CheckNotNull(influxDbClient, nameof(_influxDbClient)); _options = options; _influxDbClient = influxDbClient; _service = service; }
public void Initialise() { var connection = Effort.DbConnectionFactory.CreateTransient(); _mockContext = new LogBookEntityModel(connection); _mockContext.Database.CreateIfNotExists(); _writeService = new WriteService(_mockContext); }
/// <summary> /// Get the Write client. /// </summary> /// <param name="writeOptions">the configuration for a write client</param> /// <returns>the new client instance for the Write API</returns> public WriteApi GetWriteApi(WriteOptions writeOptions) { var service = new WriteService((Configuration)_apiClient.Configuration) { ExceptionFactory = _exceptionFactory }; var writeApi = new WriteApi(_options, service, writeOptions, this, _disposeNotification); return(writeApi); }
/// <summary> /// Get the Write client. /// </summary> /// <param name="writeOptions">the configuration for a write client</param> /// <param name="mapper">the converter used for mapping to PointData</param> /// <returns>the new client instance for the Write API</returns> public WriteApi GetWriteApi(WriteOptions writeOptions, IDomainObjectMapper mapper = null) { var service = new WriteService((Configuration)_apiClient.Configuration) { ExceptionFactory = _exceptionFactory }; var writeApi = new WriteApi(_options, service, writeOptions, mapper ?? new DefaultDomainObjectMapper(), this, _disposeNotification); return(writeApi); }
protected sealed override async Task <TDto> Handle(TCommand command) { var entity = await GetEntity(command); await Validate(entity, command); Update(entity, command); await WriteService.SaveAsync(entity); return(Convert(entity, command)); }
private static void CommitCustomerData() { var write = new WriteService(); write.Write(_customers, @"c:\tmp\test.txt"); // Provide hook string jsonParams = JsonSerializer.Serialize(_customers); _hook.CreateHook( methodName: "After", className: "CommitCustomerData", parameters: new[] { jsonParams }); }
protected override async Task Handle(AddBookToLists command) { var lists = await _listsFetchHandler.Handle(new GetListsByIds(command.ListsIds)); var items = (await _itemsFetchHandler.Handle(new GetItemsByBookAndListIds(command.ListsIds, command.BookId))) .ToList(); var newItems = new List <BookListItem>(); foreach (var list in lists) { Validate(list, command.UserId, items, command.BookId); newItems.Add(CreateItem(list, command)); } await WriteService.SaveBatchAsync(newItems); }
public void SchrijfArtikelenNaarTextFile(string folderPad, string bestandsnaam) { List <string[]> artikelenOmgezet = new List <string[]>(); foreach (Artikel instance in Artikelen) { string prijs = instance.Prijs.ToString().Replace('.', huidigDecimaalTeken); prijs = prijs.Replace(',', huidigDecimaalTeken); string[] artikelInfo = { instance.Id.ToString(), instance.Naam, instance.Eenheid, prijs }; artikelenOmgezet.Add(artikelInfo); } WriteService.ListVanArrays_To_TextFile(artikelenOmgezet, folderPad, bestandsnaam, Separator.ToString()); }
protected sealed override async Task <TDto> Handle(TCommand command) { var listId = await GetBookListId(command); var book = await WriteService.GetAsync <Book>(command.BookId); if (await DoItemExist(command.BookId, listId)) { throw new ObjectAlreadyExistsException <TItem>(new OnExceptionObjectDescriptor { ["Author"] = book.Author, ["Title"] = book.Title }); } var item = CreateItem(book, listId); await SaveAsync(item); return(Convert(item)); }
protected override async Task <SharedBookListPreviewDto> Handle(CreateSharedList command) { var user = await WriteService.GetAsync <User>(command.UserId); if (user == null) { throw new ObjectNotExistException <User>(new OnExceptionObjectDescriptor { ["Id"] = command.UserId.ToString() }); } var listNameSpecification = new SharedListNameSpecification(user); if (!listNameSpecification.SatisfiedBy(command.Name)) { throw new ObjectAlreadyExistsException <BookList>(new OnExceptionObjectDescriptor { ["Name"] = command.Name }); } var list = new BookList { Name = command.Name, OwnerId = user.Id, Type = BookListType.Shared }; var tags = await _bookListService.ProcessTags(command.Tags, list.Id); if (tags != null) { list.SharedBookListTags = tags; } await WriteService.SaveAsync(list); return(Mapper.Map <BookList, SharedBookListPreviewDto>(list)); }
//[Fact]TODO: Fix test public async Task CreatePayment_When_CreatePaymentRequest_IsValid_Return() { var payment = new CreatePaymentRequest() { MerchantId = 123, Amount = 234.23m, Currency = "USD" }; var mockContext = new Mock <PaymentsDbContext>(); mockContext.Setup(x => x.Payments) .ReturnsDbSet(Payments); mockContext.SetupGet(x => x.Payments); var service = new WriteService(mockContext.Object); await service.CreatePayment(payment); mockContext.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())); }
protected override async Task <AuthenticationDataDto> Handle(RegisterUser command) { var user = await _userFetchHandler.Handle(new GetUserByLogin(command.Email)); if (user != null) { throw new ObjectAlreadyExistsException <User>(new OnExceptionObjectDescriptor { ["Email"] = command.Email }); } user = new User { Login = command.Email, Password = _encryptionService.Encrypt(command.Password), RoleId = (int)UserRole.User, Profile = new Profile { Email = command.Email } }; await WriteService.SaveAsync(user); await WriteService.SaveAsync(new BookList { Name = "Default", OwnerId = user.Id, Type = BookListType.Private }); if (_encryptionService.Encrypt(command.Password) != user.Password) { throw new WrongPasswordException(); } return(_authenticationService.Authenticate(user)); }
////显示最新的十个创作 public static DataTable top10write() { return(WriteService.top10write()); }
//查看所有创做的信息 public static DataTable allwrite() { return(WriteService.allwrite()); }
protected internal WriteApi(InfluxDBClientOptions options, WriteService service, WriteOptions writeOptions, InfluxDBClient influxDbClient) { Arguments.CheckNotNull(service, nameof(service)); Arguments.CheckNotNull(writeOptions, nameof(writeOptions)); Arguments.CheckNotNull(influxDbClient, nameof(_influxDbClient)); _options = options; _influxDbClient = influxDbClient; // backpreasure - is not implemented in C# // // => use unbound buffer // // https://github.com/dotnet/reactive/issues/19 var observable = _subject.ObserveOn(writeOptions.WriteScheduler); var boundary = observable .Buffer(TimeSpan.FromMilliseconds(writeOptions.FlushInterval), writeOptions.BatchSize, writeOptions.WriteScheduler) .Merge(_flush); observable // // Batching // .Window(boundary) // // Group by key - same bucket, same org // .SelectMany(it => it.GroupBy(batchWrite => batchWrite.Options)) // // Create Write Point = bucket, org, ... + data // .Select(grouped => { var aggregate = grouped .Aggregate(new StringBuilder(""), (builder, batchWrite) => { var data = batchWrite.ToLineProtocol(); if (string.IsNullOrEmpty(data)) { return(builder); } if (builder.Length > 0) { builder.Append("\n"); } return(builder.Append(data)); }).Select(builder => builder.ToString()); return(aggregate.Select(records => new BatchWriteRecord(grouped.Key, records))); }) // // Jitter // .Select(source => { if (writeOptions.JitterInterval <= 0) { return(source); } return(source.Delay(_ => Observable.Timer(TimeSpan.FromMilliseconds(JitterDelay(writeOptions)), Scheduler.CurrentThread))); }) .Concat() // // Map to Async request // .Where(batchWriteItem => !string.IsNullOrEmpty(batchWriteItem.ToLineProtocol())) .Select(batchWriteItem => { var org = batchWriteItem.Options.OrganizationId; var bucket = batchWriteItem.Options.Bucket; var lineProtocol = batchWriteItem.ToLineProtocol(); var precision = batchWriteItem.Options.Precision; return(Observable .Defer(() => service.PostWriteAsyncWithIRestResponse(org, bucket, Encoding.UTF8.GetBytes(lineProtocol), null, "identity", "text/plain; charset=utf-8", null, "application/json", null, precision) .ToObservable()) .RetryWhen(f => f.SelectMany(e => { if (e is HttpException httpException) { // // This types is not able to retry // if (httpException.Status != 429 && httpException.Status != 503) { throw httpException; } var retryInterval = (httpException.RetryAfter * 1000 ?? writeOptions.RetryInterval) + JitterDelay(writeOptions); var retryable = new WriteRetriableErrorEvent(org, bucket, precision, lineProtocol, httpException, retryInterval); Publish(retryable); return Observable.Timer(TimeSpan.FromMilliseconds(retryInterval)); } throw e; })) .Select(result => { // ReSharper disable once ConvertIfStatementToReturnStatement if (result.IsSuccessful) { return Notification.CreateOnNext(result); } return Notification.CreateOnError <IRestResponse>(HttpException.Create(result)); }) .Catch <Notification <IRestResponse>, Exception>(ex => { var error = new WriteErrorEvent(org, bucket, precision, lineProtocol, ex); Publish(error); return Observable.Return(Notification.CreateOnError <IRestResponse>(ex)); }).Do(res => { if (res.Kind == NotificationKind.OnNext) { var success = new WriteSuccessEvent(org, bucket, precision, lineProtocol); Publish(success); } })); }) .Concat() .Subscribe( notification => { switch (notification.Kind) { case NotificationKind.OnNext: Trace.WriteLine($"The batch item: {notification} was processed successfully."); break; case NotificationKind.OnError: Trace.WriteLine( $"The batch item wasn't processed successfully because: {notification.Exception}"); break; default: Trace.WriteLine($"The batch item: {notification} was processed"); break; } }, exception => Trace.WriteLine($"The unhandled exception occurs: {exception}"), () => Trace.WriteLine("The WriteApi was disposed.")); }
//管理员删除创作 public static int delete(string wriname) { return(WriteService.delete(wriname)); }
protected override async Task SaveAsync(PrivateBookListItem item) { await WriteService.SaveAsync(item); }
//好像没有用到的一个方法 public static DataTable Swirid(int wriid) { return(WriteService.Swriid(wriid)); }
protected internal WriteApi( InfluxDBClientOptions options, WriteService service, WriteOptions writeOptions, IDomainObjectMapper mapper, InfluxDBClient influxDbClient, IObservable <Unit> disposeCommand) { Arguments.CheckNotNull(service, nameof(service)); Arguments.CheckNotNull(writeOptions, nameof(writeOptions)); Arguments.CheckNotNull(mapper, nameof(mapper)); Arguments.CheckNotNull(influxDbClient, nameof(_influxDbClient)); Arguments.CheckNotNull(disposeCommand, nameof(disposeCommand)); _options = options; _mapper = mapper; _influxDbClient = influxDbClient; _unsubscribeDisposeCommand = disposeCommand.Subscribe(_ => Dispose()); // backpreasure - is not implemented in C# // // => use unbound buffer // // https://github.com/dotnet/reactive/issues/19 IObservable <IObservable <BatchWriteRecord> > batches = _subject // // Batching // .Publish(connectedSource => { var trigger = Observable.Merge( // triggered by time & count connectedSource.Window(TimeSpan.FromMilliseconds( writeOptions.FlushInterval), writeOptions.BatchSize, writeOptions.WriteScheduler), // flush trigger _flush ); return(connectedSource .Window(trigger)); }) // // Group by key - same bucket, same org // .SelectMany(it => it.GroupBy(batchWrite => batchWrite.Options)) // // Create Write Point = bucket, org, ... + data // .Select(grouped => { var aggregate = grouped .Aggregate(_stringBuilderPool.Get(), (builder, batchWrite) => { var data = batchWrite.ToLineProtocol(); if (string.IsNullOrEmpty(data)) { return(builder); } if (builder.Length > 0) { builder.Append("\n"); } return(builder.Append(data)); }).Select(builder => { var result = builder.ToString(); builder.Clear(); _stringBuilderPool.Return(builder); return(result); }); return(aggregate.Select(records => new BatchWriteRecord(grouped.Key, records)) .Where(batchWriteItem => !string.IsNullOrEmpty(batchWriteItem.ToLineProtocol()))); }); if (writeOptions.JitterInterval > 0) { batches = batches // // Jitter // .Select(source => { return(source.Delay(_ => Observable.Timer(TimeSpan.FromMilliseconds(RetryAttempt.JitterDelay(writeOptions)), writeOptions.WriteScheduler))); }); } var query = batches .Concat() // // Map to Async request // .Select(batchWriteItem => { var org = batchWriteItem.Options.OrganizationId; var bucket = batchWriteItem.Options.Bucket; var lineProtocol = batchWriteItem.ToLineProtocol(); var precision = batchWriteItem.Options.Precision; return(Observable .Defer(() => service.PostWriteAsyncWithIRestResponse(org, bucket, Encoding.UTF8.GetBytes(lineProtocol), null, "identity", "text/plain; charset=utf-8", null, "application/json", null, precision) .ToObservable()) .RetryWhen(f => f .Zip(Observable.Range(1, writeOptions.MaxRetries + 1), (exception, count) => new RetryAttempt(exception, count, writeOptions)) .SelectMany(attempt => { if (attempt.IsRetry()) { var retryInterval = attempt.GetRetryInterval(); var retryable = new WriteRetriableErrorEvent(org, bucket, precision, lineProtocol, attempt.Error, retryInterval); Publish(retryable); return Observable.Timer(TimeSpan.FromMilliseconds(retryInterval), writeOptions.WriteScheduler); } throw attempt.Error; })) .Select(result => { // ReSharper disable once ConvertIfStatementToReturnStatement if (result.IsSuccessful) { return Notification.CreateOnNext(result); } return Notification.CreateOnError <IRestResponse>(HttpException.Create(result, result.Content)); }) .Catch <Notification <IRestResponse>, Exception>(ex => { var error = new WriteErrorEvent(org, bucket, precision, lineProtocol, ex); Publish(error); return Observable.Return(Notification.CreateOnError <IRestResponse>(ex)); }).Do(res => { if (res.Kind == NotificationKind.OnNext) { var success = new WriteSuccessEvent(org, bucket, precision, lineProtocol); Publish(success); } })); }) .Concat() .Subscribe( notification => { switch (notification.Kind) { case NotificationKind.OnNext: Trace.WriteLine($"The batch item: {notification} was processed successfully."); break; case NotificationKind.OnError: Trace.WriteLine( $"The batch item wasn't processed successfully because: {notification.Exception}"); break; default: Trace.WriteLine($"The batch item: {notification} was processed"); break; } }, exception => { _disposed = true; Trace.WriteLine($"The unhandled exception occurs: {exception}"); }, () => { _disposed = true; Trace.WriteLine("The WriteApi was disposed."); }); }
////根据用户id删除创作 public static int deletwri(int user_id) { return(WriteService.deletwri(user_id)); }