Beispiel #1
0
        //this is called when messages are sent 1 by 1
        public void send(HikePacket packet, int qos)
        {
            if (!isConnected())
            {
                /* only care about failures for messages we care about. */
                if (qos > 0)
                {
                    try
                    {
                        MqttDBUtils.addSentMessage(packet);
                    }
                    catch (Exception e)
                    {
                    }
                }
                this.connect();
                return;
            }
            PublishCB pbCB = null;

            if (qos > 0)
            {
                pbCB = new PublishCB(packet, this, qos, false);
            }
            mqttConnection.publish(this.topic + HikeConstants.PUBLISH_TOPIC,
                                   packet.Message, (QoS)qos == 0 ? QoS.AT_MOST_ONCE : QoS.AT_LEAST_ONCE,
                                   pbCB);
        }
Beispiel #2
0
        public void onConnected()
        {
            if (isConnected())
            {
                return;
            }
            setConnectionStatus(MQTTConnectionStatus.CONNECTED);
            subscribeToTopics(getTopics());
            if (!isRecursivePingScheduled)
            {
                scheduler.Schedule(new Action <Action <TimeSpan> >(recursivePingSchedule), TimeSpan.FromSeconds(HikeConstants.RECURSIVE_PING_INTERVAL));
            }

            /* Accesses the persistence object from the main handler thread */

            //TODO make it async
            List <HikePacket> packets = MqttDBUtils.getAllSentMessages();

            if (packets == null)
            {
                return;
            }
            Debug.WriteLine("MQTT MANAGER:: NUmber os unsent messages" + packets.Count);
            sendAllUnsentMessages(packets);
        }
Beispiel #3
0
 public void onFailure(Exception value)
 {
     hikeMqttManager.ping();
     if (packet != null)
     {
         if (qos > 0)
         {
             MqttDBUtils.addSentMessage(packet);
         }
     }
 }
Beispiel #4
0
 public void onSuccess()
 {
     if (packet != null)
     {
         if (qos > 0 && removeFromDBOnReceivingAck)
         {
             MqttDBUtils.removeSentMessage(packet.Timestamp);
         }
         if (packet.MessageId > 0) // represents ack for message that is recieved by server
         {
             JObject obj = new JObject();
             obj[HikeConstants.TYPE] = NetworkManager.SERVER_REPORT;
             obj[HikeConstants.DATA] = Convert.ToString(packet.MessageId);
             NetworkManager.Instance.onMessage(obj.ToString());
         }
     }
 }
Beispiel #5
0
        private static void instantiateClasses()
        {
            #region GROUP CACHE

            if (App.appSettings.Contains(App.GROUPS_CACHE)) // this will happen just once and no need to check version as this will work  for all versions
            {
                GroupManager.Instance.GroupCache = (Dictionary <string, List <GroupParticipant> >)App.appSettings[App.GROUPS_CACHE];
                GroupManager.Instance.SaveGroupCache();
                RemoveKeyFromAppSettings(App.GROUPS_CACHE);
            }

            #endregion
            #region PUBSUB
            Stopwatch st = Stopwatch.StartNew();
            if (App.HikePubSubInstance == null)
            {
                App.HikePubSubInstance = new HikePubSub(); // instantiate pubsub
            }
            st.Stop();
            long msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate Pubsub : {0}", msec);
            #endregion
            #region DBCONVERSATION LISTENER
            st.Reset();
            st.Start();
            if (App.DbListener == null)
            {
                App.DbListener = new DbConversationListener();
            }
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate DbListeners : {0}", msec);
            #endregion
            #region NETWORK MANAGER
            st.Reset();
            st.Start();
            App.NetworkManagerInstance = NetworkManager.Instance;
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate Network Manager : {0}", msec);
            #endregion
            #region MQTT MANAGER
            st.Reset();
            st.Start();
            if (App.MqttManagerInstance == null)
            {
                App.MqttManagerInstance = new HikeMqttManager();
            }
            if (ps == PageState.CONVLIST_SCREEN)
            {
                NetworkManager.turnOffNetworkManager = true;
                App.MqttManagerInstance.connect();
            }
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate MqttManager : {0}", msec);
            #endregion
            #region UI UTILS
            st.Reset();
            st.Start();
            App.UI_UtilsInstance = UI_Utils.Instance;
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate UI_Utils : {0}", msec);
            #endregion
            #region ANALYTICS
            st.Reset();
            st.Start();
            App.AnalyticsInstance = Analytics.Instance;
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate Analytics : {0}", msec);
            #endregion
            #region PUSH HELPER
            st.Reset();
            st.Start();
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate Push helper : {0}", msec);
            #endregion
            #region SMILEY
            if (ps == PageState.CONVLIST_SCREEN) //  this confirms tombstone
            {
                SmileyParser.Instance.initializeSmileyParser();
            }
            #endregion
            #region VIEW MODEL

            IS_VIEWMODEL_LOADED = false;
            if (_viewModel == null)
            {
                _latestVersion = Utils.getAppVersion();
                List <ConversationListObject> convList = null;

                if (!isNewInstall)// this has to be called for no new install case
                {
                    convList = GetConversations();
                }
                else // new install case
                {
                    convList = null;
                    App.WriteToIsoStorageSettings(HikeConstants.FILE_SYSTEM_VERSION, _latestVersion);// new install so write version
                }

                if (convList == null || convList.Count == 0)
                {
                    _viewModel = new HikeViewModel();
                }
                else
                {
                    _viewModel = new HikeViewModel(convList);
                }

                if (!isNewInstall && Utils.compareVersion(_latestVersion, _currentVersion) == 1) // shows this is update
                {
                    App.WriteToIsoStorageSettings(HikeConstants.AppSettings.NEW_UPDATE, true);
                    App.WriteToIsoStorageSettings(HikeConstants.FILE_SYSTEM_VERSION, _latestVersion);
                    if (Utils.compareVersion(_currentVersion, "1.5.0.0") != 1) // if current version is less than equal to 1.5.0.0 then upgrade DB
                    {
                        MqttDBUtils.UpdateToVersionOne();
                    }
                    if (Utils.compareVersion(_currentVersion, "1.7.1.2") != 1)// if current version is less than equal to 1.7.1.2 then show NUX
                    {
                        ps = PageState.UPGRADE_SCREEN;
                    }
                }
            }
            st.Stop();
            msec = st.ElapsedMilliseconds;
            Debug.WriteLine("APP: Time to Instantiate View Model : {0}", msec);
            IS_VIEWMODEL_LOADED = true;
            #endregion
            #region RateMyApp
            if (isNewInstall)
            {
                App.WriteToIsoStorageSettings(HikeConstants.AppSettings.APP_LAUNCH_COUNT, 1);
            }
            #endregion
            #region Post App Locale
            PostLocaleInfo();
            #endregion
        }