/// <summary> /// Проводит проверку поставщика и отправку на сервер. /// </summary> private async void ValidateAndSendReceiptAsync() { // Провести валидацию объекта с получением списка ошибок. List <ValidationResult> results = SelectedProvider.Validate(new ValidationContext(SelectedProvider)).ToList(); // Если список ошибок не пустой, вывести эти ошибки. if (results.Any()) { foreach (var error in results) { Alert.Show(error.ErrorMessage, "Ошибка!", MessageBoxButton.OK); } } // Если ошибок нет. else { // Если поставщик новый. if (SelectedProvider.Id == 0) { // Отправить поставщика на сохранение в бд await ServerConnect.Connection.InvokeAsync("AddProvider", SelectedProvider); } // Если поставщик существующий. else { // Отправить поставщика на сохранение в бд await ServerConnect.Connection.InvokeAsync("UpdateProvider", SelectedProvider); } // Закрыть режим редактирования. CanEdit = false; // Сбросить выбранное поступление. SelectedProvider = null; } }
private void OnPluginChanged() { ConfigurationValidated = false; ValidationResultData = null; ValidationResultNotes = null; if (SelectedProvider != null) { Account = new RemoteStorageAccount(Guid.NewGuid(), SelectedProvider, SelectedProvider.CreateEmptyRemoteStorageConfiguration()); } else { Account = null; } if (_syncThread != null && _syncThread.IsAlive) { _syncThread.Abort(); } if (_progressThread != null && _progressThread.IsAlive) { _progressThread.Abort(); } SyncProgress = 0; SyncInfoText = string.Empty; }
/// <summary> /// Closes current open position for the selected Position /// </summary> private void ClosePosition() { // Find Order Side string orderSide = SelectedPosition.Position > 0 ? OrderSide.SELL : OrderSide.BUY; // Find Order Quantity int orderQuantity = Math.Abs(SelectedPosition.Position); // Create a new Object which will be used across the application OrderDetails orderDetails = new OrderDetails(SelectedProvider.ProviderName); orderDetails.Price = 0; orderDetails.StopPrice = 0; orderDetails.Quantity = orderQuantity; orderDetails.Side = orderSide; orderDetails.Type = OrderType.Market; orderDetails.Security = SelectedPosition.Security; // Add to selected provider collection for future reference and updates SelectedProvider.AddOrder(orderDetails); // Create new order request OrderRequest orderRequest = new OrderRequest(orderDetails, OrderRequestType.New); // Raise event to notify listener EventSystem.Publish <OrderRequest>(orderRequest); }
private Tuple <IRemoteStorageSyncPersistance, List <INote>, int, int> DoSync(RemoteStorageAccount acc, AlephLogger log) { var data = SelectedProvider.CreateEmptyRemoteSyncData(); var conn = acc.Plugin.CreateRemoteStorageConnection(PluginManagerSingleton.Inst.GetProxyFactory().Build(), acc.Config, new HierarchyEmulationConfig(false, "\\", '\\')); var resultNotes = new ConcurrentQueue <INote>(); var resultErrors = new ConcurrentQueue <string>(); int fullCount; Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Connect to remote"; }); conn.StartSync(data, new List <INote>(), new List <INote>()); { Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "List notes from remote"; }); var missing = conn.ListMissingNotes(new List <INote>()); fullCount = missing.Count; Application.Current.Dispatcher.Invoke(() => { CanAbort = !acc.Plugin.SupportsNewDownloadMultithreading || missing.Count < AppSettings.DEFAULT_INITIALDOWNLOAD_PARALLELISM_THRESHOLD; }); SynchronizationThread.ExecuteInParallel( log, "InitialDownloadNewNotes", acc.Plugin.SupportsNewDownloadMultithreading, missing, AppSettings.DEFAULT_INITIALDOWNLOAD_PARALLELISM_LEVEL, AppSettings.DEFAULT_INITIALDOWNLOAD_PARALLELISM_THRESHOLD, (e, xnoteid) => { resultErrors.Enqueue(xnoteid); return(true); }, xnoteid => { var msg = $"Download Note {resultNotes.Count}/{missing.Count}"; Application.Current.Dispatcher.Invoke(() => { SyncInfoText = msg; }); var note = conn.DownloadNote(xnoteid, out var isnewnote); if (isnewnote) { note.SetLocalDirty("Set Note LocalDirty=true after download in Startupmode"); note.ResetRemoteDirty("Set Note RemoteDirty=false after download in Startupmode"); resultNotes.Enqueue(note); } else { log.Warn("Sync_FirstStart", $"Download new note {{id:'{xnoteid}'}} returned false"); } }); } Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Finish synchronization"; }); conn.FinishSync(out var _); return(Tuple.Create(data, resultNotes.ToList(), resultErrors.Count, fullCount)); }
public async Task <IVoice> DefaultVoice() { VoiceList = await SelectedProvider.GetVoicesAsync(); var lastUsedVoice = VoiceList.FirstOrDefault(voice => Settings.Default.LastVoice == voice.Name); return(lastUsedVoice ?? VoiceList.First()); }
private Tuple <IRemoteStorageSyncPersistance, List <INote> > DoSync(RemoteStorageAccount acc, AlephLogger log) { var data = SelectedProvider.CreateEmptyRemoteSyncData(); var conn = acc.Plugin.CreateRemoteStorageConnection(PluginManagerSingleton.Inst.GetProxyFactory().Build(), acc.Config, new HierachyEmulationConfig(false, "\\", '\\')); var resultNotes = new List <INote>(); Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Connect to remote"; }); conn.StartSync(data, new List <INote>(), new List <INote>()); { Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "List notes from remote"; }); var missing = conn.ListMissingNotes(new List <INote>()); int idx = 0; foreach (var xnoteid in missing) { var noteid = xnoteid; idx++; try { string msg = $"Download Note {idx}/{missing.Count}"; Application.Current.Dispatcher.Invoke(() => { SyncInfoText = msg; }); var note = conn.DownloadNote(noteid, out var isnewnote); if (isnewnote) { note.SetLocalDirty("Set Note LocalDirty=true after download in Startupmode"); note.ResetRemoteDirty("Set Note RemoteDirty=false after download in Startupmode"); resultNotes.Add(note); } else { log.Warn("Sync_FirstStart", string.Format("Download new note {{id:'{0}'}} returned false", noteid)); } } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new Exception(string.Format("Could not download new note '{0}' on remote cause of {1}", noteid, e.Message)); } } } Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Finish synchronization"; }); conn.FinishSync(); return(Tuple.Create(data, resultNotes)); }
private void RefreshFileSelections() { SelectedProvider.GetCatalog().GetLibraryAsync(_packageId, CancellationToken.None).ContinueWith(x => { if (x.IsFaulted || x.IsCanceled) { SelectedPackage = null; return; } SelectedPackage = x.Result; }); }
private void RefreshFileSelections() { (string name, string version) = LibraryIdToNameAndVersionConverter.Instance.GetLibraryNameAndVersion(_packageId, SelectedProvider.Id); SelectedProvider.GetCatalog().GetLibraryAsync(name, version, CancellationToken.None).ContinueWith(x => { if (x.IsFaulted || x.IsCanceled) { SelectedPackage = null; return; } SelectedPackage = x.Result; }); }
/// <summary> /// Отменяет редактирование поставщика. /// </summary> private async void DiscardChangesAsync() { // Отменить режим редактирования. CanEdit = false; // Если поставщик новый. if (SelectedProvider.Id == 0) { // Сбросить выбранного поставщика. SelectedProvider = null; } else { // Отправить запрос на закрытие документа. await ServerConnect.Connection.InvokeAsync("CloseDocument", SelectedProvider.Id, SelectedProvider.GetType().Name, Data.UserData.CurrentUser.Osp.Id); // Отправить запрос на получение поставщика. await ServerConnect.Connection.InvokeAsync("GetProvider", SelectedProvider.Id); } }
private void ProcessParameters() { try { if (SelectedProvider == null) { throw new Exception("No provider selected"); } var meta = SelectedProvider.GetMetaFields(); foreach (Control c in optionsGrid.Children) { if (c.Tag != null) { string id = c.Tag.ToString(); string value = null; if (c is TextBox) { value = ((TextBox)c).Text; } else if (c is ComboBox) { value = ((ComboBox)c).Text; } else if (c is CheckBox) { value = ((CheckBox)c).IsChecked.ToString(); } else { //Error } var item = meta.FirstOrDefault(x => x.ID == id); if (item != null) //TODO: Disabled hack { item.SetValue(value); } } } var newSource = selectedProvider.CreateNewSource( selectedProvider.HasUniqueName ? Name : null //Probably just use name , null, meta); if (selectedProvider.HasUrlField) { newSource.SetMetaData(new MetaDataObject(SourceViewModel.URL, SourceViewModel.URL, url)); } newSource.SetMetaData(new MetaDataObject(SourceViewModel.UPDATES_COLOR, SourceViewModel.UPDATES_COLOR, SourceViewModel.SerializeColor(selectedColor))); newSource.SetMetaData(new MetaDataObject(SourceViewModel.DISABLED, SourceViewModel.DISABLED, disabled)); if (originalSource != null) { newSource.SetID(originalSource.Data.ID.Value); datastore.UpdateSource(newSource); originalSource.SetSource(newSource); } else { datastore.AddSource(newSource); originalSource = new SourceViewModel(newSource); } window.Close(); } catch (Exception ex) { MessageBoxFactory.ShowError(ex); } }