Example #1
0
        /// <summary>
        /// Loads and restores the serialized state of the current instance, if available
        /// </summary>
        /// <param name="file">The optional file to load, if present</param>
        public async Task RestoreStateAsync(IFile?file)
        {
            if (file is null)
            {
                string
                    temporaryPath = FilesService.TemporaryFilesPath,
                    statePath     = Path.Combine(temporaryPath, "state.json");

                if (!(await FilesService.TryGetFileFromPathAsync(statePath) is IFile jsonFile))
                {
                    return;
                }

                using Stream stream = await jsonFile.OpenStreamForReadAsync();

                using StreamReader reader = new StreamReader(stream);

                string json = await reader.ReadToEndAsync();

                IdeState state = JsonSerializer.Deserialize <IdeState>(json);

                if (state.FilePath is null)
                {
                    Code = SourceCode.CreateEmpty();
                }
                else
                {
                    IFile?sourceFile = await FilesService.TryGetFileFromPathAsync(state.FilePath);

                    if (sourceFile is null)
                    {
                        Code = SourceCode.CreateEmpty();
                    }
                    else
                    {
                        Code = await SourceCode.TryLoadFromEditableFileAsync(sourceFile) ?? SourceCode.CreateEmpty();
                    }
                }

                Text   = state.Text.AsMemory();
                Row    = state.Row;
                Column = state.Column;

                if (!(Code.File is null))
                {
                    _ = FilesHistoryService.LogOrUpdateActivityAsync(Code.File);
                }

                StateRestored?.Invoke(this, state);
            }
            else
            {
                await TryLoadTextFromFileAsync(file);
            }
        }
Example #2
0
 public void OnStateRestored(int index)
 {
     StateRestored?.Invoke(index);
 }
Example #3
0
 public void RestoreStateFrom(SkinIndentity skinIdentity)
 {
     RestoreStateCore(skinIdentity);
     ServiceLocator.GetInstance <IApplicationServices>().StartNewParallelTask(() =>
     {
         RestoreTestCase(skinIdentity.ABTestCase);
         ServiceLocator.GetInstance <IApplicationServices>().ExecuteOnUIThread(() => StateRestored?.Invoke(this, EventArgs.Empty));
     });
 }
Example #4
0
 protected void RestoreState() => StateRestored?.Invoke();
 public void OnStateRestored()
 {
     StateRestored?.Invoke();
 }
Example #6
0
 private void OnStateRestored()
 {
     StateRestored?.Invoke(this, EventArgs.Empty);
 }
Example #7
0
 private void Builder_StateRestored(object sender, EventArgs e)
 {
     StateRestored?.Invoke(this, EventArgs.Empty);
 }