示例#1
0
        /// <summary>
        /// Represents an open file in the runtime of Kuriimu.
        /// </summary>
        /// <param name="filePlugin">The entry class of the plugin for this file.</param>
        /// <param name="pluginState">The plugin state of this file.</param>
        /// <param name="parentState">The parent state for this file.</param>
        /// <param name="fileSystem">The file system around the initially opened file.</param>
        /// <param name="filePath">The path of the file to be opened in the file system.</param>
        /// <param name="streamManager">The stream manager used for this opened state.</param>
        /// <param name="pluginManager">The plugin manager for this state.</param>
        public StateInfo(IFilePlugin filePlugin, IPluginState pluginState, IStateInfo parentState,
                         IFileSystem fileSystem, UPath filePath,
                         IStreamManager streamManager, IPluginManager pluginManager)
        {
            ContractAssertions.IsNotNull(filePlugin, nameof(filePlugin));
            ContractAssertions.IsNotNull(pluginState, nameof(pluginState));
            ContractAssertions.IsNotNull(fileSystem, nameof(fileSystem));
            ContractAssertions.IsNotNull(streamManager, nameof(streamManager));
            ContractAssertions.IsNotNull(pluginManager, nameof(pluginManager));

            if (filePath == UPath.Empty || filePath.IsDirectory)
            {
                throw new InvalidOperationException($"'{filePath}' has to be a path to a file.");
            }
            if (!fileSystem.FileExists(filePath))
            {
                throw FileSystemExceptionHelper.NewFileNotFoundException(filePath);
            }

            FilePlugin    = filePlugin;
            PluginState   = pluginState;
            FilePath      = filePath;
            FileSystem    = fileSystem;
            StreamManager = streamManager;
            PluginManager = pluginManager;

            ParentStateInfo = parentState;

            ArchiveChildren = new List <IStateInfo>();
        }
        /// <summary>
        /// Construcotr of the class.
        /// </summary>
        /// <param name="changePosition"></param>
        /// <param name="pluginState"></param>
        public MoveActiveWindowPositionExecutionMain(IChangeWindowPosition changePosition, IPluginState pluginState)
        {
            if (changePosition == null) { throw new ArgumentNullException("changePosition"); }
            if (pluginState == null) { throw new ArgumentNullException("pluginState"); }

            _changePosition = changePosition;
            _pluginState = pluginState;
        }
示例#3
0
        private bool TryCreateState(IPluginState state)
        {
            // 1. Check if state implements ICreateFile
            //if (!(state is ICreateFile creatableState))
            //{
            //    return false;
            //}

            // 2. Create empty state
            //creatableState.CreateNew();
            return(false);
        }
示例#4
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>
        /// <returns>If the loading was successful.</returns>
        private async Task <LoadResult> TryLoadStateAsync(IPluginState pluginState, IFileSystem fileSystem, UPath filePath,
                                                          LoadContext loadContext)
        {
            // 1. Check if state implements ILoadFile
            if (!(pluginState is ILoadFiles loadableState))
            {
                return(new LoadResult(false, "The state is not loadable."));
            }

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

            return(new LoadResult(true));
        }
示例#5
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 implements ILoadFile
            if (!(pluginState is ILoadFiles loadableState))
            {
                return(new LoadResult(false, "The state is not loadable."));
            }

            // 2. Try loading the state
            try
            {
                await Task.Run(async() => await loadableState.Load(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));
        }
示例#6
0
        /// <summary>
        /// Try to create a new plugin state.
        /// </summary>
        /// <param name="plugin">The plugin from which to create a new state.</param>
        /// <param name="pluginManager">The plugin manager to pass to the state creation.</param>
        /// <param name="pluginState">The created state.</param>
        /// <returns>If the creation was successful.</returns>
        private LoadResult TryCreateState(IFilePlugin plugin, IPluginManager pluginManager, out IPluginState pluginState)
        {
            pluginState = null;

            try
            {
                pluginState = plugin.CreatePluginState(pluginManager);
            }
            catch (Exception e)
            {
                return(new LoadResult(e));
            }

            return(new LoadResult(true));
        }
 public UnknownPluginStateException(IPluginState pluginState) : base(GetMessage(pluginState))
 {
 }
 private static string GetMessage(IPluginState pluginState)
 {
     return(string.Format(UnknownPluginState, pluginState.GetType().Name));
 }
示例#9
0
        /// <summary>
        /// Try to create a new plugin state.
        /// </summary>
        /// <param name="plugin">The plugin from which to create a new state.</param>
        /// <param name="pluginManager">The plugin manager to pass to the state creation.</param>
        /// <param name="pluginState">The created state.</param>
        /// <param name="loadInfo">The load info for this loading operation.</param>
        /// <returns>If the creation was successful.</returns>
        private LoadResult TryCreateState(IFilePlugin plugin, IPluginManager pluginManager, LoadInfo loadInfo, out IPluginState pluginState)
        {
            pluginState = null;

            try
            {
                pluginState = plugin.CreatePluginState(pluginManager);
            }
            catch (Exception e)
            {
                loadInfo.Logger?.Fatal(e, "The plugin state for '{0}' could not be initialized.", plugin.PluginId);
                return(new LoadResult(e));
            }

            return(new LoadResult(true));
        }