private void LoadData(List <LoginFieldS> lf) { SourceItems.Clear(); if (lf != null && lf.Count > 0) { Converts conv = new Converts(); foreach (LoginFieldS fields in lf) { DrawingImage tmpDraw = new DrawingImage(); if (fields.imageData == null || fields.imageData.Length == 0) { tmpDraw = HIOStaticValues.PutTextInImage(fields.url.Substring(0, 1)); } else { tmpDraw = conv.BitmapImageToDrawingImage(conv.byteArrayToImage(fields.imageData)); } SourceItems.Add(new TLinkItem(fields.title, fields.userName, tmpDraw, Int32.Parse(fields.rowid), fields.url)); } } OnPropertyChanged(() => Items); }
public PlaylistPlayer(Services.HohoemaPlaylist hohoemaPlaylist, PlaylistSettings playlistSettings) { HohoemaPlaylist = hohoemaPlaylist; PlaylistSettings = playlistSettings; _SettingsObserveDisposer = Observable.Merge( PlaylistSettings.ObserveProperty(x => x.IsShuffleEnable).ToUnit(), PlaylistSettings.ObserveProperty(x => x.RepeatMode).ToUnit(), PlaylistSettings.ObserveProperty(x => x.IsReverseModeEnable).ToUnit() ) .Subscribe(async _ => { using (var releaser = await _PlaylistUpdateLock.LockAsync()) { _RepeatMode = PlaylistSettings.RepeatMode; ResetRandmizedItems(SourceItems); CurrentIndex = PlaylistSettings.IsShuffleEnable ? 0 : (SourceItems?.IndexOf(Current) ?? 0); RaisePropertyChanged(nameof(CanGoBack)); RaisePropertyChanged(nameof(CanGoNext)); } }); }
public void RemoveGroup(Group g) { _service.RemoveGroup(g.ID); Groups.Remove(g); InstancesWithoutGroup.AddOrUpdate(g.Instances); SourceItems.AddOrUpdate(g.Instances.Select(i => CreateSourceItem(i))); }
public void LoadDatabySort() { if (HIOStaticValues.CheckSyncingData()) { return; } #region Sort Data List <TAccountItem> items = SourceItems.ToList(); SourceItems.Clear(); if (SortByField.IsNullOrEmpty() || "Name".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderBy(t => t.Name).ToList(); } else if ("Date".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderByDescending(t => t.Date).ToList(); } else if ("Popularity".Equals(SortByField, StringComparison.InvariantCultureIgnoreCase)) { items = items.OrderByDescending(t => t.Popularity).ToList(); } #endregion #region Add Data foreach (var item in items) { SourceItems.Add(item); } #endregion OnPropertyChanged(nameof(Items)); }
protected async Task GenerateLoad(int requests) { var srcNumberOfItems = SourceItems.Count(); List <string> selectedItems; var randomResources = SourceItems.OrderBy(i => Guid.NewGuid()); if (requests <= srcNumberOfItems) { selectedItems = randomResources.Take(requests).ToList(); } else { var tmpList = new List <string>(); do { tmpList.AddRange(randomResources.Take(requests)); requests -= srcNumberOfItems; } while (requests >= 0); selectedItems = tmpList; } _executionsPerSecond = selectedItems.Count; Console.WriteLine(PrintTestProgress()); Interlocked.Add(ref ExpectedExecutionCount, selectedItems.Count()); await Load(selectedItems); }
private void DeleteItem() { if (SelectedIndex >= 0) { SourceItems.RemoveAt(SelectedIndex); } }
private async Task SaveGroupsToFile() { string infoSourceName = ""; switch (dataSourceMode) { case SmartDataSourceMode.SD_SOURCE_EVENTS: await smartDataProvider.SaveEventGroups(SourceItems.Select(x => x.ToSmartGroupsJsonData()).ToList()); infoSourceName = "Events"; break; case SmartDataSourceMode.SD_SOURCE_ACTIONS: await smartDataProvider.SaveActionsGroups(SourceItems.Select(x => x.ToSmartGroupsJsonData()).ToList()); infoSourceName = "Actions"; break; case SmartDataSourceMode.SD_SOURCE_TARGETS: await smartDataProvider.SaveTargetsGroups(SourceItems.Select(x => x.ToSmartGroupsJsonData()).ToList()); infoSourceName = "Targets"; break; } History.MarkAsSaved(); messageBoxService.ShowDialog(new MessageBoxFactory <bool>().SetTitle("Success!") .SetMainInstruction($"Editor successfully saved definitions of {infoSourceName} Groups!") .SetIcon(MessageBoxIcon.Information) .WithOkButton(true) .Build()); }
public void RemoveInstanceFromGroup(Instance i, Group g) { _service.RemoveInstanceFromGroup(i.ID, g.ID); g.Instances.Remove(i); InstancesWithoutGroup.AddOrUpdate(i); SourceItems.AddOrUpdate(CreateSourceItem(i)); }
public void AddInstanceToGroup(Instance i, Group g) { _service.AddInstanceToGroup(i.ID, g.ID); g.Instances.Add(i); InstancesWithoutGroup.Remove(i); SourceItems.AddOrUpdate(CreateSourceItem(i, g)); }
private void AddSource() { var obj = new ConditionSourcesJsonData(); obj.Id = SourceItems.Max(x => x.Id) + 1; obj.Name = "CONDITION_SOURCE_TYPE_"; OpenEditor(obj, true); }
private async Task AddNewItem() { var obj = new ConditionJsonData(); obj.Id = SourceItems.Max(x => x.Id) + 1; obj.Name = "CONDITION_"; await OpenEditor(obj, true); }
public void PopulateItems() { if ((MetroManager.Current.RailwayIds == null) || !MetroManager.Current.RailwayIds.Any()) { return; } foreach (var railwayId in MetroManager.Current.RailwayIds) { var existingItem = SourceItems .FirstOrDefault(x => x.RailwayIds .Select(y => y.Replace("Branch", String.Empty)) .Contains(railwayId.Replace("Branch", String.Empty))); // For MarunouchiBranch if (existingItem != null) { existingItem.RailwayIds.Add(railwayId); } else { var newItem = new RailwayItemViewModel { RailwayIds = new List <string> { railwayId } }; SourceItems.Add(newItem); } } if ((Settings.Current.RailwayIdPriority == null) || !Settings.Current.RailwayIdPriority.Any()) { SelectedIndices = Enumerable.Range(0, SourceItems.Count).ToArray(); } else { var indices = new List <int>(); int order = 0; foreach (var railwayId in Settings.Current.RailwayIdPriority) { int index = 0; foreach (var item in SourceItems) { if (item.RailwayIds[0] == railwayId) { item.IsSelected = true; item.Order = order; indices.Add(index); break; } index++; } order++; } SelectedIndices = indices.ToArray(); } }
public async Task AddGroupToSource() { var result = await OpenNameEditingWindow(""); if (!string.IsNullOrWhiteSpace(result)) { SourceItems.Add(new ConditionGroupsEditorData(result)); } }
public DragInfo(object sender, MouseButtonEventArgs e) { //use the relative mouse position for browser DragStartPosition = Mouse.GetPosition(sender as IInputElement); Effects = DragDropEffects.None; MouseButton = e.ChangedButton; VisualSource = sender as UIElement; ItemsControl itemsControl = sender as ItemsControl; if (itemsControl != null) { UIElement item = null; // Don't remove try/catch, sometimes exception is thrown here. // For example, when clicking "Loading more..." item, the item will be removed immediately, // so when code goes here, the item has gone and exception is thrown. try { item = itemsControl.GetItemContainer((UIElement)e.OriginalSource); } catch { } if (item != null) { ItemsControl itemParent = ItemsControl.ItemsControlFromItemContainer(item); if (itemParent != null) { SourceCollection = itemParent.ItemsSource ?? itemParent.Items; SourceItem = itemParent.ItemContainerGenerator.ItemFromContainer(item); } SourceItems = itemsControl.GetSelectedItems(); // Some controls (TreeView) haven't updated their // SelectedItem by this point. Check to see if there 1 or less item in // the SourceItems collection, and if so, override the SelectedItems // with the clicked item. if (SourceItems.Cast <object>().Count() <= 1) { SourceItems = Enumerable.Repeat(SourceItem, 1); } VisualSourceItem = item; } else { SourceCollection = itemsControl.ItemsSource ?? itemsControl.Items; } } if (SourceItems == null) { SourceItems = Enumerable.Empty <object>(); } }
public void AddGroupToSource() { var result = ""; OpenNameEditingWindow("", out result); if (!string.IsNullOrWhiteSpace(result)) { SourceItems.Add(new SmartDataGroupsEditorData(result)); } }
private async void ResetItems() { var newOwner = Playlist; using (var releaser = await _PlaylistUpdateLock.LockAsync()) { PlayedItems.Clear(); _ItemsObservaeDisposer?.Dispose(); _ItemsObservaeDisposer = null; ResetRandmizedItems(SourceItems); if (newOwner is INotifyCollectionChanged playlistNotifyCollectionChanged) { _ItemsObservaeDisposer = playlistNotifyCollectionChanged.CollectionChangedAsObservable() .Subscribe(async _ => { using (var releaser2 = await _PlaylistUpdateLock.LockAsync()) { // 再生中アイテムが削除された時のプレイリストの動作 // 動画プレイヤーには影響を与えないこととする // 連続再生動作の継続性が確保できればOK SourceItems.Clear(); foreach (var newItem in newOwner.Select(x => new PlaylistItem() { ContentId = x, Owner = newOwner, Type = PlaylistItemType.Video, })) { SourceItems.Add(newItem); } ResetRandmizedItems(SourceItems); if (PlaylistSettings.IsShuffleEnable) { CurrentIndex = 0; } else { CurrentIndex = Current == null ? 0 : SourceItems.IndexOf(Current); } RaisePropertyChanged(nameof(CanGoBack)); RaisePropertyChanged(nameof(CanGoNext)); } }); } RaisePropertyChanged(nameof(CanGoBack)); RaisePropertyChanged(nameof(CanGoNext)); } }
private void DeleteItemFromSource(object obj) { if (obj is ConditionGroupsEditorData source) { SourceItems.Remove(source); } else if (obj is ConditionGroupsEditorDataNode node) { node.Owner !.Members.Remove(node); node.Owner = null; } }
private void ApplySelectedItems() { if (!SourceItems.Any(x => x.IsSelected)) { return; } Settings.Current.RailwayIdPriority = SourceItems .Where(x => x.IsSelected) .OrderBy(x => x.Order) .SelectMany(x => x.RailwayIds) .ToArray(); }
private void OnTextChanged(object sender, TextChangedEventArgs e) { if (ignoreUpdate) { ignoreUpdate = false; return; } var tb = sender as TextBox; // Don't change selection when text is selected or no text if (!string.IsNullOrEmpty(tb.Text) && string.IsNullOrEmpty(tb.SelectedText)) { var currentText = tb.Text; // Clear the existing selections and cancel any background work SourceItems.Clear(); suggestions.Clear(); foreach (var worker in workers) { worker.CancelAsync(); } workers.Clear(); // Start udpate process foreach (var suggestionProvider in SuggestionProvidersCollection) { // Set up a background worker var bw = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; workers.Add(bw); bw.DoWork += GetSuggestions_DoWork; bw.ProgressChanged += GetSuggestions_ProgressChanged; bw.RunWorkerCompleted += GetSuggestions_RunWorkerCompleted; bw.RunWorkerAsync(new BackgroundWorkerArguments { Provider = suggestionProvider, SearchText = currentText, CurrentValue = SelectedValue }); } } // Set focus on the text box tb.Focus(); }
private void ResetRandmizedItems() { RandamizedItems.Clear(); if (SourceItems != null) { var firstItem = SourceItems.Take(1).SingleOrDefault(); if (firstItem != null) { RandamizedItems.Add(firstItem); RandamizedItems.AddRange(SourceItems.Skip(1).Shuffle()); } } }
private void LoadData(List <LoginFieldS> listlp) { SourceItems.Clear(); SourceAllItems.Clear(); DataBase db = new DataBase(); List <LoginFieldS> llp = db.getInfoFromDB("*", "", ""); Converts conv = new Converts(); if (listlp != null && listlp.Any()) { foreach (LoginFieldS lf in listlp) { DrawingImage tmpDraw = new DrawingImage(); if (lf.imageData == null || lf.imageData.Length == 0) { tmpDraw = HIOStaticValues.PutTextInImage(lf.url.Substring(0, 1)); } else { tmpDraw = conv.BitmapImageToDrawingImage(conv.byteArrayToImage(lf.imageData)); } SourceItems.Add(new TLinkItem { Title = lf.title, Description = lf.userName, ImageData = tmpDraw, Id = Int32.Parse(lf.rowid), Url = url }); } } if (llp != null && llp.Any()) { foreach (LoginFieldS lf in llp) { DrawingImage tmpDraw = new DrawingImage(); if (lf.imageData == null || lf.imageData.Length == 0) { tmpDraw = HIOStaticValues.PutTextInImage(lf.url.Substring(0, 1)); } else { tmpDraw = conv.BitmapImageToDrawingImage(conv.byteArrayToImage(lf.imageData)); } SourceAllItems.Add(new TLinkItem { Title = lf.title, Description = lf.userName, ImageData = tmpDraw, Id = Int32.Parse(lf.rowid), Url = lf.url }); } } OnPropertyChanged(() => Items); }
internal async void PlayStarted(PlaylistItem item) { if (item == null) { throw new Exception(); } using (var releaser = await _PlaylistUpdateLock.LockAsync()) { // 新たにプレイリストが指定された場合に // 連続再生をセットアップする if (item.Owner != null) { if (item.Owner != Playlist) { Playlist = item.Owner; } } // GoNext/GoBack内でCurrentが既に変更済みの場合はスキップ // Playlist外から直接PlaylistItemが変更された場合にのみ // 現在再生位置の更新を行う if (Current != item) { Current = item; if (SourceItems != null) { CurrentIndex = PlaylistSettings.IsShuffleEnable ? 0 : SourceItems.IndexOf(Current); } else { CurrentIndex = 0; } // ランダム再生かつ先頭の再生を行う場合は // ランダムアイテムの先頭が現在再生中アイテムになるように // ランダムアイテムリストを修正する // この修正によって、シャッフル再生が先頭しか再生されない問題を回避できる if (CurrentIndex == 0 && PlaylistSettings.IsShuffleEnable) { if (RandamizedItems.FirstOrDefault() != Current) { RandamizedItems.Remove(Current); RandamizedItems.Insert(0, Current); } } } } }
private void CellEditEnding(DataGridCellEditEndingEventArgs e) { var columnDisplayIndex = (DataGridColumns)e.Column.DisplayIndex; if (DataGridSelectedItem is Transaction selectedTransaction) { if (columnDisplayIndex == DataGridColumns.MoneySourceField) { if (!SourceItems.Contains(selectedTransaction.MoneySource)) { SourceItems.Add(selectedTransaction.MoneySource); } } } }
private void LoadBase() { var baseItems = db.GetItems(); ExpensesItems.Clear(); foreach (var transaction in baseItems) { ExpensesItems.Add(transaction); if (!SourceItems.Contains(transaction.MoneySource)) { SourceItems.Add(transaction.MoneySource); } } RaisePropertyChanged(nameof(ExpensesItems)); }
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: if (e.NewStartingIndex < 0) { goto case NotifyCollectionChangedAction.Reset; } for (int i = e.NewItems.Count - 1; i >= 0; i--) { SourceItems.Insert(e.NewStartingIndex, e.NewItems[i]); } break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { SourceItems.RemoveAt(e.OldStartingIndex); } break; case NotifyCollectionChangedAction.Move: for (var i = 0; i < e.OldItems.Count; i++) { var oldi = e.OldStartingIndex; var newi = e.NewStartingIndex; if (e.NewStartingIndex < e.OldStartingIndex) { oldi += i; newi += i; } SourceItems.Move(oldi, newi); } break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Reset: default: ReloadData(); break; } Device.BeginInvokeOnMainThread(() => List.UpdateLayout()); }
private void loadProducts(Trade trade) { foreach (var item in trade.TradeProducts.ToList()) { TradeSideEnum side = trade.GetTradeSide(item.EntityID); if (side == TradeSideEnum.Destination) { DestinationItems.Add(new ProductForTradeViewModel(item, TradeStatus)); } else { SourceItems.Add(new ProductForTradeViewModel(item, TradeStatus)); } } }
private void loadMoney(Trade trade) { foreach (var money in trade.TradeMoneys.ToList()) { TradeSideEnum side = trade.GetTradeSide(money.EntityID); if (side == TradeSideEnum.Destination) { DestinationItems.Add(new MoneyForTradeViewModel(money, TradeStatus)); } else { SourceItems.Add(new MoneyForTradeViewModel(money, TradeStatus)); } } }
private async void Delete() { if (HIOStaticValues.CheckSyncingData()) { return; } if (TMessageBox.Show("Are you sure you want to delete these accounts?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Commands cmd = new Backend.Commands(); while (true) { var res = cmd.AmISync(); if (res == SyncronizingStateEnum.Synced) { break; } else { HIOStaticValues.SyncOpration(); } } await UIService.Execute(async() => { DataBase db = new DataBase(); foreach (var item in SourceItems.Where(t => t.IsChecked).ToArray()) { Commands ic = new Commands(); if (ic.Delete(item.UserID)) { App.Current.Dispatcher.BeginInvoke((Action)(() => { SourceItems.Remove(SourceItems.FirstOrDefault(i => i.UserID == item.UserID)); OnPropertyChanged(nameof(Items)); })); } } await LoadData(); }); OnPropertyChanged(nameof(IsAllChecked)); } }
/// <summary> /// Constructor. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public DragInfo(object sender, MouseButtonEventArgs e) { DragStartPosition = e.GetPosition(null); Effects = DragDropEffects.None; MouseButton = e.ChangedButton; VisualSource = sender as UIElement; if (sender is ItemsControl) { ItemsControl itemsControl = (ItemsControl)sender; UIElement item = itemsControl.GetItemContainer((UIElement)e.OriginalSource); if (item != null) { ItemsControl itemParent = ItemsControl.ItemsControlFromItemContainer(item); SourceCollection = itemParent.ItemsSource ?? itemParent.Items; SourceItem = itemParent.ItemContainerGenerator.ItemFromContainer(item); SourceItems = itemsControl.GetSelectedItems(); // Some controls (I'm looking at you TreeView!) haven't updated their // SelectedItem by this point. Check to see if there 1 or less item in // the SourceItems collection, and if so, override the SelectedItems // with the clicked item. if (SourceItems.Cast <object>().Count() <= 1) { SourceItems = Enumerable.Repeat(SourceItem, 1); } VisualSourceItem = item; } else { SourceCollection = itemsControl.ItemsSource ?? itemsControl.Items; } } if (SourceItems == null) { SourceItems = Enumerable.Empty <object>(); } this.IsNotHandled = false; }
internal async void ResetItems(IPlayableList newOwner) { using (var releaser = await _PlaylistUpdateLock.LockAsync()) { PlayedItems.Clear(); ResetRandmizedItems(); _ItemsObservaeDisposer?.Dispose(); _ItemsObservaeDisposer = null; Playlist = newOwner; if (Playlist != null) { _ItemsObservaeDisposer = Playlist.PlaylistItems.CollectionChangedAsObservable() .Subscribe(async x => { using (var releaser2 = await _PlaylistUpdateLock.LockAsync()) { // 再生中アイテムが削除された時のプレイリストの動作 // 動画プレイヤーには影響を与えないこととする // 連続再生動作の継続性が確保できればOK ResetRandmizedItems(); if (PlaylistSettings.IsShuffleEnable) { CurrentIndex = 0; } else { CurrentIndex = Current == null ? 0 : SourceItems.IndexOf(Current); } RaisePropertyChanged(nameof(CanGoBack)); RaisePropertyChanged(nameof(CanGoNext)); } }); } RaisePropertyChanged(nameof(CanGoBack)); RaisePropertyChanged(nameof(CanGoNext)); } }