public async Task RestoreAsync() { FileActionRequestEventArgs args = new FileActionRequestEventArgs(Name + "State"); await OnReadFromFileRequest(args); if (args.Exception != null) { throw args.Exception; } if (args.InOutData == null) { return; } await Task.Run(() => { MemoryStream ms = new MemoryStream(); ms.Write(args.InOutData, 0, args.InOutData.Length); ms.Position = 0; BinaryFormatter formatter = new BinaryFormatter(); formatter.Binder = new Binder(); var pluginViewModelState = (PluginViewModel)formatter.Deserialize(ms); foreach (PropertyInfo property in pluginViewModelState.GetType().GetProperties()) { try { property.SetValue(this, property.GetValue(pluginViewModelState, null)); } catch (ArgumentException) { } } }); }
public async void ButtonClickHandler() { MessageBlock = "You just pressed the button!"; FileActionRequestEventArgs args = new FileActionRequestEventArgs("someFile"); await OnReadFromFileRequest(args); }
public async Task DumpAsync() { if (_isChanged) { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); formatter.Serialize(ms, this); FileActionRequestEventArgs args = new FileActionRequestEventArgs(Name + "State", ms.ToArray()); await OnWriteToFileRequest(args); } }
protected virtual async Task OnWriteToFileRequest(FileActionRequestEventArgs args) { await WriteToFileRequest?.Invoke(this, args); }
protected virtual async Task OnReadFromFileRequest(FileActionRequestEventArgs args) { await ReadFromFileRequest?.Invoke(this, args); }