public LogisticChannel(string name) { this.name = name; AllChannels.Add(this); }
public void ResetChannelsAndChannelGroupsAndBuildState() { AllPresenceChannelsOrChannelGroups.Clear(); AllNonPresenceChannelsOrChannelGroups.Clear(); ChannelsAndChannelGroupsAwaitingConnectCallback.Clear(); AllChannels.Clear(); AllChannelGroups.Clear(); AllSubscribedChannelsAndChannelGroups.Clear(); HasChannelGroups = false; HasChannels = false; HasPresenceChannels = false; HasChannelsOrChannelGroups = false; CurrentSubscribedChannelsCount = 0; CurrentSubscribedChannelGroupsCount = 0; foreach (var ci in channelEntitiesDictionary) { if (ci.Value.IsSubscribed) { if (ci.Key.IsChannelGroup) { CurrentSubscribedChannelGroupsCount++; AllChannelGroups.Add(new ChannelEntity(ci.Key, ci.Value)); } else { CurrentSubscribedChannelsCount++; AllChannels.Add(new ChannelEntity(ci.Key, ci.Value)); } AllSubscribedChannelsAndChannelGroups.Add(new ChannelEntity(ci.Key, ci.Value)); if (ci.Key.IsPresenceChannel) { AllPresenceChannelsOrChannelGroups.Add(new ChannelEntity(ci.Key, ci.Value)); } else { AllNonPresenceChannelsOrChannelGroups.Add(new ChannelEntity(ci.Key, ci.Value)); } if (ci.Value.IsAwaitingConnectCallback) { ChannelsAndChannelGroupsAwaitingConnectCallback.Add(new ChannelEntity(ci.Key, ci.Value)); } } #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("ResetChannelsAndChannelGroupsAndBuildState: channelEntities subscription key/val {0} {1}", ci.Key.ChannelOrChannelGroupName, ci.Value.IsSubscribed), PNLoggingMethod.LevelInfo); #endif } if (CurrentSubscribedChannelGroupsCount > 0) { HasChannelGroups = true; } if (CurrentSubscribedChannelsCount > 0) { HasChannels = true; } if (AllPresenceChannelsOrChannelGroups.Count > 0) { HasPresenceChannels = true; } if (HasChannels || HasChannelGroups) { HasChannelsOrChannelGroups = true; } #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("PrevCompiledUserState: {0}", CompiledUserState), PNLoggingMethod.LevelInfo); #endif CompiledUserState = Helpers.BuildJsonUserState(AllSubscribedChannelsAndChannelGroups); #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CompiledUserState: {0}", CompiledUserState), PNLoggingMethod.LevelInfo); #endif }
public async Task LoadAllChannels(bool forceDownload = false) { AllChannels.Clear(); FavoriteChannels.Clear(); StorageFile file = null; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync("channels.json"); } catch { } string data = null; if (file == null || forceDownload) { data = await ChannelsHelper.DownloadJson(ChannelsHelper.CHANNELS_URL); if (data != null) { file = await ApplicationData.Current.LocalFolder.CreateFileAsync("channels.json", CreationCollisionOption.ReplaceExisting); var writer = new StreamWriter(await file.OpenStreamForWriteAsync()); await writer.WriteAsync(data); writer.Dispose(); } } else { var reader = new StreamReader(await file.OpenStreamForReadAsync()); data = await reader.ReadToEndAsync(); reader.Dispose(); } if (data == null) { return; } var channels = JsonConvert.DeserializeObject(data) as JContainer; foreach (var asset in ChannelsHelper.ChannelsAssets) { var item = new ChannelItem(); item.Key = asset.Key; item.Image = asset.Value[0]; item.Color1 = asset.Value[1]; item.Color2 = asset.Value[2]; var channel = channels.FirstOrDefault((element) => element["key"].Value <string>() == asset.Key); if (channel != null) { item.ID = channel.Value <int>("id"); item.Name = channel.Value <string>("name"); item.Description = channel.Value <string>("description"); } LoadChannelStreams(item); LoadTrackHistory(item); AllChannels.Add(item); } if (AllChannels.Count > 2) { AllChannels[0].Next = AllChannels[1]; AllChannels[AllChannels.Count - 1].Prev = AllChannels[AllChannels.Count - 2]; } for (int i = 1; i < AllChannels.Count - 1; i++) { AllChannels[i].Prev = AllChannels[i - 1]; AllChannels[i].Next = AllChannels[i + 1]; } await LoadFavoriteChannels(); }
public void AddChannel(Channel channel) { AllChannels.Add(channel); }