/// <summary>
        /// Handles the Elapsed event of the PendingChangesTimer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
        public void PendingChangesTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (PendingChanges.Count == 0)
            {
                return;
            }

            var changes = PendingChanges.ToList();

            PendingChanges.Clear();

            if (File.Exists(_pendingDataPath))
            {
                try { File.Delete(_pendingDataPath); }
                catch { }
            }

            var req = Remote.API.SendDatabaseChanges(changes, _user, _pass);

            if (!req.Success || !req.OK)
            {
                PendingChanges.AddRange(changes);
                PendingChangesTimer.Start();
                SavePendingChanges();
            }
        }
Beispiel #2
0
        //private static void SyncPoolingLoop()
        //{
        //    // Wait for Start Db Contxt
        //    Thread.Sleep(new TimeSpan(0,0,10));

        //    Thread.CurrentThread.Priority = ThreadPriority.Lowest;
        //    while (true)
        //    {
        //        // 5 min
        //        Thread.Sleep(TimeSpan.FromSeconds(5));

        //        CheckForUpdates();
        //    }
        //}



        //public static bool IsRunningSync { get; set; }


        #endregion

        //Procedimiento principal de sincronización
        public static void CheckForUpdates()
        {
            try
            {
                //lock (Extensions.SyncLock)
                //{
                //    PendingChanges.Clear();

                //    if (!WebApiClient.IsAvailableConnection) return;
                //    if (OnBeginSync != null) OnBeginSync();
                //    //Buscar los cambios pendientes en SAP
                //    var version = SyncVersion.GetLatestVersionByType();

                //    var changesets = WebApiClient.GetNewChangesets(version.Item1, version.Item2, Config.WhsCode).Result;

                //    // ORder By Version CHanges

                //    changesets = changesets.OrderByDescending(o => o.version).ToList();

                //    //Llenar pila con cambios
                //    changesets
                //    .Where(p=> PendingChanges.All(c => c.version != p.version))
                //    .ToList().ForEach(c => PendingChanges.Push(c));

                //    changesetsCount = PendingChanges.Count();
                //    index = 0;

                //    //Sincronizar
                //    GetPendingChanges();

                //    //UploadPendingChanges();

                //    if (onSyncComplete != null) onSyncComplete();
                //  }
            }
            catch (Exception ex)
            {
                if (onSyncComplete != null)
                {
                    onSyncComplete();
                }
                PendingChanges.Clear();
                throw ex;
            }
        }