コード例 #1
0
        private OneUpdateResult bg_oneUpdate()
        {
            OneUpdateResult ret = new OneUpdateResult();

            // 1) gather data
            IxFaces.iDsp.FileLog_Debug("bg_oneUpdate...");
            using (_8AndroidCommunicator com = IxFaces.iUpdater.Android())
            {
                AndroidEndPoint = com.GetEndPointInfo();
            }
            IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eReportEndPoint, AndroidEndPoint));

            List <string> fromServer = bg_nn_serverUpdate();

            ret.TelNoServer = fromServer.Count;
            IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eReportTelNumbers, 0, ret.TelNoServer));

            List <string> fromAndroid = bg_nn_androidUpdate();

            ret.TelNoAndroid = fromAndroid.Count;
            IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eReportTelNumbers, ret.TelNoAndroid, 0));

            TelListController.VerifyResult verRes = null;

            using (var _lock = TheInfoList.GetLock())
            {
                // 2) clear existing data
                _lock.Locked.Clear();

                // 3) recalc
                _lock.Locked.Merge(fromServer, fromAndroid, true);
                verRes = _lock.Locked.Verify();
            }
            IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eReportTelNumberMerge, verRes));
            TelControllerReportToFile(verRes.GetFullReport());

            if (verRes.OnlyOnServer.Count > 0)
            {
                using (_8AndroidCommunicator com = IxFaces.iUpdater.Android())
                {
                    foreach (string needUpdate in verRes.OnlyOnServer)
                    {
                        com.SetCommand(needUpdate, IxFaces.iDsp);
                        using (var _lock = TheInfoList.GetLock())
                        {
                            _lock.Locked.AddOneAndroid(needUpdate);
                        }
                        ret.AddedTelToAndroid = true;
                    }
                }
            }
            LastUpdated = DateTime.UtcNow;
            if (ret.AddedTelToAndroid)
            {
                LastUpdated = DateTime.MinValue;
            }
            return(ret);
        }
コード例 #2
0
        private void bg_updateThread()
        {
            while (StopRequest.WaitOne(5000, false) == false)
            {
                // wait until we are due
                bool interfaceAvailable = false;

                try
                {
                    if (TimeToNextUpdate.Ticks == 0)
                    {
                        // due now
                        using (var _lock = TheInfoList.GetLock())
                        {
                            interfaceAvailable = IxFaces != null;
                        }

                        if (!interfaceAvailable)
                        {
                            // no interface
                            StopRequest.WaitOne(1000, false);
                        }
                        else
                        {
                            // interface ok
                            IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eStart));
                            OneUpdateResult upRes = bg_oneUpdate();
                            BackgroundRunning.Set();
                            IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eDone, true, NextUpdateScheduledFor));
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (IxFaces != null)
                    {
                        IxFaces.iDsp.FileLog_Error("Background thread Exception: " + ex.Message);
                        IxFaces.iDsp.FileLog_Debug(ex.StackTrace);
                        IxFaces.iDsp.AddLine2(new DetailedData_AndroidCommunication_BT(DetailedData_AndroidCommunication_BT.eType.eDone, false, NextUpdateScheduledFor));
                        IxFaces.iDsp.Delay(5000);
                    }
                }
            }
        }