private object SubscribeData(TopicData topicData)
 {
     if (isSolaceConnected)
     {
         try
         {
             Task <bool> subTask   = Task.Run(async() => await solaceConnection.SubscribeAsync(topicData.SolaceTopic).ConfigureAwait(false));
             var         subResult = subTask.Result;
             if (subResult)
             {
                 solaceTopics.Add(topicData.SolaceTopic, 1);
                 logger.Info("Subscription added for - {0}", topicData.ToString());
                 return(GetData(topicData));
             }
             else
             {
                 logger.Error("Failed to add subscription on Solace for data - {0}", topicData.ToString());
                 return(ERROR_STATUS);
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex, "Exception while subscribing for data - {0}", topicData.ToString());
             return(ERROR_STATUS);
         }
     }
     else
     {
         logger.Trace("SolaceRTD is not connected to a Solace PubSub+ Broker - {0}", topicData.ToString());
         return(NOT_CONNECTED_STATUS);
     }
 }
        public dynamic ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
        {
            if (Strings == null || Strings.Length != 2)
            {
                return(ERROR_STATUS);
            }

            try
            {
                string solaceTopic = Strings.GetValue(0).ToString();
                string fieldName   = Strings.GetValue(1).ToString();
                if (string.IsNullOrWhiteSpace(solaceTopic) || string.IsNullOrWhiteSpace(fieldName))
                {
                    logger.Error("Required Solace topic or fieldname parameter missing for Solace RTD function");
                    return(ERROR_STATUS);
                }

                var topicData = new TopicData {
                    SolaceTopic = solaceTopic, FieldName = fieldName
                };

                // Add the solace topic to the list of data we need to refresh
                if (!topicDatas.ContainsKey(TopicID))
                {
                    logger.Debug("Adding topic data - " + topicData.ToString());
                    topicDatas.Add(TopicID, topicData);
                }

                if (solaceTopics.ContainsKey(topicData.SolaceTopic))
                {
                    // We are already subscribed to the solace topic
                    // We are also keeping track of how many time we are requesting data from the
                    // same topic, so we can unsubscribe to the topic when reference is zero.
                    solaceTopics[topicData.SolaceTopic] += 1;
                    return(GetData(topicData));
                }
                else
                {
                    return(SubscribeData(topicData));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception on ServerStart()");
            }
            return(ERROR_STATUS);
        }
        private bool UnsubscribeData(TopicData topicData)
        {
            var result = false;

            if (isSolaceConnected)
            {
                try
                {
                    Task <bool> subTask = Task.Run(async() => await solaceConnection.UnsubscribeAsync(topicData.SolaceTopic).ConfigureAwait(false));
                    result = subTask.Result;
                    if (result)
                    {
                        logger.Info("Removed Solace subscription to topic - {0}", topicData.SolaceTopic);
                    }
                    else
                    {
                        logger.Error("Failed to remove subscription on Solace for topic - {0}", topicData.SolaceTopic);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exception while unsubscribing for topic - {0}", topicData.SolaceTopic);
                }
            }
            else
            {
                logger.Trace("SolaceRTD is not connected to a Solace PubSub+ Broker - {0}", topicData.ToString());
            }

            return(result);
        }