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

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