public static Task <int> Main(string[] args) { var command = new RootCommand() { Description = "Developer tool to update the Visual Studio project versions." }; command.AddCommand(ListCommand.Create()); command.AddCommand(MajorCommand.Create()); command.AddCommand(MinorCommand.Create()); command.AddCommand(PatchCommand.Create()); command.AddCommand(BuildCommand.Create()); command.AddCommand(PreCommand.Create()); command.AddCommand(SetCommand.Create()); var builder = new CommandLineBuilder(command) .UseHelp() .UseDefaults() .UseVersionOption() .CancelOnProcessTermination() .UseExceptionHandler(); var parser = builder.Build(); return(parser.InvokeAsync(args)); }
public async Task ExecuteAsync_MultiPartRouteWithBodyFromFile_VerifyResponse() { string filePath = "someFilePath.txt"; string fileContents = "This is a test response from a PATCH: \"Test Patch Body From File\""; ArrangeInputs(commandText: $"PATCH --file " + filePath, baseAddress: _baseAddress, path: _testPath, urlsWithResponse: _urlsWithResponse, out MockedShellState shellState, out HttpState httpState, out ICoreParseResult parseResult, out MockedFileSystem fileSystem, out IPreferences preferences, readBodyFromFile: true, fileContents: fileContents); fileSystem.AddFile(filePath, "Test Patch Body From File"); PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); List <string> result = shellState.Output; Assert.Equal(2, result.Count); Assert.Contains("HTTP/1.1 200 OK", result); Assert.Contains(fileContents, result); }
/// <summary> /// Applies the delta file to an outdated version to update it. /// </summary> /// <returns>The patch.</returns> /// <param name="oldFilePath">Old file path.</param> /// <param name="deltaFilePath">Delta file path.</param> /// <param name="outputFilePath">Output file path(new file).</param> public string applyPatch(string oldFilePath, string deltaFilePath, string outputFilePath = "") { curProcessDone = false; try { if (string.IsNullOrEmpty(outputFilePath) == true) //generate save location { outputFilePath = oldFilePath; } outputFilePath = outputFilePath.Trim(); //remove line endings outputFilePath = outputFilePath + ".new"; //append a .new as to not get errors with existing files //Usage: Octodiff.exe patch <basis-file> <delta-file> <new-file> [<options>] string[] commands = { oldFilePath, deltaFilePath, outputFilePath }; //add correct arguments for patching PatchCommand command = new PatchCommand(); command.Execute(commands); //apply the patch to the file } catch (Exception ex) { currentProcess = ""; currentException = ex.Message; curProcessDone = true; return(ex.Message); } currentProcess = ""; curProcessDone = true; return("Success"); }
public PatchHeader(uint index, uint address, int length, PatchCommand command, PatchFlags flags) { Index = index; Address = address; Length = length; Command = command; Flags = flags; }
public HttpResponseMessage PatchFile(Guid userId, Guid fileId, [FromUri] Guid version, [FromBody] JsonPatchDocument <Core.File> model, [FromHeader(Name = "opensheets-bypass-level")] Level bypassLevel = Level.Information) { if (bypassLevel > Level.Warning && (Level)Context.Principal.Metadata["Allowed-Bypass"] < bypassLevel) { return(Request.CreateResponse(HttpStatusCode.Forbidden, new { Reason = $"Attempted to bypass validation of {bypassLevel} level, only allowed { (Level?)Context.Principal.Metadata["Allowed-Bypass"] ?? Level.Warning }" })); } GetResponse <Core.File> response = _router.Query <GetFileByIdRequest, GetResponse <Core.File> >(new GetFileByIdRequest() { FileId = fileId, OwnerId = userId }); if (response.Result == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } CheckPermissionResponse permissionResponse = _router.Query <CheckPermissionRequest, CheckPermissionResponse>(new CheckPermissionRequest() { IdentityId = Context.Identity.Id, OwnerId = userId, FileId = fileId }); bool canWrite = false; if (!permissionResponse.EffectivePermissions.TryGetValue(FilePermissionAction.Write, out canWrite) || !canWrite) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } if (response.Result.Version != version) { return(Request.CreateResponse(HttpStatusCode.Conflict)); } ValidatePatchResponse validateResp = _router.Query <ValidatePatchRequest <Core.File>, ValidatePatchResponse>(new ValidatePatchRequest <Core.File>() { ObjectId = fileId, ProposedPatch = model }); if (validateResp.Results.Any(x => x.Level > bypassLevel)) { return(Request.CreateResponse((HttpStatusCode)422, new { Validation = new { Errors = validateResp.Results } })); } PatchCommand <Core.File> request = new PatchCommand <Core.File>() { NewVersion = Guid.NewGuid(), Patch = model }; _router.Command(request); return(Request.CreateResponse(HttpStatusCode.OK, new { Version = request.NewVersion })); }
public static Task <Result> Patch(this IProvider provider, PatchCommand command) { // TODO: Revisit this... var remotePatch = provider as ISupportPatching; if (remotePatch != null) { return(remotePatch.Patch(command)); } return(command.RunLocal(provider)); }
/// <summary> /// Recalls the async. /// </summary> /// <returns>The async.</returns> /// <param name="message">Message.</param> public Task <AVIMRecalledMessage> RecallAsync(IAVIMMessage message) { var tcs = new TaskCompletionSource <AVIMRecalledMessage>(); var patchCmd = new PatchCommand().Recall(message); RunCommandAsync(patchCmd) .OnSuccess(t => { var recalledMsg = new AVIMRecalledMessage(); AVIMMessage.CopyMetaData(message, recalledMsg); tcs.SetResult(recalledMsg); }); return(tcs.Task); }
public override void Command(PatchCommand <Identity> request, IServiceRouter router, RequestContext context) { Identity identity = _storage.GetIdentityById(request.ObjectId); request.Patch.ApplyTo(identity); _storage.SaveIdentity(identity, request.NewVersion); router.Push <IdentityUpdatedEvent>(evt => { evt.IdentityId = identity.Id; evt.NewVersion = request.NewVersion; evt.OldVersion = identity.Version; }); }
public HttpResponseMessage PatchIdentity(Guid identityId, Guid version, [FromBody] JsonPatchDocument <Identity> model, [FromUri] Level bypassLevel = Level.Information) { if (bypassLevel > Level.Warning && (Level)Context.Principal.Metadata["Allowed-Bypass"] < bypassLevel) { return(Request.CreateResponse(HttpStatusCode.Forbidden, new { Reason = $"Attempted to bypass validation of {bypassLevel} level, only allowed { (Level?)Context.Principal.Metadata["Allowed-Bypass"] ?? Level.Warning }" })); } if (identityId == Guid.Empty) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } GetResponse <Identity> response = _router.Query <GetIdentityByIdRequest, GetResponse <Identity> >(new GetIdentityByIdRequest() { IdentityId = identityId }); if (response.Result == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (response.Result.Version != version) { return(Request.CreateResponse(HttpStatusCode.Conflict)); } ValidatePatchResponse validateResp = _router.Query <ValidatePatchRequest <Identity>, ValidatePatchResponse>(new ValidatePatchRequest <Identity>() { ObjectId = identityId, ProposedPatch = model }); if (validateResp.Results.Any(x => x.Level > bypassLevel)) { return(Request.CreateResponse((HttpStatusCode)422, new { Validation = new { Errors = validateResp.Results } })); } PatchCommand <Identity> request = new PatchCommand <Identity>() { NewVersion = Guid.NewGuid(), Patch = model }; _router.Command(request); return(Request.CreateResponse(HttpStatusCode.OK, new { Version = request.NewVersion })); }
internal async Task RecallMessage(string convId, LCIMMessage message) { PatchCommand patch = new PatchCommand(); PatchItem item = new PatchItem { Cid = convId, Mid = message.Id, From = Client.Id, Recall = true, Timestamp = message.SentTimestamp, PatchTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), }; patch.Patches.Add(item); GenericCommand request = NewCommand(CommandType.Patch, OpType.Modify); request.PatchMessage = patch; await Connection.SendRequest(request); }
public async Task ChangePatchVersionTest() { using (var fs = new DisposableFileSystem()) { fs.CreateFile("MySolution.sln"); fs.CreateFolder("src/Services"); fs.CreateFile("src/Services/project1.csproj", ProjectHelper.SetVersion("1.5.1")); var store = new ProjectStore(); var command = new PatchCommand(GitHelper.CreateDefaultGitMock().Object); var context = new CommandContext(_console, Verbosity.Info); context.Directory = fs.RootPath; await command.ExecuteAsync(context); var project = store.Read(PathHelper.GetFile(fs, "src/Services/project1.csproj")); Assert.Equal("1.5.2", project.Version); } }
public async Task ExecuteAsync_WithNoBasePath_VerifyError() { ArrangeInputs(commandText: "PATCH", baseAddress: null, path: null, urlsWithResponse: null, out MockedShellState shellState, out HttpState httpState, out ICoreParseResult parseResult, out MockedFileSystem fileSystem, out IPreferences preferences); string expectedErrorMessage = Strings.Error_NoBasePath.SetColor(httpState.ErrorColor); PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); Assert.Equal(expectedErrorMessage, shellState.ErrorMessage); }
/// <summary> /// Modifies the aysnc. /// </summary> /// <returns>The aysnc.</returns> /// <param name="oldMessage">要修改的消息对象</param> /// <param name="newMessage">新的消息对象</param> public Task <IAVIMMessage> UpdateAsync(IAVIMMessage oldMessage, IAVIMMessage newMessage) { var tcs = new TaskCompletionSource <IAVIMMessage>(); var patchCmd = new PatchCommand().Modify(oldMessage, newMessage); this.RunCommandAsync(patchCmd) .OnSuccess(t => { // 从旧消息对象中拷贝数据 AVIMMessage.CopyMetaData(oldMessage, newMessage); // 获取更新时间戳 var response = t.Result.Item2; if (response.TryGetValue("lastPatchTime", out object updatedAtObj) && long.TryParse(updatedAtObj.ToString(), out long updatedAt)) { newMessage.UpdatedAt = updatedAt; } tcs.SetResult(newMessage); }); return(tcs.Task); }
public async Task <IHttpActionResult> Patch([FromBody] Book book) { if (book == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest()); } var command = new PatchCommand() { Book = book }; await command.Execute(); return(Ok()); }
public async Task ExecuteAsync_MultiPartRouteWithInlineContent_VerifyResponse() { ArrangeInputs(commandText: "PATCH --content \"Test Patch Body\"", baseAddress: _baseAddress, path: _testPath, urlsWithResponse: _urlsWithResponse, out MockedShellState shellState, out HttpState httpState, out ICoreParseResult parseResult, out MockedFileSystem fileSystem, out IPreferences preferences); PatchCommand patchCommand = new PatchCommand(fileSystem, preferences); await patchCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None); string expectedResponse = "This is a test response from a PATCH: \"Test Patch Body\""; List <string> result = shellState.Output; Assert.Equal(2, result.Count); Assert.Contains("HTTP/1.1 200 OK", result); Assert.Contains(expectedResponse, result); }
public async Task AddFileTest() { using (var fs = new DisposableFileSystem()) { fs.CreateFile("MySolution.sln"); fs.CreateFolder("src/Services"); fs.CreateFile("src/Services/project1.csproj", ProjectHelper.SetVersion("1.5.1")); var store = new ProjectStore(); var gitMock = GitHelper.CreateGitMock(true); var command = new PatchCommand(gitMock.Object); var context = new CommandContext(_console, Verbosity.Info); context.Add = true; context.Directory = fs.RootPath; context.Message = "test"; await command.ExecuteAsync(context); gitMock.Verify(git => git.IsInstalled()); gitMock.Verify(git => git.RunCommandAsync(It.IsAny <CommandContext>(), It.Is <string>(args => args.Equals("add --all")))); gitMock.Verify(git => git.RunCommandAsync(It.IsAny <CommandContext>(), It.Is <string>(args => args.Equals("commit -a -m \"test\"")))); } }
private async Task OnMessagePatched(GenericCommand notification) { PatchCommand patchMessage = notification.PatchMessage; foreach (PatchItem patch in patchMessage.Patches) { // 获取对话 LCIMConversation conversation = await Client.GetOrQueryConversation(patch.Cid); LCIMMessage message; if (patch.HasBinaryMsg) { byte[] bytes = patch.BinaryMsg.ToByteArray(); message = LCIMBinaryMessage.Deserialize(bytes); } else { message = LCIMTypedMessage.Deserialize(patch.Data); } message.ConversationId = patch.Cid; message.Id = patch.Mid; message.FromClientId = patch.From; message.SentTimestamp = patch.Timestamp; message.PatchedTimestamp = patch.PatchTimestamp; if (message is LCIMRecalledMessage recalledMessage) { // 消息撤回 Client.OnMessageRecalled?.Invoke(conversation, recalledMessage); } else { // 消息修改 Client.OnMessageUpdated?.Invoke(conversation, message); } } }
public MainViewViewModel(IUserDialogs userDialogs, IDotaClientDistancePatcher distancePatcher, SettingsViewModel settingsViewModel, IScreen hostScreen) { SettingsViewModel = settingsViewModel; HostScreen = hostScreen; var pathCanExecute = this.WhenAnyValue( model => model.SettingsViewModel.Settings.Value.X32Client.Distance.Value, model => model.SettingsViewModel.Settings.Value.X64Client.Distance.Value, (x32, x64) => new[] { x32, x64 }) .Select(items => items.All(value => value >= 1000 && value <= 9999)); PatchCommand = ReactiveCommand.CreateFromTask <Settings>(distancePatcher.PatchAsync, pathCanExecute); PatchCommand .SubscribeOnUIDispatcher() .Subscribe(_ => { userDialogs.Alert("Done!"); }); PatchCommand.ThrownExceptions .SubscribeOnUIDispatcher() .Subscribe(exception => userDialogs.Alert("Error occurred!")); }
internal async Task UpdateMessage(string convId, LCIMMessage oldMessage, LCIMMessage newMessage) { PatchCommand patch = new PatchCommand(); PatchItem item = new PatchItem { Cid = convId, Mid = oldMessage.Id, From = Client.Id, Recall = false, Timestamp = oldMessage.SentTimestamp, PatchTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), }; if (newMessage is LCIMTypedMessage typedMessage) { item.Data = JsonConvert.SerializeObject(typedMessage.Encode()); } else if (newMessage is LCIMBinaryMessage binaryMessage) { item.BinaryMsg = ByteString.CopyFrom(binaryMessage.Data); } if (newMessage.MentionIdList != null) { item.MentionPids.AddRange(newMessage.MentionIdList); } if (newMessage.MentionAll) { item.MentionAll = newMessage.MentionAll; } patch.Patches.Add(item); GenericCommand request = NewCommand(CommandType.Patch, OpType.Modify); request.PatchMessage = patch; GenericCommand response = await Connection.SendRequest(request); }
public Task ReplaceAsync(IAVIMMessage oldMessage, IAVIMMessage newMessage) { var patchCmd = new PatchCommand().Modify(oldMessage, newMessage); return(this.LinkedRealtime.RunCommandAsync(patchCmd)); }
public Task RecallAsync(IAVIMMessage message) { var patchCmd = new PatchCommand().Recall(message); return(this.LinkedRealtime.RunCommandAsync(patchCmd)); }
public Task <Result> Visit(PatchCommand patchCommand) { throw new NotImplementedException(); }
public System.Threading.Tasks.Task <Result> Visit(PatchCommand patchCommand) { throw new NotImplementedException(); }