示例#1
0
        /// <summary>
        /// Try to load the state for the plugin.
        /// </summary>
        /// <param name="pluginState">The plugin state to load.</param>
        /// <param name="fileSystem">The file system to retrieve further files from.</param>
        /// <param name="savePath">The <see cref="savePath"/> for the initial file.</param>
        /// <param name="loadContext">The load context.</param>
        /// <returns>If the loading was successful.</returns>
        private async Task <LoadResult> TryLoadStateAsync(IPluginState pluginState, IFileSystem fileSystem, UPath savePath,
                                                          LoadContext loadContext)
        {
            // 1. Check if state implements ILoadFile
            if (!pluginState.CanLoad)
            {
                return(new LoadResult(false, "The state is not loadable."));
            }

            // 2. Try loading the state
            try
            {
                await Task.Run(async() => await pluginState.AttemptLoad(fileSystem, savePath, loadContext));
            }
            catch (Exception ex)
            {
                return(new LoadResult(ex));
            }

            return(new LoadResult(true));
        }
示例#2
0
        /// <summary>
        /// Try to load the state for the plugin.
        /// </summary>
        /// <param name="pluginState">The plugin state to load.</param>
        /// <param name="fileSystem">The file system to retrieve further files from.</param>
        /// <param name="filePath">The path of the identified file.</param>
        /// <param name="loadContext">The load context.</param>
        /// <param name="loadInfo">The load info for this loading operation.</param>
        /// <param name="plugin">The plugin from which the state should be loaded.</param>
        /// <returns>If the loading was successful.</returns>
        private async Task <LoadResult> TryLoadStateAsync(IPluginState pluginState, IFileSystem fileSystem, UPath filePath,
                                                          LoadContext loadContext, LoadInfo loadInfo, IFilePlugin plugin)
        {
            // 1. Check if state supports loading
            if (!pluginState.CanLoad)
            {
                return(new LoadResult(false, "The state is not loadable."));
            }

            // 2. Try loading the state
            try
            {
                await Task.Run(async() => await pluginState.AttemptLoad(fileSystem, filePath, loadContext));
            }
            catch (Exception e)
            {
                loadInfo.Logger?.Fatal(e, "The plugin state for {0} could not be loaded.", plugin.PluginId);
                return(new LoadResult(e));
            }

            return(new LoadResult(true));
        }