public async Task <FileChangesResult> ReturnSubProjectFileChangesAsync( string v_sCompanyName, string v_sProjectNo, string v_sSubProjectNo, ObservableCollection <SubProjectFileDetail> v_fdFiles, string v_sAuthID, string v_sToken) { m_wcfClient = new WcfExt116.ServiceClient(); FileChangesResult result = new FileChangesResult(); try { ObservableCollection <WcfExt116.SubProjectFileDetail> fdFiles = new ObservableCollection <WcfExt116.SubProjectFileDetail>(); foreach (SubProjectFileDetail sd in v_fdFiles) { WcfExt116.SubProjectFileDetail oSPFD = new WcfExt116.SubProjectFileDetail(); oSPFD.sProjectNo = sd.sProjectNo; oSPFD.sSubProjectNo = sd.sSubProjectNo; oSPFD.sfFiles = new ObservableCollection <WcfExt116.SubProjectFile>(); foreach (SubProjectFile o in sd.sfFiles) { WcfExt116.SubProjectFile oSPF = new WcfExt116.SubProjectFile(); oSPF.bFileDeleted = o.bFileDeleted; oSPF.Comments = o.Comments; oSPF.FileName = o.FileName; oSPF.ModifiedDate = o.ModifiedDate; oSPFD.sfFiles.Add(oSPF); } fdFiles.Add(oSPFD); } WcfExt116.FileChangesResult sResult = await m_wcfClient.ReturnSubProjectFileChangesAsync( v_sCompanyName, v_sProjectNo, v_sSubProjectNo, fdFiles, v_sAuthID, v_sToken); if (sResult.bSuccessfull == true) { result.bSuccessfull = sResult.bSuccessfull; result.sfChanges = new ObservableCollection <SubProjectFileDetail>(); foreach (WcfExt116.SubProjectFileDetail o in sResult.sfChanges) { SubProjectFileDetail oSPFD = new SubProjectFileDetail(); oSPFD.sProjectNo = o.sProjectNo; oSPFD.sSubProjectNo = o.sSubProjectNo; oSPFD.sfFiles = new ObservableCollection <SubProjectFile>(); foreach (WcfExt116.SubProjectFile oBEV in o.sfFiles) { SubProjectFile oSPF = new SubProjectFile(); oSPF.bFileDeleted = oBEV.bFileDeleted; oSPF.Comments = oBEV.Comments; oSPF.FileName = oBEV.FileName; oSPF.ModifiedDate = oBEV.ModifiedDate; oSPFD.sfFiles.Add(oSPF); } result.sfChanges.Add(oSPFD); } } return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// v1.0.1 - Check for file changes. /// </summary> /// <returns></returns> private async Task <bool> CheckForFileChanges(string v_sProjectNo, string v_sSubProjectNo, bool v_bBackgroundTask) { bool bSaveOK = false; bool bConnected = false; bool bErrorOccurred = false; bool bReturnStatus = true; WcfExt116 cAX = null; //ObservableCollection<wcfAX.DownloadDataChange> cSubProjects = null; SubProjectFileDetail cProjectFile; List <cProjectFilesTable> cSubProjectFiles = null; //ObservableCollection<wcfAX.SubProjectData> cSubProjectsChanged = null; List <SubProjectSync> cSubProjectsSync; SubProjectFile sfSubProject; FileChangesResult sfrResult; ObservableCollection <SubProjectFileDetail> cProjectFileDetails = null; SubProjectFileDownloadResult sfdResult; object sfSubProjectFolder = null;// Origin was storageFolder try { ////Update screen. //cMain.UpdateSyncMainPage("Checking connection."); ////Check we are connected first //bConnected = await cMain.IsAXSystemAvailable(false); //if (bConnected == false) //{ // //Update screen. // cMain.UpdateSyncMainPage("Checking failed."); // return false; //} try { cAX = new WcfExt116(); cSubProjectFiles = this.m_cData.FetchSubProjectFilesForChecking(v_sSubProjectNo); cProjectFileDetails = new ObservableCollection <SubProjectFileDetail>(); if (cSubProjectFiles.Count > 0) { cProjectFile = new SubProjectFileDetail(); cProjectFile.sProjectNo = v_sProjectNo; cProjectFile.sSubProjectNo = v_sSubProjectNo; cProjectFile.sfFiles = new ObservableCollection <SubProjectFile>(); foreach (cProjectFilesTable cSubProjectFile in cSubProjectFiles) { sfSubProject = new SubProjectFile(); sfSubProject.FileName = cSubProjectFile.FileName; sfSubProject.Comments = cSubProjectFile.NoteText; sfSubProject.ModifiedDate = cSubProjectFile.ModDateTime; cProjectFile.sfFiles.Add(sfSubProject); } cProjectFileDetails.Add(cProjectFile); } cProjectFileDetails = await cAX.CheckForAXFileChanges(v_sProjectNo, v_sSubProjectNo, cProjectFileDetails); if (cProjectFileDetails != null) { foreach (SubProjectFileDetail sfdFile in cProjectFileDetails) { sfSubProjectFolder = await DependencyService.Get <ISettings>().ReturnSubProjectImagesFolder(sfdFile.sSubProjectNo); if (sfdFile.sfFiles != null) { int iFileCount = 0; foreach (SubProjectFile spfFile in sfdFile.sfFiles) { iFileCount += 1; //Update screen. if (v_bBackgroundTask == false) { this.UpdateMessage("Downloading file (" + iFileCount.ToString() + " of " + sfdFile.sfFiles.Count.ToString() + ") - Sub Project (" + v_sSubProjectNo + ")"); } ; sfdResult = await cAX.ReturnFileData(spfFile.FileName); //Save file to device. bool bFileSaved = await DependencyService.Get <ISettings>().SaveFileLocally(sfSubProjectFolder, sfdResult.byFileData, spfFile.FileName); if (bFileSaved == false) { throw new Exception("Unable to save file to device (" + spfFile.FileName + ")"); } //Save file record into files table. bool bSavesOK = this.m_cData.SaveSubProjectFile(sfdFile.sSubProjectNo, spfFile.FileName, spfFile.Comments, spfFile.ModifiedDate, false); if (bSavesOK == false) { throw new Exception("Unable to save file details to database (" + spfFile.FileName + ")"); } } } } } } 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. if (v_bBackgroundTask == false) { this.UpdateMessage("Connection Failed."); } ; bReturnStatus = false; } } if (cAX != null) { await DependencyService.Get <IWcfExt116>().CloseAXConnection(); } return(bReturnStatus); } catch (Exception ex) { throw new Exception(ex.Message); } }