Пример #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
        /// <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);
            }
        }