Beispiel #1
0
        public async Task <DownloadDataChangesResult> CheckForDataDownloadChangesAsync(
            string v_sCompanyName,
            string v_sPurpose,
            ObservableCollection <DownloadDataChange> v_cSubProjects,
            bool v_bCheckForNewSubProjects,
            string v_sAuthID,
            string v_sToken)
        {
            m_wcfClient = new WcfExt116.ServiceClient();
            DownloadDataChangesResult result = new DownloadDataChangesResult();

            try
            {
                ObservableCollection <WcfExt116.DownloadDataChange> cSubProjects = new ObservableCollection <WcfExt116.DownloadDataChange>();
                foreach (DownloadDataChange o in v_cSubProjects)
                {
                    WcfExt116.DownloadDataChange oND = new WcfExt116.DownloadDataChange();
                    oND.ActivitiesTable_ModDate = o.ActivitiesTable_ModDate;
                    oND.Delivery_ModDate        = o.Delivery_ModDate;
                    oND.ProjTable_ModDate       = o.ProjTable_ModDate;
                    oND.sProjectNo    = o.sProjectNo;
                    oND.sSubProjectNo = o.sSubProjectNo;
                    oND.Notes         = new ObservableCollection <WcfExt116.clsRealtimeNoteKeyValues>();
                    oND.Units         = new ObservableCollection <WcfExt116.UnitDetails>();
                    cSubProjects.Add(oND);
                }
                WcfExt116.DownloadDataChangesResult sResult = await m_wcfClient.CheckForDataDownloadChangesAsync(
                    v_sCompanyName,
                    v_sPurpose,
                    cSubProjects,
                    v_bCheckForNewSubProjects,
                    v_sAuthID,
                    v_sToken);

                if (sResult.bSuccessfull == true)
                {
                    result.bSuccessfull = sResult.bSuccessfull;
                    result.pdChanged    = new ObservableCollection <SubProjectData>();
                    result.sDeleted     = new ObservableCollection <string>();
                    foreach (WcfExt116.SubProjectData o in sResult.pdChanged)
                    {
                        SubProjectData oSPD = new SubProjectData();

                        oSPD.ABPAWORDERCOMPLETEDDATE                 = o.ABPAWORDERCOMPLETEDDATE;
                        oSPD.ABPAWORIGINALSUBPROJECTID               = o.ABPAWORIGINALSUBPROJECTID;
                        oSPD.ABPAXACCESSEQUIPMENT                    = o.ABPAXACCESSEQUIPMENT;
                        oSPD.ABPAXASBESTOSPRESUMED                   = o.ABPAXASBESTOSPRESUMED;
                        oSPD.ABPAXFLOORLEVEL                         = o.ABPAXFLOORLEVEL;
                        oSPD.ABPAXHealthSaferyIncompleteUploadedBy   = o.ABPAXHealthSaferyIncompleteUploadedBy;
                        oSPD.ABPAXHealthSafetyIncomplete             = o.ABPAXHealthSafetyIncomplete;
                        oSPD.ABPAXHealthSafetyIncompleteDateUploaded = o.ABPAXHealthSafetyIncompleteDateUploaded;
                        oSPD.ABPAXINSTALLATIONTEAM                   = o.ABPAXINSTALLATIONTEAM;
                        oSPD.ABPAXINSTALLATIONTYPE                   = o.ABPAXINSTALLATIONTYPE;
                        oSPD.ABPAXINSTALLLETTERREQUIRED              = o.ABPAXINSTALLLETTERREQUIRED;
                        oSPD.ABPAXINSTALLLETTERSENTDATE01            = o.ABPAXINSTALLLETTERSENTDATE01;
                        oSPD.ABPAXINSTALLLETTERSENTDATE02            = o.ABPAXINSTALLLETTERSENTDATE02;
                        oSPD.ABPAXINSTALLLETTERSENTDATE03            = o.ABPAXINSTALLLETTERSENTDATE03;
                        oSPD.ABPAXINSTALLNEXTDAYSMS                  = o.ABPAXINSTALLNEXTDAYSMS;
                        oSPD.ABPAXINSTALLSMSSENT                     = o.ABPAXINSTALLSMSSENT;
                        oSPD.ABPAXINTERNDAMAGE                       = o.ABPAXINTERNDAMAGE;
                        oSPD.ABPAXPERMANENTGASVENT                   = o.ABPAXPERMANENTGASVENT;
                        oSPD.ABPAXPUBLICPROTECT                      = o.ABPAXPUBLICPROTECT;
                        oSPD.ABPAXSERVICESTOMOVE                     = o.ABPAXSERVICESTOMOVE;
                        oSPD.ABPAXSTRUCTURALFAULTS                   = o.ABPAXSTRUCTURALFAULTS;
                        oSPD.ABPAXWINDOWBOARD                        = o.ABPAXWINDOWBOARD;
                        oSPD.ABPAXWRKACCRESTRICTIONS                 = o.ABPAXWRKACCRESTRICTIONS;
                        oSPD.DeliveryCity   = o.DeliveryCity;
                        oSPD.DeliveryStreet = o.DeliveryStreet;
                        oSPD.Delivery_ConfirmedAppointmentIndicator = o.Delivery_ConfirmedAppointmentIndicator;
                        oSPD.Delivery_EndDateTime      = o.Delivery_EndDateTime;
                        oSPD.Delivery_ModifiedDateTime = o.Delivery_ModifiedDateTime;
                        oSPD.Delivery_StartDateTime    = o.Delivery_StartDateTime;
                        oSPD.DlvState                         = o.DlvState;
                        oSPD.DlvZipCode                       = o.DlvZipCode;
                        oSPD.Email                            = o.Email;
                        oSPD.EndDateTime                      = o.EndDateTime;
                        oSPD.MODIFIEDDATETIME                 = o.MODIFIEDDATETIME;
                        oSPD.Mxm1002InstallStatus             = o.Mxm1002InstallStatus;
                        oSPD.Mxm1002ProgressStatus            = o.Mxm1002ProgressStatus;
                        oSPD.MXM1002SequenceNr                = o.MXM1002SequenceNr;
                        oSPD.MXM1002TrfDate                   = o.MXM1002TrfDate;
                        oSPD.MXMAlternativeContactMobileNo    = o.MXMAlternativeContactMobileNo;
                        oSPD.MXMAlternativeContactName        = o.MXMAlternativeContactName;
                        oSPD.MXMAlternativeContactTelNo       = o.MXMAlternativeContactTelNo;
                        oSPD.MXMConfirmedAppointmentIndicator = o.MXMConfirmedAppointmentIndicator;
                        oSPD.MXMContactBySMS                  = o.MXMContactBySMS;
                        oSPD.MXMDisabledAdaptionsRequired     = o.MXMDisabledAdaptionsRequired;
                        oSPD.MXMDoorChoiceFormReceived        = o.MXMDoorChoiceFormReceived;
                        oSPD.MXMNextDaySMS                    = o.MXMNextDaySMS;
                        oSPD.MxmProjDescription               = o.MxmProjDescription;
                        oSPD.MXMPropertyType                  = o.MXMPropertyType;
                        oSPD.MXMResidentMobileNo              = o.MXMResidentMobileNo;
                        oSPD.MXMResidentName                  = o.MXMResidentName;
                        oSPD.MXMSMSSent                       = o.MXMSMSSent;
                        oSPD.MXMSpecialResidentNote           = o.MXMSpecialResidentNote;
                        oSPD.MXMSurveyletterRequired          = o.MXMSurveyletterRequired;
                        oSPD.MXMSurveyLetterSentDate01        = o.MXMSurveyLetterSentDate01;
                        oSPD.MXMSurveyLetterSentDate02        = o.MXMSurveyLetterSentDate02;
                        oSPD.MXMSurveyLetterSentDate03        = o.MXMSurveyLetterSentDate03;
                        oSPD.MXMSurveyorName                  = o.MXMSurveyorName;
                        oSPD.MXMSurveyorPCTag                 = o.MXMSurveyorPCTag;
                        oSPD.MXMSurveyorProfile               = o.MXMSurveyorProfile;
                        oSPD.MXMTelephoneNo                   = o.MXMTelephoneNo;
                        oSPD.Name  = o.Name;
                        oSPD.Notes = new ObservableCollection <NoteDetails>();
                        if (o.Notes != null)
                        {
                            foreach (WcfExt116.NoteDetails vo in o.Notes)
                            {
                                NoteDetails oND = new NoteDetails();
                                oND.AXRecID     = vo.AXRecID;
                                oND.DeviceIDKey = vo.DeviceIDKey;
                                oND.InputDate   = vo.InputDate;
                                oND.NoteText    = vo.NoteText;
                                oND.NoteType    = vo.NoteType;
                                oND.ProjectNo   = vo.ProjectNo;
                                oND.Purpose     = vo.Purpose;
                                oND.UserName    = vo.UserName;
                                oND.UserProfile = vo.UserProfile;
                                oSPD.Notes.Add(oND);
                            }
                        }
                        oSPD.ParentID = o.ParentID;
                        oSPD.ProjId   = o.ProjId;
                        oSPD.Purpose  = o.Purpose;
                        oSPD.SMMActivities_MODIFIEDDATETIME = o.SMMActivities_MODIFIEDDATETIME;
                        oSPD.StartDateTime = o.StartDateTime;
                        oSPD.Status        = o.Status;
                        oSPD.Units         = new ObservableCollection <UnitDetails>();
                        if (o.Units != null)
                        {
                            foreach (WcfExt116.UnitDetails vo in o.Units)
                            {
                                UnitDetails oUD = new UnitDetails();
                                oUD.dInstalledDate   = vo.dInstalledDate;
                                oUD.iInstalledStatus = vo.iInstalledStatus;
                                oUD.iUNITNUMBER      = vo.iUNITNUMBER;
                                oUD.sITEMID          = vo.sITEMID;
                                oUD.sSTYLE           = vo.sSTYLE;
                                oUD.sUNITLOCATION    = vo.sUNITLOCATION;
                                oSPD.Units.Add(oUD);
                            }
                        }
                        oSPD.URL = o.URL;
                        result.pdChanged.Add(oSPD);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Check for data changes to download.
        /// </summary>
        /// <returns></returns>
        public async Task <bool> CheckForDataChanges(bool v_bBackgroundTask)
        {
            bool bSaveOK = false;

            DataAccess.SaveSubProjectDataResult srResult;
            bool bConnected     = false;
            bool bErrorOccurred = false;
            bool bReturnStatus  = true;

            WcfExt116 cAX = null;
            //cDataAccess cDataDB = null;

            ObservableCollection <DownloadDataChange> cSubProjects = null;
            DownloadDataChange cSubProject;
            List <SubProjectSyncUpdateValues>     cSubProjectDates    = null;
            ObservableCollection <SubProjectData> cSubProjectsChanged = null;

            //v1.0.10 - Data change result object.
            DownloadDataChangesResult dcResult = null;

            string sProjectStatus    = string.Empty;
            string sSubProjectStatus = string.Empty;

            int  iSubProjectLimit        = -1;
            bool bCheckForNewSubProjects = true;

            int iSubProjectsAdded   = 0;
            int iSubProjectsDeleted = 0;

            List <cProjectNotesTable> cNotes = null;
            RealtimeNoteKeyValues     cNoteKey;
            List <cUnitsTable>        cUnits = null;
            UnitDetails udUnitDetail;

            try
            {
                //If called from background task then go off and fetch projects to sync
                if (v_bBackgroundTask == true)
                {
                    iSubProjectLimit        = 2;
                    bCheckForNewSubProjects = false;

                    Syncing.p_ocProjectsToSync = this.m_cData.FetchProjectsToSync();
                }

                //Update screen.
                if (v_bBackgroundTask == false)
                {
                    this.UpdateMessage("Checking connection.");


                    //Check we are connected first
                    bConnected = await this.m_cSetting.IsAXSystemAvailable(false);

                    if (bConnected == false)
                    {
                        //Update screen.
                        if (v_bBackgroundTask == false)
                        {
                            this.UpdateMessage("Checking failed.");
                        }
                        ;

                        return(false);
                    }
                }


                if (Syncing.p_ocProjectsToSync != null)
                {
                    int iProjectCount    = 0;
                    int iSubProjectCount = 0;

                    cAX = new WcfExt116();

                    string sLastProjectNo = String.Empty;

                    foreach (ProjectSearch cProject in Syncing.p_ocProjectsToSync)
                    {
                        bErrorOccurred = false;
                        iProjectCount += 1;

                        //Update screen.
                        if (v_bBackgroundTask == false)
                        {
                            sProjectStatus = "Checking project (" + iProjectCount.ToString() + " of " + Syncing.p_ocProjectsToSync.Count.ToString() + ") " + cProject.ProjectNo;

                            this.UpdateMessage(sProjectStatus);

                            //this.SubProjectStatusUpdate(this, new cSyncEventParamProjectStatus(sLastProjectNo, cProject.ProjectNo, iSubProjectsAdded, iSubProjectsDeleted, true));
                        }


                        iSubProjectsAdded   = 0;
                        iSubProjectsDeleted = 0;

                        try
                        {
                            cSubProjects = new ObservableCollection <DownloadDataChange>();

                            cSubProjectDates = this.m_cData.FetchSubProjectUpdateDateTime(cProject.ProjectNo, iSubProjectLimit);
                            foreach (SubProjectSyncUpdateValues cSubProjectValue in cSubProjectDates)
                            {
                                cSubProject               = new DownloadDataChange();
                                cSubProject.sProjectNo    = cProject.ProjectNo;
                                cSubProject.sSubProjectNo = cSubProjectValue.SubProjectNo;

                                cSubProject.Notes = new ObservableCollection <RealtimeNoteKeyValues>();

                                if (cSubProjectValue.ModifiedDateTime.HasValue == true)
                                {
                                    cSubProject.ProjTable_ModDate = cSubProjectValue.ModifiedDateTime.Value;
                                }

                                if (cSubProjectValue.SMMActivities_MODIFIEDDATETIME.HasValue == true)
                                {
                                    cSubProject.ActivitiesTable_ModDate = cSubProjectValue.SMMActivities_MODIFIEDDATETIME.Value;
                                }

                                //v1.0.12 - Delivery modified date time
                                if (cSubProjectValue.Delivery_ModifiedDateTime.HasValue == true)
                                {
                                    cSubProject.Delivery_ModDate = cSubProjectValue.Delivery_ModifiedDateTime.Value;
                                }


                                //Add notes to upload.
                                cNotes = this.m_cData.GetSubProjectNotesData(cSubProjectValue.SubProjectNo);
                                foreach (cProjectNotesTable cProjNote in cNotes)
                                {
                                    cNoteKey             = new RealtimeNoteKeyValues();
                                    cNoteKey.DeviceIDKey = cProjNote.IDKey;
                                    cNoteKey.NotesRecID  = cProjNote.AXRecID;
                                    cNoteKey.ProjectNo   = cSubProjectValue.SubProjectNo;

                                    cSubProject.Notes.Add(cNoteKey);
                                }

                                //Units are only used for the installers app.
                                if (DependencyService.Get <ISettings>().IsThisTheSurveyorApp() == false)
                                {
                                    cSubProject.Units = new ObservableCollection <UnitDetails>();

                                    //Add units to upload.
                                    cUnits = this.m_cData.FetchUnitsForSubProject(cSubProject.sSubProjectNo);
                                    foreach (cUnitsTable cUnitRow in cUnits)
                                    {
                                        udUnitDetail = new UnitDetails();
                                        udUnitDetail.iInstalledStatus = cUnitRow.InstalledStatus;
                                        udUnitDetail.iUNITNUMBER      = cUnitRow.UnitNo;
                                        udUnitDetail.sITEMID          = cUnitRow.ItemID;
                                        udUnitDetail.sSTYLE           = cUnitRow.Style;
                                        udUnitDetail.sUNITLOCATION    = cUnitRow.UnitLocation;

                                        cSubProject.Units.Add(udUnitDetail);
                                    }
                                }

                                cSubProjects.Add(cSubProject);
                            }


                            //v1.0.10 - Retry on failed attempts.
                            int iAttempts = 0;
                            do
                            {
                                try
                                {
                                    dcResult = null;
                                    dcResult = await cAX.CheckForAXDataChanges(cSubProjects, bCheckForNewSubProjects);

                                    if (dcResult != null)
                                    {
                                        if (dcResult.bSuccessfull == true)
                                        {
                                            cSubProjectsChanged = dcResult.pdChanged;
                                        }
                                    }
                                    if (cSubProjectsChanged != null)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        throw new Exception("CheckForAXDataChanges returned null");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    bErrorOccurred = true;

                                    iAttempts++;
                                    if (v_bBackgroundTask == false)
                                    {
                                        //this.ProjectSyncError(this, new cSyncEventErrorParams(ex.Message, cProject.ProjectNo));
                                    }
                                    ;
                                }
                            } while (iAttempts < 3); //Try 3 times.


                            //Sub projects to update.
                            if (cSubProjectsChanged != null)
                            {
                                foreach (SubProjectData cData in cSubProjectsChanged)
                                {
                                    srResult = this.m_cData.SaveSubProjectData(cProject.ProjectNo, cProject.ProjectName, cData);
                                    bSaveOK  = srResult.bSavedOK;

                                    //If sub project added then increase count.
                                    if (bSaveOK == true)
                                    {
                                        if (srResult.bProjectAdded == true)
                                        {
                                            iSubProjectsAdded += 1;
                                        }
                                    }
                                }

                                //v1.0.18 - No need to update these, takes up too much time.
                                //v1.0.1 - Update the sub projects passed up to say they have synced.
                                //cProjectTable cSubProjectSync;
                                //foreach (wcfAX.DownloadDataChange ddcSub in cSubProjects)
                                //{

                                //    cSubProjectSync = this.m_cData.GetSubProjectProjectData(ddcSub.sSubProjectNo);
                                //    cSubProjectSync.DateLastSynced = DateTime.Now;
                                //    bSaveOK = this.m_cData.UpdateSubProjectData(cSubProjectSync);

                                //}


                                //v1.0.10  - Delete list of sub projects returned.
                                if (dcResult.sDeleted != null)
                                {
                                    //Loop through list of sub project to delete
                                    foreach (string sSubProjectToDelete in dcResult.sDeleted)
                                    {
                                        await this.m_cData.DeleteSubProjectFromDevice(sSubProjectToDelete);

                                        iSubProjectsDeleted++;
                                    }
                                }
                            }
                            else
                            {
                                bErrorOccurred = true;
                            }

                            iSubProjectCount = 0;

                            //v1.0.1 - Checking files
                            foreach (SubProjectSyncUpdateValues cSubProjectValue in cSubProjectDates)
                            {
                                iSubProjectCount += 1;
                                sSubProjectStatus = "Checking files for sub project (" + iSubProjectCount.ToString() + " of " + cSubProjectDates.Count.ToString() + ")";

                                //Update screen.
                                if (v_bBackgroundTask == false)
                                {
                                    this.UpdateMessage(sProjectStatus + " - " + sSubProjectStatus);
                                }
                                ;

                                bSaveOK = await this.CheckForFileChanges(cProject.ProjectNo, cSubProjectValue.SubProjectNo, v_bBackgroundTask);

                                if (bSaveOK == false)
                                {
                                    throw new Exception("Error checking files for sub project (" + cSubProjectValue.SubProjectNo + ")");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (v_bBackgroundTask == false)
                            {
                                //this.ProjectSyncError(this, new cSyncEventErrorParams(ex.Message, cProject.ProjectNo));
                            }
                            ;

                            bErrorOccurred = true;
                        }

                        //If error occurred check connection is OK, if not leave.
                        if (bErrorOccurred == true)
                        {
                            //Update screen.
                            if (v_bBackgroundTask == false)
                            {
                                this.UpdateMessage("Checking Connection.");
                            }
                            ;

                            //Check we are connected first
                            bConnected = await this.m_cSetting.IsAXSystemAvailable(false);

                            if (bConnected == false)
                            {
                                //Update screen.
                                if (v_bBackgroundTask == false)
                                {
                                    this.UpdateMessage("Connection Failed.");
                                }
                                ;

                                bReturnStatus = false;
                                break;
                            }
                        }

                        //Update last project no
                        sLastProjectNo = cProject.ProjectNo;
                    }

                    if (v_bBackgroundTask == false)
                    {
                        bool bUpdateSuccess = false;
                        if (bErrorOccurred == false)
                        {
                            bUpdateSuccess = true;
                        }

                        //this.SubProjectStatusUpdate(this, new cSyncEventParamProjectStatus(sLastProjectNo, string.Empty, iSubProjectsAdded, iSubProjectsDeleted, bUpdateSuccess));
                    }

                    if (cAX != null)
                    {
                        await DependencyService.Get <IWcfExt116>().CloseAXConnection();
                    }
                }

                return(bReturnStatus);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }