コード例 #1
0
        //
        // Collection loading management

        public async Task <bool> Start(
            NativeDataCfg nativeDataCfg,
            StartupCfg startupCfg,
            SMCollection collection)
        {
            try
            {
                if (_sm != null)
                {
                    throw new InvalidOperationException("_sm is already instantiated");
                }

                await LoadConfig(collection, startupCfg);

                var nativeData = CheckSuperMemoExecutable(nativeDataCfg);

                _sm = InstantiateSuperMemo(collection, nativeData.SMVersion);

                // TODO: Move somewhere else
                _sm.UI.ElementWdw.OnAvailable += OnSuperMemoWindowsAvailable;

                await _sm.Start(nativeData);

                // TODO: Ensure opened collection (windows title) matches parameter
            }
            catch (Exception ex)
            {
                if (ex is SMAException)
                {
                    LogTo.Warning(ex, "Failed to start SM.");
                }

                else
                {
                    LogTo.Error(ex, "Failed to start SM.");
                }

                _sm?.Dispose();
                _sm = null;

                try
                {
                    if (OnSMStoppedEvent != null)
                    {
                        await OnSMStoppedEvent.InvokeAsync(this, new SMProcessArgs(_sm, null)).ConfigureAwait(true);
                    }
                }
                catch (Exception pluginEx)
                {
                    LogTo.Error(pluginEx, "Exception while notifying plugins OnSMStoppedEvent.");
                }

                // TODO: Handle exception

                return(false);
            }

            return(true);
        }
コード例 #2
0
        //
        // Collection loading management

        public async Task <Exception> StartAsync(
            NativeDataCfg nativeDataCfg,
            SMCollection collection)
        {
            try
            {
                if (_sm != null)
                {
                    throw new InvalidOperationException("_sm is already instantiated");
                }

                // Load collection config
                await LoadConfigAsync(collection).ConfigureAwait(false);

                // Make sure the SuperMemo version is compatible and instantiate it
                var nativeData = CheckSuperMemoExecutable(nativeDataCfg);

                _sm = GetSuperMemoFactory(collection, nativeData.SMVersion);

                // Notify Plugins of selected collection
                await OnCollectionSelectedAsync(collection).ConfigureAwait(false);

                await _sm.StartAsync(nativeData).ConfigureAwait(false);

                // TODO: Ensure opened collection (windows title) matches parameter
            }
            catch (Exception ex)
            {
                if (ex is SMAException)
                {
                    LogTo.Warning(ex, "Failed to start SM.");
                }

                else
                {
                    LogTo.Error(ex, "Failed to start SM.");
                }

                _sm?.Dispose();
                _sm = null;

                // TODO: Handle exception

                return(ex);
            }

            return(null);
        }
コード例 #3
0
ファイル: SMA.cs プロジェクト: lukasz-mroz/SuperMemoAssistant
        //
        // Collection loading management

        public async Task <Exception> Start(
            NativeDataCfg nativeDataCfg,
            SMCollection collection)
        {
            try
            {
                if (_sm != null)
                {
                    throw new InvalidOperationException("_sm is already instantiated");
                }

                await LoadConfig(collection);

                var nativeData = CheckSuperMemoExecutable(nativeDataCfg);

                _sm = InstantiateSuperMemo(collection, nativeData.SMVersion);

                // TODO: Move somewhere else
                _sm.UI.ElementWdw.OnAvailable += OnSuperMemoWindowsAvailable;

                await _sm.Start(nativeData);

                // TODO: Ensure opened collection (windows title) matches parameter
            }
            catch (Exception ex)
            {
                if (ex is SMAException)
                {
                    LogTo.Warning(ex, "Failed to start SM.");
                }

                else
                {
                    LogTo.Error(ex, "Failed to start SM.");
                }

                _sm?.Dispose();
                _sm = null;

                // TODO: Handle exception

                return(ex);
            }

            return(null);
        }