public AsyncCompletedEventHandler AsyncCompletedEventHandler(PatchModel patch) { return(new AsyncCompletedEventHandler((sender, e) => { Invoke(new MethodInvoker(delegate() { downloadTimer.Stop(); if (e.Error == null) { if (e.Cancelled) { } else { var text = app.Language.Text.UIComponent; for (var i = 0; i < app.ui.Messages.Count; i++) { Messages[i].Add(new MessagesModel($"{app.Language.Get(i).UIComponent.Downloaded} {patch.FileName} - {app.Language.Get(i).UIComponent.Lbl_report_unit2} {app.SizeToString(patch.Size)}", StateCode.Downloaded)); } UpdateMsg(); for (var i = 0; i < app.ui.Messages.Count; i++) { Messages[i].Add(new MessagesModel($"{app.Language.Get(i).UIComponent.Installing} {patch.FileName}...", StateCode.Extracting)); } UpdateMsg(); UpdateProgres(100, app.GetTotalPercentage()); ShowReport(); } } })); })); }
public void read(object root_json) { IDictionary pmodels_json = (IDictionary)root_json; IDictionary reference_json = (IDictionary)pmodels_json ["reference"]; reference = new Mat((int)(long)reference_json ["rows"], (int)(long)reference_json ["cols"], CvType.CV_32F); // Debug.Log ("reference " + reference.ToString ()); IList data_json = (IList)reference_json ["data"]; float[] data = new float[reference.rows() * reference.cols()]; for (int i = 0; i < data_json.Count; i++) { data [i] = (float)(double)data_json [i]; } reference.put(0, 0, data); // Debug.Log ("reference dump " + reference.dump ()); int n = (int)(long)pmodels_json ["n_patches"]; patches = new List <PatchModel> (n); for (int i = 0; i < n; i++) { PatchModel patchModel = new PatchModel(); patchModel.read(pmodels_json ["patch " + i]); patches.Add(patchModel); } }
public ActionResult Save(PatchModel model) { if (model.Id == 0) { //create Patch p = PatchModelHelper.ConvertTo(model); PatchManager patchManager = new PatchManager(); patchManager.Create(p); return(RedirectToAction("Index", "Patch")); } else { //update Patch p = PatchModelHelper.ConvertTo(model); PatchManager patchManager = new PatchManager(); Patch patch = patchManager.Get(p.Id); if (patch != null) { patch.Height = p.Height; patch.Width = p.Width; patch.NutrientClaim = p.NutrientClaim; patch.LocationType = p.LocationType; patch.Name = p.Name; patch.Description = p.Description; patchManager.Update(patch); } } return(View("PatchEdit", model)); }
public async Task DownloadFilesAysnc(Uri url, string savePath, PatchModel patch) { app.UpdateState(StateCode.Downloading); try { client = new WebClient(); client.DownloadProgressChanged += app.ui.DownloadPatchProgressChangedHandler(patch); client.DownloadFileCompleted += app.ui.AsyncCompletedEventHandler(patch); // Add Multiple languages. for (var i = 0; i < app.ui.Messages.Count; i++) { app.ui.Messages[i].Add(new MessagesModel($"{app.Language.Get(i).UIComponent.Downloading} {patch.FileName}...", StateCode.Downloading)); } app.ui.UpdateMsg(); Stopwatch timer = app.ui.GetDownloadTimer(); timer.Restart(); timer.Start(); await client.DownloadFileTaskAsync(url, savePath); client.Dispose(); } catch (Exception ex) { Console.WriteLine($"*************FileDownloadController.DownloadFilesAysnc(Uri url, string savePath, PatchModel patch): {ex.Message}"); // Add Multiple languages. for (var i = 0; i < app.ui.Messages.Count; i++) { app.ui.Messages[i].Add(new MessagesModel($"{app.Language.Get(i).UIComponent.DownloadFailed} {patch.FileName}", StateCode.ErrorConnectingFail)); } app.ui.UpdateMsg(); app.UpdateState(StateCode.FailedToDownload); throw new FileDownloadException(); } }
public Result Patch(string collectionName, string key, PatchModel item) { if (item == null) { throw new ArgumentNullException("item", "item cannot be null"); } List <PatchModel> patches = new List <PatchModel>(); patches.Add(item); var json = JsonConvert.SerializeObject(patches); var url = UrlBase + collectionName + "/" + key; var baseResult = Communication.CallWebRequest(_apiKey, url, "PATCH", json); return(new Result { Path = new OrchestratePath { Collection = collectionName, Key = key, Ref = baseResult.ETag }, Score = 1, Value = baseResult.Payload }); }
public async Task Unzip(string fileName, string targetDir, PatchModel patch) { var text = app.Language.Text.UIComponent; try { using (var zip = ZipFile.Read(fileName)) { zip.ExtractProgress += app.ui.ExtractProgress(patch); app.UpdateState(StateCode.Extracting); patch.NoOfZippedFiles = zip.Count; foreach (var entry in zip) { if (app.cts.IsCancellationRequested) { app.cts.Token.ThrowIfCancellationRequested(); } try { patch.NoOfUnZippedFiles++; await Task.Run(() => entry.Extract(targetDir, ExtractExistingFileAction.OverwriteSilently)); patch.SizeOfUnzippedFiles += entry.UncompressedSize; patch.SizeOfZippedFiles += entry.CompressedSize; } catch (Exception ex) { Console.WriteLine($"*************1 ZipController.Unzip(string fileName, string targetDir, PatchModel patch) {ex.Message}"); app.UpdateState(StateCode.ErrorExtractingFail); for (var i = 0; i < app.ui.Messages.Count; i++) { app.ui.Messages[i].Add(new MessagesModel($"{app.Language.Get(i).UIComponent.InstallFailed} {entry.FileName}", StateCode.ErrorExtractingFail)); } app.ui.UpdateMsg(); } } for (var i = 0; i < app.ui.Messages.Count; i++) { app.ui.Messages[i].Add(new MessagesModel($"{app.Language.Get(i).UIComponent.IntalledPatch} {patch.FileName} - {app.Language.Get(i).UIComponent.Lbl_report_unit2} {app.SizeToString(patch.Size)}", StateCode.Extracted)); } ; app.ui.UpdateMsg(); patch.IsUnzipSucceed = true; await app.DeleteTempFile(patch.FileName); if (++noOfUnzipped == app.Setting.PatchList.Count) { app.ui.CompeteUpdating(); } app.UpdateLocalPatchVersion(patch); } } catch (Exception ex) { Console.WriteLine($"*************2 ZipController.Unzip(string fileName, string targetDir, PatchModel patch) {ex.Message}"); app.UpdateState(StateCode.ErrorExtractingFail); } }
public ActionResult Patch(long id) { //get patch from db; PatchManager patchManager = new PatchManager(); Patch p = patchManager.Get(id); PatchModel model = PatchModelHelper.ConvertTo(p); return(View(model)); }
public ActionResult Patch(int id, [FromBody] PatchModel patch) { try { Service.Update(id, patch); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }
public HttpResponseMessage Patch(PatchModel<Todo> todoPatch) { // You first have to fetch the model from the database. // DbContext makes partial database updates trivial ! // But you always first need to fetch the data from the database... Todo updateModel = _db.Todoes.Find( todoPatch.GetKeys(_db)); // now you can apply the received updates on our fetched model todoPatch.UpdateModel(updateModel); // and save the changes _db.SaveChanges(); // http status code 204 marks the request as excecuted return new HttpResponseMessage<Todo>(HttpStatusCode.NoContent); }
public static UpdateDto ToDto(this PatchModel model) { if (model is null) { throw new ArgumentNullException(nameof(model)); } return(new UpdateDto( Name: model.Name, Subject: model.Subject, IsHtml: model.IsHtml, Type: model.Type)); }
public PatcherWindow(PatchModel model, EditorModel em) { InitializeComponent(); PatchWindow.LoadedBehavior = MediaState.Manual; this.DataContext = model; Model = model; EModel = em; Model.RefreshReferences(); Model.WindowState.PropertyChanged += WindowState_PropertyChanged; Refresh.Click += (s, a) => { PreparePatchPicker(); }; DecSpace.Click += (s, a) => { model.WorkspaceWidth -= 100; }; IncSpace.Click += (s, a) => { model.WorkspaceWidth += 100; }; PreparePatchPicker(); PrepareTutoPatchPicker(); }
public async Task <Result> PatchAsync(string collectionName, string key, PatchModel item) { if (item == null) { throw new ArgumentNullException("item", "item cannot be null"); } var json = JsonConvert.SerializeObject(item); return(Put(collectionName, key, json)); var url = UrlBase + collectionName + "/" + key; var baseResult = Communication.CallWebRequest(_apiKey, url, "PATCH", json); return(await PatchAsync(collectionName, key, item)); }
public void PatchAddModel() { var item = new TestData { Id = 3, Value = "John" }; var putResult = _orchestrate.Put(CollectionName, "3", item); Assert.IsTrue(putResult.Path.Ref.Length > 0); var patchItem = new PatchModel { op = "add", value = "Newly added value", path = "Value" }; var patchResult = _orchestrate.Patch(CollectionName, "3", patchItem); var testValue = JsonConvert.DeserializeObject <TestData>(_orchestrate.Get(CollectionName, "3").Value.ToString()); Assert.IsTrue(testValue.Value.Equals("TestJSONPATCH")); }
public void PatchRemove() { var item = new TestData { Id = 3, Value = "John" }; var putResult = _orchestrate.Put(CollectionName, "3", item); Assert.IsTrue(putResult.Path.Ref.Length > 0); var patchItem = new PatchModel { op = "remove", path = "Value" }; var patchResult = _orchestrate.Patch(CollectionName, "3", patchItem); var getValue = _orchestrate.Get(CollectionName, "3"); Assert.IsTrue(getValue.Value != null); }
public void PatchReplaceModel() { var item = new TestData { Id = 3, Value = "John" }; var putResult = _orchestrate.Put(CollectionName, "3", item); Assert.IsTrue(putResult.Path.Ref.Length > 0); var patchItem = new PatchModel { op = "replace", path = "Value", value = "Replaced John with this!" }; var patchResult = _orchestrate.Patch(CollectionName, "3", patchItem); var testValue = JsonConvert.DeserializeObject <TestData>(_orchestrate.Get(CollectionName, "3").Value.ToString()); Assert.IsTrue(testValue.Value.Equals("Replaced John with this!")); }
public void UpdateLocalPatchVersion(PatchModel patch) { try { Setting.LocalConfig.Launcher.PatchVersion = patch.Version; Setting.LocalConfig.Launcher.Token = cryption.Encrypt(patch.Version.ToString()); var file = $"{settingDir}{settingFile}"; File.WriteAllText(file, JsonConvert.SerializeObject(Setting.LocalConfig)); ui.UpdateVersion(); } catch (Exception ex) { Console.WriteLine($"*************MainController.UpdateLocalPatchVersion(): {ex.Message}"); // If the file can't be wrotten , stop the program. UpdateState(State = StateCode.ErrorWritingFail); ui.AddMsg(ex.Message); } }
// GET: Patch public ActionResult Index(long id, bool reset = true) { PatchPlanerModel model = new PatchPlanerModel(); #region create patch Model //get patch from db; PatchManager patchManager = new PatchManager(); Patch p = patchManager.Get(id); PatchModel patchModel = PatchModelHelper.ConvertTo(p); #endregion #region create model for search getAllNames(); if (reset) { ResetSearchProvider(); } SearchProvider sp = GetSearchProvider(); SubjectManager subjectManager = new SubjectManager(); SearchModel searchModel = new SearchModel(); SearchManager searchManager = new SearchManager(); var plants = searchManager.SearchPlants(sp.SearchCriterias); if (plants != null) { //convert all subjects to subjectModels plants = plants.OrderBy(s => s.Name); plants.ToList().ForEach(s => searchModel.Plants.Add(PlantModel.Convert(s))); } searchModel.SearchCriterias = sp.SearchCriterias; #endregion model.Patch = patchModel; model.Search = searchModel; return(View(model)); }
//ToDo create Patch from PatchModel /// <summary> /// Convert a patch model to a patch widthout placemenents /// </summary> /// <param name="patchModel"></param> /// <returns>Patch</returns> public static Patch ConvertTo(PatchModel patchModel) { Patch patch = new Patch(); patch.Id = patchModel.Id; patch.Name = patchModel.Name; patch.Description = patchModel.Description; patch.Height = patchModel.Height; patch.Width = patchModel.Width; patch.LocationType = patchModel.LocationType; patch.NutrientClaim = patchModel.NutrientClaim; ////placmenets //foreach (var p in patch.Placements) //{ // model.Placements.Add(ConvertTo(p)); //} return(patch); }
public async Task<HttpStatusCodeResult> ChangeStoryPublicStatus(int Id, bool isActive, bool question = false) { var patch = new PatchModel { Op = PatchOps.replace, Path = "/IsActive", Value = isActive }; if (!question) { await _proxy.PatchStoryAsync(Id, new List<PatchModel> { patch }); } else { await _proxy.PatchQuestionTemplateAsync(Id, new List<PatchModel> { patch }); } return new HttpStatusCodeResult(HttpStatusCode.OK); }
public EventHandler <ExtractProgressEventArgs> ExtractProgress(PatchModel patch) { return(new EventHandler <ExtractProgressEventArgs>((sender, e) => { if (e.EventType == ZipProgressEventType.Extracting_EntryBytesWritten) { Invoke(new MethodInvoker(delegate() { var text = app.Language.Text.UIComponent; var name = e.CurrentEntry.FileName; lbl_state.Text = $"{text.InstallFailed} {name} - {app.SizeToString(e.BytesTransferred)} / {app.SizeToString(e.TotalBytesToTransfer)}"; var percentage = 100.0 * e.BytesTransferred / e.TotalBytesToTransfer; UpdateProgres(percentage, app.GetTotalPercentage()); ShowReport(); })); } else if (e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry) { } })); }
public void PatchRemoveJsonObj() { var item = new TestData { Id = 3, Value = "John" }; var putResult = _orchestrate.Put(CollectionName, "3", item); Assert.IsTrue(putResult.Path.Ref.Length > 0); var patchObj = new List <object>() { new { op = "remove", path = "Value" } }; var patchItem = new PatchModel { op = "remove", path = "Value" }; var patchResult = _orchestrate.Patch(CollectionName, "3", patchItem); var testValue = Newtonsoft.Json.JsonConvert.DeserializeObject <TestData>(_orchestrate.Get(CollectionName, "3").Value.ToString()); Assert.IsTrue(String.IsNullOrEmpty(testValue.Value)); }
/// <summary> /// Convert a patch to a patchModel /// </summary> /// <param name="patch"></param> /// <returns>PatchModel</returns> public static PatchModel ConvertTo(Patch patch) { PatchModel model = new PatchModel(); model.Id = patch.Id; model.Name = patch.Name; model.Description = patch.Description; model.Height = patch.Height; model.Width = patch.Width; model.LocationType = patch.LocationType; model.NutrientClaim = patch.NutrientClaim; //placmenets foreach (var p in patch.PatchElements) { if (p is Placement) { model.Placements.Add(ConvertTo((Placement)p)); } } return(model); }
public ActionResult <BookingsModel> Patch(string id, PatchModel model) { try { _bookingsService.UpdateBookingDetails(id, model.Path, model.Value); return(NoContent()); } catch (ArgumentNullException anEx) { _logger.LogError(anEx, $"The specified id is null or has no value."); return(BadRequest($"The specified id is null or has no value. See log for details.")); } catch (ArgumentException arg) { _logger.LogError(arg, $"The specified path is not valid."); return(BadRequest(arg.Message)); } catch (Exception ex) { _logger.LogError(ex, $"An unexpected error occurred attempting to patch a BookingsModel. {model} for booking {id}."); return(new StatusCodeResult((int)HttpStatusCode.InternalServerError)); } }
public void Update(int id, PatchModel patchModel) { if (patchModel.Operation == "replace") { if (patchModel.Path == "/currentCapacity") { var conf = Repository.Get(c => c.Id == id).Include("Ingredient").SingleOrDefault(); if (conf != null) { Int32.TryParse(patchModel.Value.ToString(), out int j); if (conf.CurrentCapacity + j <= conf.MaxCapacity) { conf.CurrentCapacity += j; UnitOfWork.SaveChanges(); return; } throw new Exception("Input value isn't correct"); } throw new Exception("Id not found"); } } throw new NotImplementedException(); }
public PatchWork(PatchModel model, bool fadeMode, EditorModel emodel, bool forced) { //NOT WORKING NOW this.pmodel = model; this.Model = emodel; Forced = forced; Name = "Patching: " + model.SourceInfo.FullName; foreach (var ep in model.MediaTracks) { if (!ep.IsTutoPatch) { var patchInfo = ep.FullName; var name = Path.Combine(Model.Locations.TemporalDirectory.FullName, patchInfo.Name); var fileInPatches = new FileInfo(ep.Path.LocalPath); //BeforeWorks.Add(new PreparePatchWork(emodel, fileInPatches, new FileInfo(name), false)); } else if (!ep.FullName.Exists) { var m = emodel.Videotheque.EditorModels.First(x => x.Montage.RawVideoHash == ep.ModelHash); var epInfo = m.Montage.Information.Episodes[ep.EpisodeNumber]; //BeforeWorks.Add(new AssemblyEpisodeWork(m, epInfo)); } } }
public DownloadProgressChangedEventHandler DownloadPatchProgressChangedHandler(PatchModel patch) { return(new DownloadProgressChangedEventHandler((sender, e) => { if (app.cts.Token.IsCancellationRequested) { ((WebClient)sender).CancelAsync(); return; } app.State = StateCode.Downloading; Invoke(new MethodInvoker(delegate() { patch.DownloadedSize = e.BytesReceived; var elapsedSecond = downloadTimer.ElapsedMilliseconds / 1000.0; patch.DownloadSpeedPerSecond = patch.DownloadedSize / elapsedSecond; patch.TotalDownloadTime = elapsedSecond; patch.Size = e.TotalBytesToReceive; patch.DownloadedPercentage = 100.0 * patch.DownloadedSize / patch.Size; //lbl_state.Text = $"正在下載 {patch.FileName} - {app.SizeToString(patch.DownloadedSize)} 共 {app.SizeToString(patch.Size)} ({patch.DownloadedPercentage}%)"; UpdateProgres(patch.DownloadedPercentage, app.GetTotalPercentage()); ShowReport(); })); })); }
public PatchRequest(ObjectId templateId, PatchModel model) { TemplateId = templateId; Model = model; }
public void Update(int id, PatchModel orderDto) { throw new NotImplementedException(); }
public void Update(int id, PatchModel drink) { throw new System.NotImplementedException(); }
public void Build(string oldDirectory, string newDirectory, string patchDirectory, string version) { var oldDir = new DirectoryInfo(oldDirectory); var newDir = new DirectoryInfo(newDirectory); var patchDir = new DirectoryInfo(Path.Combine(patchDirectory, version)); var oldFiles = oldDir.EnumerateFiles("*", SearchOption.AllDirectories) .Select(fileInfo => new MyFileInfo(oldDir, fileInfo)).ToList(); var newFiles = newDir.EnumerateFiles("*", SearchOption.AllDirectories) .Select(fileInfo => new MyFileInfo(newDir, fileInfo)).ToList(); var updatedFiles = newFiles.Join(oldFiles, nf => nf.RelativePath, of => of.RelativePath, (nf, of) => new ChangedFileInfo(of, nf)) .Where(q => !FileUtils.FilesAreEqual(q.OldFile, q.NewFile)).ToList(); var addedFiles = newFiles.Where(q => oldFiles.All(w => w.RelativePath != q.RelativePath)).ToList(); var deletedFiles = oldFiles.Where(q => newFiles.All(w => w.RelativePath != q.RelativePath)).ToList(); if (!patchDir.Exists) { patchDir.Create(); } else { patchDir.Delete(true); patchDir.Refresh(); patchDir.Create(); } var patchContentDir = patchDir.FullName + @"\Data"; var patchModel = new PatchModel(); patchModel.UpdatedFiles = new List <PatchFileInfo>(); foreach (var fileInfo in updatedFiles) { var targetFilePatch = new FileInfo(patchContentDir + fileInfo.RelativePath + ".patch"); if (!targetFilePatch.Directory.Exists) { targetFilePatch.Directory.Create(); } BuildPatchFile(fileInfo.OldFile, fileInfo.NewFile, targetFilePatch.FullName); targetFilePatch.Refresh(); var fileHash = HashUtility.GetFileHash(fileInfo.NewFile.FullPath); string patchFilePath; long fileSize = fileInfo.NewFile.Size; bool isPatch; if (targetFilePatch.Length >= fileInfo.NewFile.Size) { targetFilePatch.Delete(); File.Copy(fileInfo.NewFile.FullPath, patchContentDir + fileInfo.RelativePath); patchFilePath = fileInfo.RelativePath; isPatch = false; } else { patchFilePath = fileInfo.RelativePath + ".patch"; isPatch = true; } patchModel.UpdatedFiles.Add(new PatchFileInfo { RelativePath = patchFilePath, Size = fileSize, Hash = fileHash, IsPatch = isPatch }); } foreach (var patchFileInfo in addedFiles) { var targetFilePatch = new FileInfo(patchContentDir + patchFileInfo.RelativePath); if (!targetFilePatch.Directory.Exists) { targetFilePatch.Directory.Create(); } File.Copy(patchFileInfo.FullPath, patchContentDir + patchFileInfo.RelativePath); } patchModel.Version = version; patchModel.DeletedFiles = deletedFiles.Select(q => q.RelativePath).ToList(); patchModel.NewFiles = addedFiles.Select(q => new PatchFileInfo { RelativePath = q.RelativePath, Size = q.Size, Hash = HashUtility.GetFileHash(q.FullPath), IsPatch = false }).ToList(); patchModel.ReleaseDateTime = DateTime.UtcNow; File.WriteAllText(patchDir.FullName + @"\Info.json", JsonConvert.SerializeObject(patchModel, Formatting.Indented)); var zipPath = new FileInfo(Path.Combine(patchDirectory, version + ".zip")); if (zipPath.Exists) { zipPath.Delete(); } ZipFile.CreateFromDirectory(patchDir.FullName, zipPath.FullName, CompressionLevel.Optimal, false, Encoding.UTF8); zipPath.Refresh(); patchDir.Delete(true); var patchesInfoFile = new FileInfo(Path.Combine(patchDirectory, "Info.json")); UpdateInfoModel updateModel; if (patchesInfoFile.Exists) { updateModel = JsonConvert.DeserializeObject <UpdateInfoModel>(File.ReadAllText(patchesInfoFile.FullName)); } else { updateModel = new UpdateInfoModel() { Patches = new List <VersionModel>() }; } if (updateModel.Patches.All(q => q.Version != version)) { updateModel.Patches.Add(new VersionModel() { Version = version, ReleaseDateTime = DateTime.UtcNow, Size = zipPath.Length }); File.WriteAllText(patchesInfoFile.FullName, JsonConvert.SerializeObject(updateModel, Formatting.Indented)); } MessageBox.Show("Patch created!"); }
public void read (object root_json) { IDictionary pmodels_json = (IDictionary)root_json; IDictionary reference_json = (IDictionary)pmodels_json ["reference"]; reference = new Mat ((int)(long)reference_json ["rows"], (int)(long)reference_json ["cols"], CvType.CV_32F); // Debug.Log ("reference " + reference.ToString ()); IList data_json = (IList)reference_json ["data"]; float[] data = new float[reference.rows () * reference.cols ()]; for (int i = 0; i < data_json.Count; i++) { data [i] = (float)(double)data_json [i]; } reference.put (0, 0, data); // Debug.Log ("reference dump " + reference.dump ()); int n = (int)(long)pmodels_json ["n_patches"]; patches = new List<PatchModel> (n); for (int i = 0; i < n; i++) { PatchModel patchModel = new PatchModel (); patchModel.read (pmodels_json ["patch " + i]); patches.Add (patchModel); } }
public async Task <IActionResult> PatchAsync([FromRoute] ObjectId id, [FromBody] PatchModel model, CancellationToken cancellationToken) { await fSender.Send(new PatchRequest(id, model), cancellationToken); return(NoContent()); }