Пример #1
0
        /// <summary>
        /// Upload file to AX.
        /// </summary>
        /// <returns></returns>
        public async Task <UploadChangesResult> UploadFile(
            string v_sSubProjectNo,
            string v_sUserName,
            string v_sMachineName,
            UploadFileChange v_cFileUpload)
        {
            UploadChangesResult cUResults = null;

            try
            {
                ObservableCollection <UploadFileChange> cUploads = new ObservableCollection <UploadFileChange>();
                cUploads.Add(v_cFileUpload);

                //v1.0.3 - Use new service, new parameters user name and machine name.
                cUResults = await DependencyService.Get <IWcfExt116>().UploadSubProjectFilesAsync(
                    this.m_cCompanyName,
                    v_sSubProjectNo,
                    v_sUserName,
                    v_sMachineName,
                    cUploads,
                    Settings.p_sSetting_AuthID,
                    Session.Token);


                return(cUResults);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + " - SubProjectNo(" + v_sSubProjectNo + ")");
            }
        }
Пример #2
0
        public async Task <UploadChangesResult> UploadSubProjectDataChangesAsync(
            string v_sCompanyName,
            string v_sPurpose,
            string v_sUserName,
            string v_sMachineName,
            string v_sSubProjectNo,
            ObservableCollection <AXDataUploadDataChange> v_cChanges,
            string v_sAuthID,
            string v_sToken)
        {
            m_wcfClient = new WcfExt116.ServiceClient();
            UploadChangesResult result = new UploadChangesResult();

            try
            {
                ObservableCollection <WcfExt116.cAXDataUploadDataChange> cChanges = new ObservableCollection <WcfExt116.cAXDataUploadDataChange>();
                foreach (AXDataUploadDataChange o in v_cChanges)
                {
                    WcfExt116.cAXDataUploadDataChange oAUDC = new WcfExt116.cAXDataUploadDataChange();
                    oAUDC.FieldName  = o.FieldName;
                    oAUDC.FieldValue = o.FieldValue;
                    oAUDC.ProjectNo  = o.ProjectNo;
                    cChanges.Add(oAUDC);
                }
                WcfExt116.UploadChangesResult sResult = await m_wcfClient.UploadSubProjectDataChangesAsync(
                    v_sCompanyName,
                    v_sPurpose,
                    v_sUserName,
                    v_sMachineName,
                    v_sSubProjectNo,
                    cChanges,
                    v_sAuthID,
                    v_sToken);

                if (sResult.bSuccessfull == true)
                {
                    result.bSuccessfull            = sResult.bSuccessfull;
                    result.ActivitiesTable_ModDate = sResult.ActivitiesTable_ModDate;
                    result.ProjTable_ModDate       = sResult.ProjTable_ModDate;
                    result.NoteValues = new ObservableCollection <RealtimeNoteKeyValues>();
                    foreach (WcfExt116.clsRealtimeNoteKeyValues o in sResult.NoteValues)
                    {
                        RealtimeNoteKeyValues oRNV = new RealtimeNoteKeyValues();
                        oRNV.DeviceIDKey = o.DeviceIDKey;
                        oRNV.NotesRecID  = o.NotesRecID;
                        oRNV.ProjectNo   = o.ProjectNo;
                        result.NoteValues.Add(oRNV);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #3
0
        public async Task <UploadChangesResult> UploadSubProjectFilesAsync(
            string v_sCompanyName,
            string v_sSubProjectNo,
            string v_sUserName,
            string v_sMachineName,
            ObservableCollection <UploadFileChange> v_cChanges,
            string v_sAuthID,
            string v_sToken)
        {
            m_wcfClient = new WcfExt116.ServiceClient();
            UploadChangesResult result = new UploadChangesResult();

            try
            {
                ObservableCollection <WcfExt116.UploadFileChange> cChanges = new ObservableCollection <WcfExt116.UploadFileChange>();
                foreach (UploadFileChange o in v_cChanges)
                {
                    WcfExt116.UploadFileChange oUFC = new WcfExt116.UploadFileChange();
                    oUFC.byData = new byte[o.byData.Length];
                    Array.Copy(o.byData, oUFC.byData, o.byData.Length);
                    oUFC.sComment  = o.sComment;
                    oUFC.sFileName = o.sFileName;
                    cChanges.Add(oUFC);
                }
                WcfExt116.UploadChangesResult sResult = await m_wcfClient.UploadSubProjectFilesAsync(
                    v_sCompanyName,
                    v_sSubProjectNo,
                    v_sUserName,
                    v_sMachineName,
                    cChanges,
                    v_sAuthID,
                    v_sToken);

                if (sResult.bSuccessfull == true)
                {
                    result.bSuccessfull            = sResult.bSuccessfull;
                    result.ActivitiesTable_ModDate = sResult.ActivitiesTable_ModDate;
                    result.ProjTable_ModDate       = sResult.ProjTable_ModDate;
                    result.NoteValues = new ObservableCollection <RealtimeNoteKeyValues>();
                    foreach (WcfExt116.clsRealtimeNoteKeyValues o in sResult.NoteValues)
                    {
                        RealtimeNoteKeyValues oRNKV = new RealtimeNoteKeyValues();
                        oRNKV.DeviceIDKey = o.DeviceIDKey;
                        oRNKV.NotesRecID  = o.NotesRecID;
                        oRNKV.ProjectNo   = o.ProjectNo;
                        result.NoteValues.Add(oRNKV);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #4
0
        public async Task <UploadChangesResult> UploadSubProjectNotesChangesAsync(
            string v_sCompanyName,
            string v_sPurpose,
            string v_sUserName,
            string v_sMachineName,
            string v_sSubProjectNo,
            ObservableCollection <NoteDetails> v_cNotes,
            string v_sAuthID,
            string v_sToken)
        {
            m_wcfClient = new WcfExt116.ServiceClient();
            UploadChangesResult result = new UploadChangesResult();

            try
            {
                ObservableCollection <WcfExt116.NoteDetails> cNotes = new ObservableCollection <WcfExt116.NoteDetails>();
                foreach (NoteDetails o in v_cNotes)
                {
                    WcfExt116.NoteDetails oND = new WcfExt116.NoteDetails();
                    oND.AXRecID     = o.AXRecID;
                    oND.DeviceIDKey = o.DeviceIDKey;
                    oND.InputDate   = o.InputDate;
                    oND.NoteText    = o.NoteText;
                    oND.NoteType    = o.NoteType;
                    oND.ProjectNo   = o.ProjectNo;
                    oND.Purpose     = o.Purpose;
                    oND.UserName    = o.UserName;
                    oND.UserProfile = o.UserProfile;
                    cNotes.Add(oND);
                }
                WcfExt116.UploadChangesResult sResult = await m_wcfClient.UploadSubProjectNotesChangesAsync(
                    v_sCompanyName,
                    v_sPurpose,
                    v_sUserName,
                    v_sMachineName,
                    v_sSubProjectNo,
                    cNotes,
                    v_sAuthID,
                    v_sToken);

                if (sResult.bSuccessfull == true)
                {
                    result.bSuccessfull            = sResult.bSuccessfull;
                    result.ActivitiesTable_ModDate = sResult.ActivitiesTable_ModDate;
                    result.ProjTable_ModDate       = sResult.ProjTable_ModDate;
                    result.NoteValues = new ObservableCollection <RealtimeNoteKeyValues>();
                    foreach (WcfExt116.clsRealtimeNoteKeyValues o in sResult.NoteValues)
                    {
                        RealtimeNoteKeyValues oRNKV = new RealtimeNoteKeyValues();
                        oRNKV.DeviceIDKey = o.DeviceIDKey;
                        oRNKV.NotesRecID  = o.NotesRecID;
                        oRNKV.ProjectNo   = o.ProjectNo;
                        result.NoteValues.Add(oRNKV);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Upload photos to AX.
        /// </summary>
        /// <returns></returns>
        public async Task <bool> UploadPhotos()
        {
            WcfExt116        cAX = null;
            UploadFileChange cFileUpload;
            //StorageFile sfFile = null;
            object sfFile = null;
            //bool bUploadOK = false;
            bool bSaveOK        = false;
            bool bConnected     = false;
            bool bErrorOccurred = false;
            bool bReturnStatus  = true;

            try
            {
                string sUserName    = Session.CurrentUserName;
                string sMachineName = Settings.GetMachineName(); //DependencyService.Get<ISettings>().GetMachineName();

                //Update screen.
                this.UpdateMessage("Checking connection.");

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

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

                    return(false);
                }

                //Fetch list of files waiting to be uploaded.

                //Update screen.
                this.UpdateMessage("Checking for files to uploading.");

                List <cProjectFilesTable> cFiles = this.m_cData.ReturnNewFilesForUploading();
                if (cFiles != null)
                {
                    cAX = new WcfExt116();

                    int iFileCount = 0;
                    UploadChangesResult ufResult = null;


                    foreach (cProjectFilesTable cFile in cFiles)
                    {
                        iFileCount += 1;
                        bSaveOK     = false;

                        //Update screen.
                        this.UpdateMessage("Uploading file (" + iFileCount.ToString() + " of " + cFiles.Count.ToString() + ") Sub project: " + cFile.SubProjectNo);

                        bErrorOccurred = false;

                        try
                        {
                            cFileUpload           = new UploadFileChange();
                            cFileUpload.sComment  = cFile.NoteText;
                            cFileUpload.sFileName = cFile.FileName;

                            sfFile = await DependencyService.Get <ISettings>().ReturnStorageFileForSubProject(cFile.SubProjectNo, cFile.FileName);

                            if (sfFile != null)
                            {
                                cFileUpload.byData = await DependencyService.Get <ISettings>().ConvertFileToByteArray(sfFile);

                                if (cFileUpload.byData != null)
                                {
                                    ufResult = await cAX.UploadFile(cFile.SubProjectNo, sUserName, sMachineName, cFileUpload);

                                    if (ufResult != null)
                                    {
                                        if (ufResult.bSuccessfull == true)
                                        {
                                            //v1.0.6 - Update local mod date.
                                            cFile.ModDateTime = ufResult.ProjTable_ModDate;
                                            bSaveOK           = this.m_cData.UpdateFileAsNotNew(cFile);
                                        }
                                    }

                                    //v1.0.6 - If not saved ok, report as error.
                                    if (bSaveOK == false)
                                    {
                                        //Update screen.
                                        this.UpdateMessage("File upload failed.");
                                        bErrorOccurred = true;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //cMain.ReportError(ex, cMain.GetCallerMethodName(), string.Empty);
                            bErrorOccurred = true;
                        }

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

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

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

                                bReturnStatus = false;
                                break;
                            }
                        }
                    }

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


                return(bReturnStatus);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #6
0
        /// <summary>
        /// Upload changes to AX.
        /// </summary>
        public async Task <bool> UploadChanges(bool v_bBackgroundTask)
        {
            bool      bConnected     = false;
            WcfExt116 cAX            = null;
            bool      bErrorOccurred = false;
            bool      bReturnStatus  = true;

            //Create changes upload object for passing to WCF.
            ObservableCollection <AXDataUploadDataChange> cChanges = new ObservableCollection <AXDataUploadDataChange>();

            //v1.0.1 - OC for new notes.
            ObservableCollection <NoteDetails> cNotes = new ObservableCollection <NoteDetails>();

            //v1.0.1 - Processing new notes.
            List <cProjectNotesTable> pntNotes = new List <cProjectNotesTable>();

            ///v1.0.1
            NoteDetails ndNote;

            //
            AXDataUploadDataChange cChange = new AXDataUploadDataChange();

            UploadChangesResult uUploadResult = null;

            string sPurpose = Settings.ReturnPurposeType();

            int iSubProjectCount = 0;

            //v1.0.10 - Unit change upload variables.
            ObservableCollection <UnitDetails> ocUnitDetails = new ObservableCollection <UnitDetails>();
            UnitDetails udUnitDetail;
            DateTime    dInstallationDate;
            string      sInstallationTeam;

            List <cUnitsUpdateTable> cUnitUpdates;

            bool bUploadOK = false;


            try
            {
                if (v_bBackgroundTask == false)
                {
                    //Update screen.
                    if (Application.Current.MainPage.Navigation.NavigationStack.Count > 0)
                    {
                        this.UpdateMessage("Checking connection..");
                    }
                }


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

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

                    return(false);
                }

                List <cUpdatesTable> cSubProjectUpdates = null;

                //string sUserName = await DependencyService.Get<ISettings>().GetUserName();
                //string sMachineName = DependencyService.Get<ISettings>().GetMachineName();
                //string sUserFullName = await DependencyService.Get<ISettings>().GetUserDisplayName();
                string sUserName     = Session.CurrentUserName;
                string sMachineName  = Settings.GetMachineName();
                string sUserFullName = Session.CurrentUserName;

                //Create new instance of
                cAX = new WcfExt116();


                //Fetch list of sub project with updates to upload

                //Update screen.
                if (v_bBackgroundTask == false)
                {
                    this.UpdateMessage("Retrieving sub project with pending data uploads...");
                }
                ;

                List <SubProjectSync> cSubProjects = this.m_cData.FetchSubProjectsWithUploads();
                if (cSubProjects.Count > 0)
                {
                    //Loop through sub project and try and upload the changes for each.
                    foreach (SubProjectSync cSubProject in cSubProjects)
                    {
                        iSubProjectCount += 1;

                        bErrorOccurred = false;

                        //Update screen.
                        if (v_bBackgroundTask == false)
                        {
                            this.UpdateMessage("Uploading Sub project: (" + iSubProjectCount.ToString() + " of " + cSubProjects.Count.ToString() + ") - " + cSubProject.SubProjectNo);
                        }
                        ;

                        try
                        {
                            if (cSubProject.UpdateQty > 0)
                            {
                                //Clear out existing update.
                                cChanges.Clear();

                                //Fetch list of pending updates.
                                cSubProjectUpdates = this.m_cData.ReturnPendingUpdatesForSubProject(cSubProject.SubProjectNo);

                                //Add update to upload object.
                                foreach (cUpdatesTable cUpdate in cSubProjectUpdates)
                                {
                                    cChange            = new AXDataUploadDataChange();
                                    cChange.ProjectNo  = cUpdate.SubProjectNo;
                                    cChange.FieldName  = cUpdate.FieldName;
                                    cChange.FieldValue = cUpdate.FieldValue;

                                    cChanges.Add(cChange);
                                }

                                //Pass update to AX.
                                uUploadResult = await cAX.UploadSubProjectChanges(sUserName, sMachineName, cSubProject.SubProjectNo, cChanges);

                                //If OK then delete updates from local updates table.
                                if (uUploadResult != null && uUploadResult.bSuccessfull == true)
                                {
                                    //Remove changes from upload table.
                                    this.m_cData.RemoveChangesFromUploadTable(cSubProjectUpdates);

                                    //v1.0.10 - Do not update sub project dates as can stop latest data from syncing.
                                    //Update sub project modified dates.
                                    //this.m_cData.UpdateSubProjectUpdateDates(cSubProject.SubProjectNo, uUploadResult.ProjTable_ModDate, uUploadResult.ActivitiesTable_ModDate);
                                }
                                else
                                {
                                    //Update screen.
                                    if (v_bBackgroundTask == false)
                                    {
                                        this.UpdateMessage("Upload failed for sub project: " + cSubProject.SubProjectNo);
                                    }
                                    ;

                                    bErrorOccurred = true;
                                }
                            }

                            if (cSubProject.UnitUpdateQty > 0)
                            {
                                //v1.0.10 - Upload unit status changes if running contract manager mode.
                                if (DependencyService.Get <ISettings>().IsThisTheSurveyorApp() == false)
                                {
                                    //Fetch pending updates for unit.
                                    cUnitUpdates = this.m_cData.FetchUnitUpdatesForSubProject(cSubProject.SubProjectNo);
                                    if (cUnitUpdates.Count > 0)
                                    {
                                        //Fetch the most recent update date.
                                        dInstallationDate = this.m_cData.FetchMostRecentUnitInstallDateForSubProject(cSubProject.SubProjectNo);

                                        //Fetch installation team.
                                        sInstallationTeam = this.m_cData.FetchInstallationTeamForSubProject(cSubProject.SubProjectNo);

                                        //Make sure the collection is clean
                                        if (ocUnitDetails != null)
                                        {
                                            ocUnitDetails.Clear();
                                        }
                                        else
                                        {
                                            ocUnitDetails = new ObservableCollection <UnitDetails>();
                                        }

                                        //Update observable collection with unit updates.
                                        foreach (cUnitsUpdateTable cUpdate in cUnitUpdates)
                                        {
                                            udUnitDetail = new UnitDetails();
                                            udUnitDetail.dInstalledDate   = dInstallationDate;
                                            udUnitDetail.iInstalledStatus = cUpdate.InstalledStatus;
                                            udUnitDetail.iUNITNUMBER      = cUpdate.UnitNo;

                                            ocUnitDetails.Add(udUnitDetail);
                                        }

                                        //Pass up.
                                        bUploadOK = await cAX.UploadUnitStatusChanges(cSubProject.SubProjectNo, sUserName, sMachineName, dInstallationDate, sInstallationTeam, ocUnitDetails);

                                        //If OK then remove updates from table.
                                        if (bUploadOK == true)
                                        {
                                            this.m_cData.DeleteUnitUpdates(cSubProject.SubProjectNo);
                                        }
                                        else
                                        {
                                            //Update screen.
                                            if (v_bBackgroundTask == false)
                                            {
                                                this.UpdateMessage("Upload failed for sub project: " + cSubProject.SubProjectNo);
                                            }
                                            ;

                                            bErrorOccurred = true;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //cMain.ReportError(ex, cMain.GetCallerMethodName(), string.Empty);
                            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.
                                this.UpdateMessage("Checking Failed.");

                                bReturnStatus = false;
                                break;
                            }
                        }
                    }
                }

                //** Upload notes to AX **

                //Update screen.
                if (v_bBackgroundTask == false)
                {
                    this.UpdateMessage("Fetching sub projects with new notes");
                }
                ;

                iSubProjectCount = 0;

                cSubProjects = this.m_cData.FetchSubProjectsWithNewNotes();
                if (cSubProjects != null)
                {
                    //Loop through sub project and try and upload the changes for each.
                    foreach (SubProjectSync cSubProject in cSubProjects)
                    {
                        iSubProjectCount += 1;

                        bErrorOccurred = false;

                        //Update screen.
                        if (v_bBackgroundTask == false)
                        {
                            this.UpdateMessage("Uploading notes for Sub project: (" + iSubProjectCount.ToString() + " of " + cSubProjects.Count.ToString() + ") - " + cSubProject.SubProjectNo);
                        }
                        ;


                        try
                        {
                            cNotes.Clear();

                            pntNotes = this.m_cData.FetchNewNotes(cSubProject.SubProjectNo);
                            foreach (cProjectNotesTable cNote in pntNotes)
                            {
                                ndNote             = new NoteDetails();
                                ndNote.AXRecID     = cNote.AXRecID;
                                ndNote.DeviceIDKey = cNote.IDKey;
                                ndNote.InputDate   = cNote.InputDateTime;
                                ndNote.NoteText    = cNote.NoteText;
                                ndNote.NoteType    = cNote.NoteType;
                                ndNote.ProjectNo   = cNote.SubProjectNo;
                                ndNote.Purpose     = sPurpose;
                                ndNote.UserName    = sUserFullName;
                                ndNote.UserProfile = sUserName;

                                cNotes.Add(ndNote);
                            }

                            //Pass update to AX.
                            uUploadResult = await cAX.UploadSubProjectNotes(sUserName, sMachineName, cSubProject.SubProjectNo, cNotes);

                            //If OK then delete updates from local updates table.
                            if (uUploadResult != null && uUploadResult.bSuccessfull == true)
                            {
                                this.m_cData.UpdateNotesWithRecID(uUploadResult.NoteValues);
                            }
                            else
                            {
                                //Update screen.
                                if (v_bBackgroundTask == false)
                                {
                                    this.UpdateMessage("Notes upload failed for sub project: " + cSubProject.SubProjectNo);
                                }
                                ;

                                bErrorOccurred = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            //cMain.ReportError(ex, cMain.GetCallerMethodName(), string.Empty);
                            bReturnStatus = true;
                        }
                    }
                }


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

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