internal bool CreateChannelEntityAndAddToSubscribe(PNOperationType type, List <string> rawChannels, bool isChannelGroup, bool unsubscribeCheck, ref List <ChannelEntity> channelEntities, PubNubUnity pn) { bool bReturn = false; for (int index = 0; index < rawChannels.Count; index++) { string channelName = rawChannels[index].Trim(); if (channelName.Length > 0) { if ((type == PNOperationType.PNPresenceOperation) || (type == PNOperationType.PNPresenceUnsubscribeOperation)) { channelName = string.Format("{0}{1}", channelName, Utility.PresenceChannelSuffix); } #if (ENABLE_PUBNUB_LOGGING) LogChannelEntitiesDictionary(); this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateChannelEntityAndAddToSubscribe: channel={0}", channelName), PNLoggingMethod.LevelInfo); #endif //create channelEntity ChannelEntity ce = Helpers.CreateChannelEntity(channelName, true, isChannelGroup, null, this.PubNubInstance.PNLog); bool channelIsSubscribed = false; if (ChannelEntitiesDictionary.ContainsKey(ce.ChannelID)) { channelIsSubscribed = ChannelEntitiesDictionary [ce.ChannelID].IsSubscribed; } if (unsubscribeCheck) { if (channelIsSubscribed) { channelEntities.Add(ce); bReturn = true; } #if (ENABLE_PUBNUB_LOGGING) else { string message = string.Format("{0}Channel Not Subscribed", (ce.ChannelID.IsPresenceChannel) ? "Presence " : ""); this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateChannelEntityAndAddToSubscribe: channel={0} response={1}", channelName, message), PNLoggingMethod.LevelInfo); } #endif } else { if (!channelIsSubscribed) { channelEntities.Add(ce); bReturn = true; } #if (ENABLE_PUBNUB_LOGGING) else { string message = string.Format("{0}Already subscribed", (ce.ChannelID.IsPresenceChannel) ? "Presence " : ""); this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateChannelEntityAndAddToSubscribe: channel={0} response={1}", channelName, message), PNLoggingMethod.LevelInfo); } #endif } } #if (ENABLE_PUBNUB_LOGGING) else { string message = "Invalid Channel Name"; if (isChannelGroup) { message = "Invalid Channel Group Name"; } this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateChannelEntityAndAddToSubscribe: channel={0} response={1}", channelName, message), PNLoggingMethod.LevelInfo); } #endif } return(bReturn); }
public static PNStatus CreatePNStatus(PNStatusCategory category, string errorString, Exception errorException, bool error, PNOperationType operation, ChannelEntity channelEntity, RequestState pnRequestState, PubNubUnity pnUnity) { PNErrorData errorData = null; if ((!string.IsNullOrEmpty(errorString)) || (errorException != null)) { errorData = new PNErrorData(); errorData.Info = errorString; errorData.Ex = errorException; } List <string> affectedChannels = null; List <string> affectedChannelGroups = null; if (channelEntity.ChannelID.IsChannelGroup) { affectedChannelGroups = new List <string>(); affectedChannelGroups.Add(channelEntity.ChannelID.ChannelOrChannelGroupName); } else { affectedChannels = new List <string>(); affectedChannels.Add(channelEntity.ChannelID.ChannelOrChannelGroupName); } return(CreatePNStatus(category, errorData, error, operation, affectedChannels, affectedChannelGroups, pnRequestState, pnUnity)); }