Beispiel #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);
        }
Beispiel #2
0
        public async Task OnSMStopped()
        {
            _sm = null;

            if (OnSMStoppedEvent != null)
            {
                await OnSMStoppedEvent.InvokeAsync(this, null);
            }
        }