// // 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); }
// // 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); }