Ejemplo n.º 1
0
        /// <summary>
        /// Save all local information into configuration file
        /// </summary>
        public static async void SaveSyncFile()
        {
            SyncList = SyncList.Distinct().ToList();


            string emailAddress = GetSettingsValue("SYNC_EMAIL");
            string saveText     = "";

            #region Save Synced Files

            //foreach (var orderID in SyncList)
            foreach (Order order in OrderList.Where(x => x.IsSyncing))
            {
                //saveText += orderID + Environment.NewLine;

                #region Save corresponding items with orderID

                // Order order = OrderList.First(x => x.OrderID == orderID);
                saveText += "[OR_LO_]=" + order.Location +
                            //"||[PRETAX_PRICE]=" + order.OrderTotalPreTax +
                            "||[OR_DA_]=" + order.Date.ToString() +
                            "||[OR_PA_]=" + order.Payment +
                            "||[OR_ID_]=" + order.OrderID + Environment.NewLine;

                #endregion

                #region Save order with corresponding orderID

                foreach (Item item in MasterItemList.Where(x => x.OrderID == order.OrderID).ToList())
                {
                    saveText += "[IT_NA_]=" + item.Name +
                                "||[IT_CA_]=" + item.Category +
                                "||[IT_QU_]=" + item.Quantity +
                                "||[IT_PR_]=" + item.Price +
                                "||[IT_ID_]=" + item.OrderID + Environment.NewLine;
                }

                #endregion
            }

            #endregion

            if (saveText.Length < 4)
            {
                saveText = " ";
            }

            // Create local repository
            await WriteFileContent("localSyncFTP", saveText);

            // Copy local repository to FTP Server
            if (Device.OS == TargetPlatform.Android || Device.OS == TargetPlatform.iOS)
            {
                DependencyService.Get <IFtpWebRequest>().FTPWrite(emailAddress + SyncFileName,
                                                                  Path.Combine(_fileSystem.LocalStorage.Path, "localSyncFTP"));
            }

            // Delete local copy
            //DeleteFileContent("localSyncFTP");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the current sync file if available
        /// </summary>
        public static async Task <bool> LoadSyncFile()
        {
            string syncText     = "";
            string emailAddress = GetSettingsValue("SYNC_EMAIL");

            try
            {
                if (Global.isOnWifi()) // only try on WiFi (most data will block this)
                {
                    if (Device.OS == TargetPlatform.Android || Device.OS == TargetPlatform.iOS)
                    {
                        // Copy local repository to FTP Server
                        // Read from FTP File
                        //string[] lines = GetFileContent(emailAddress + SyncFileName)
                        Task <string> ftpLine = Task.Run(() => DependencyService.Get <IFtpWebRequest>()
                                                         .FTPRead(emailAddress + SyncFileName));


                        List <string> lines = AESGCM.SimpleDecryptWithPassword(await ftpLine, AESGCMKey).Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();

                        // Only load orders
                        foreach (string line in lines)
                        {
                            // if is already synced, append "[ISSYNCED]=1" if contains this in sync file (the desktop application will append this AFTER it syncs)
                            if (line.Length > 5 && line.Contains("[OR_LO_]="))
                            {
                                SyncList.Add(Parse_Line_Information(line, "OR_ID_") +
                                             (line.Contains("[OR_SY_]=1")
                                                 ? "[OR_SY_]=1"
                                                 : "")); // append only order id to list
                            }
                        }

                        // Remove duplication
                        SyncList.Distinct();
                    }
                }
            }
            catch (Exception Ex)
            {
                Debug.WriteLine("No file found: " + Ex);
            }


            return(true); //complete
        }