Example #1
0
        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  = (TestPluginViewModel)formatter.Deserialize(ms);
                foreach (PropertyInfo property in pluginViewModelState.GetType().GetProperties())
                {
                    try
                    {
                        property.SetValue(this, property.GetValue(pluginViewModelState, null));
                    }
                    catch (ArgumentException) { }
                }
            });
        }
Example #2
0
        public async void ButtonClickHandler()
        {
            MessageBlock = "You just pressed the button!";
            FileActionRequestEventArgs args = new FileActionRequestEventArgs("someFile");

            await OnReadFromFileRequest(args);
        }
Example #3
0
 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);
     }
 }
Example #4
0
 protected virtual async Task OnWriteToFileRequest(FileActionRequestEventArgs args)
 {
     await WriteToFileRequest?.Invoke(this, args);
 }
Example #5
0
 protected virtual async Task OnReadFromFileRequest(FileActionRequestEventArgs args)
 {
     await ReadFromFileRequest?.Invoke(this, args);
 }