/// <summary> /// Opens a channel or switches to the channel if already opened. /// </summary> /// <exception cref="ChannelNotFoundException">If the name of the specifed channel was not found this exception will be thrown.</exception> /// <param name="name"></param> public void OpenChannel(string name) { if (name == null) throw new ArgumentNullException(nameof(name)); CurrentChannel.Value = AvailableChannels.FirstOrDefault(c => c.Name == name) ?? throw new ChannelNotFoundException(name); }
/// <summary> /// Initializes a new instance of the <see cref="SelectChannelsViewModel" /> class. /// </summary> /// <param name="runtime">The runtime.</param> /// <param name="availableChannels">The available channels.</param> /// <param name="indexChannel">The index channel.</param> /// <param name="selectedChannels">The defaulted selected channels.</param> public SelectChannelsViewModel(IRuntimeService runtime, List <LogCurveItem> availableChannels, string indexChannel, List <LogCurveItem> selectedChannels = null) { Runtime = runtime; DisplayName = $"{_dialogTitlePrefix} - Select Channels"; // Create a selectedChannels list if one was not sent in if (selectedChannels == null) { selectedChannels = new List <LogCurveItem>(); } // If the selectedChannels list does not contain the index channel //... then find it in the availableChannels and add it to the selectedChannels if (!selectedChannels.Any(l => l.Equals(indexChannel))) { IndexChannel = availableChannels.FirstOrDefault(a => a.Equals(indexChannel)); selectedChannels.Add(IndexChannel); } // Get the IndexChannel LogCurveItem from the selectedChannels IndexChannel = selectedChannels.FirstOrDefault(a => a.Equals(indexChannel)); availableChannels.ForEach(c => AvailableChannels.Add(c)); SelectedChannels = new ObservableCollection <LogCurveItem>(selectedChannels); RemoveSelectedFromAvailableChannels(); MoveToTop(SelectedChannels, IndexChannel); }
/// <summary> /// Find an existing channel instance for the provided channel. Lookup is performed basd on ID. /// The provided channel may be used if an existing instance is not found. /// </summary> /// <param name="lookup">A candidate channel to be used for lookup or permanently on lookup failure.</param> /// <param name="addToAvailable">Whether the channel should be added to <see cref="AvailableChannels"/> if not already.</param> /// <param name="addToJoined">Whether the channel should be added to <see cref="JoinedChannels"/> if not already.</param> /// <returns>The found channel.</returns> private Channel getChannel(Channel lookup, bool addToAvailable = false, bool addToJoined = false) { Channel found = null; bool lookupCondition(Channel ch) => lookup.Id > 0 ? ch.Id == lookup.Id : lookup.Name == ch.Name; var available = AvailableChannels.FirstOrDefault(lookupCondition); if (available != null) found = available; var joined = JoinedChannels.FirstOrDefault(lookupCondition); if (found == null && joined != null) found = joined; if (found == null) { found = lookup; // if we're using a channel object from the server, we want to remove ourselves from the users list. // this is because we check the first user in the channel to display a name/icon on tabs for now. var foundSelf = found.Users.FirstOrDefault(u => u.Id == api.LocalUser.Value.Id); if (foundSelf != null) found.Users.Remove(foundSelf); } if (joined == null && addToJoined) joinedChannels.Add(found); if (available == null && addToAvailable) availableChannels.Add(found); return found; }
private void fetchUpdates() { if (fetchReq != null) { return; } fetchReq = new GetUpdatesRequest(lastMessageId); fetchReq.Success += updates => { if (updates?.Presence != null) { foreach (var channel in updates.Presence) { addChannel(AvailableChannels.Find(c => c.Id == channel.Id)); } foreach (var group in updates.Messages.GroupBy(m => m.ChannelId)) { careChannels.Find(c => c.Id == group.Key)?.AddNewMessages(group.ToArray()); } lastMessageId = updates.Messages.LastOrDefault()?.Id ?? lastMessageId; } fetchReq = null; }; fetchReq.Failure += delegate { fetchReq = null; }; api.Queue(fetchReq); }
public void StopSearching() { foreach (var watcher in _channelWatchers) { watcher.Stop(); } AvailableChannels.Clear(); }
private void ChannelWatcher_DeviceRemovedEvent(object sender, IChannel e) { lock (this) { if (AvailableChannels.Contains(e)) { AvailableChannels.Remove(e); } } }
private void ChannelWatcher_DeviceFoundEvent(object sender, IChannel e) { lock (this) { if (!AvailableChannels.Contains(e)) { e.Connected += channel_Connected; AvailableChannels.Add(e); } } }
public ConfigurationModel( List <Channel> availableChannels, List <OfficeClientEdition> availableEditions) { this.AddedLanguages = new ObservableCollection <Language>(); this.ExcludedProducts = new ObservableCollection <Product>(); this.EnableUpdates = true; this.AvailableChannels = availableChannels; this.AvailableEditions = availableEditions; this.SelectedChannel = AvailableChannels.FirstOrDefault(); this.SelectedEdition = AvailableEditions.FirstOrDefault(); }
private void ChannelWatcher_DeviceFoundEvent(object sender, IChannel e) { lock (this) { if (!AvailableChannels.Contains(e)) { if (!AvailableChannels.Where(channel => channel.Id == e.Id).Any()) { AvailableChannels.Add(e); } } } }
private void StatisticsOnPropertyChanged(object sender, PropertyChangedEventArgs args) { switch (args.PropertyName) { case nameof(StatisticsModel.Channel): SelectedChannel = AvailableChannels.Find(box => box.Cargo == models.Statistics.Channel); break; case nameof(StatisticsModel.ColorSpace): SelectedColorSpace = AvailableColorSpaces.Find(box => box.Cargo == models.Statistics.ColorSpace); break; } }
public StatisticsViewModel(ModelsEx models) { this.models = models; var settingsValue = models.Settings.StatisticsChannel; selectedChannel = AvailableChannels.Find(v => v.Cargo == settingsValue); ChannelDescription = channelDescriptions[(int)settingsValue]; viewModels = new StatisticViewModel[models.NumPipelines]; for (int i = 0; i < viewModels.Length; ++i) { viewModels[i] = new StatisticViewModel(i, models, this); } models.Window.Window.TabControl.SelectionChanged += TabControlOnSelectionChanged; SSIM = new SSIMsViewModel(models); }
private void RemoveSelectedFromAvailableChannels() { if (SelectedChannels.Count == 0) { return; } var alreadySelectedCurves = new List <LogCurveItem>(); AvailableChannels.ForEach(a => { if (SelectedChannels.FirstOrDefault(sc => sc.Mnemonic.EqualsIgnoreCase(a.Mnemonic)) != null) { alreadySelectedCurves.Add(a); } }); alreadySelectedCurves.ForEach(r => AvailableChannels.Remove(r)); }
/// <summary> /// Opens the most recently closed channel that has not already been reopened, /// Works similarly to reopening the last closed tab on a web browser. /// </summary> public void JoinLastClosedChannel() { // This loop could be eliminated if the join channel operation ensured that every channel joined // is removed from the closedChannels list, but it'd require a linear scan of closed channels on every join. // To keep the overhead of joining channels low, just lazily scan the list of closed channels locally. while (closedChannels.Count > 0) { ClosedChannel lastClosedChannel = closedChannels.Last(); closedChannels.RemoveAt(closedChannels.Count - 1); // If the user has already joined the channel, try the next one if (joinedChannels.FirstOrDefault(lastClosedChannel.Matches) != null) { continue; } Channel lastChannel = AvailableChannels.FirstOrDefault(lastClosedChannel.Matches); if (lastChannel != null) { // Channel exists as an available channel, directly join it CurrentChannel.Value = JoinChannel(lastChannel); } else if (lastClosedChannel.Type == ChannelType.PM) { // Try to get user in order to open PM chat users.GetUserAsync((int)lastClosedChannel.Id).ContinueWith(u => { if (u.Result == null) { return; } Schedule(() => CurrentChannel.Value = JoinChannel(new Channel(u.Result))); }); } return; } }
private void ChannelWatcher_ClearDevices(object sender, System.EventArgs e) { AvailableChannels.Clear(); }
/// <summary> /// Selects all channels from Available and moves them to Selected /// </summary> public void SelectAllChannels() { var available = AvailableChannels.ToList().OrderBy(c => c.Mnemonic); available.ForEach(a => MoveChannel(a, AvailableChannels, SelectedChannels)); }