Пример #1
0
        public async Task TriggerOfflineTableSync()
        {
            lock (thisLock)
            {
                var spoilTrt    = GetLastRetreivedSpoil();
                var freshSpoils = GetUnSyncedSpoilAfter(spoilTrt);

                freshSpoils.ForEach(trt =>
                {
                    Spoil dbTrt = this.GetSpoilBy(trt.TransactionRefNo);
                    //_spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == trt.TransactionRefNo);

                    if (dbTrt == null)
                    {
                        trt.CreatedOnUtc  = DateTime.UtcNow;
                        trt.ModifiedOnUtc = DateTime.UtcNow;
                        Log.Warning(String.Format("Spoil with stock ref no ({0}) couldn't be retreive for update.", trt.StockRefNo));
                        Log.Information(String.Format("Switching to adding Spoil with stock ref no ({0}) to sync table as newly created.", trt.StockRefNo));

                        //_spoilSyncSvc.Add(trt);
                        _syncStoreProvider.AddSpoilToSync(
                            Guid.NewGuid(),
                            trt.TransactionRefNo, trt.StockRefNo,
                            trt.StockDetails, trt.StockUnit,
                            trt.StockUnitLeft, trt.IsSyncReady,
                            trt.SyncStatus, trt.SpoilDetails,
                            trt.ReasonSyncFailed, trt.ReportedBy,
                            trt.SyncRefCreatedOn, trt.SyncRefModifiedOn,
                            trt.MachineName, trt.SyncRefNo,
                            trt.SyncDate, trt.SyncFailedCount,
                            trt.RefCreatedDate, trt.RefModifiedDate,
                            trt.Cost, trt.CreatedOnUtc,
                            trt.ModifiedOnUtc, trt.IsDeleted);
                    }
                    else
                    {
                        Spoil.Extend(trt, dbTrt);
                        _syncStoreProvider.UpdateSyncedSpoil(dbTrt.StockRefNo,
                                                             dbTrt.StockDetails, dbTrt.StockUnit,
                                                             dbTrt.StockUnitLeft, dbTrt.IsSyncReady,
                                                             dbTrt.SyncStatus, dbTrt.SpoilDetails,
                                                             dbTrt.ReportedBy, dbTrt.MachineName,
                                                             dbTrt.RefCreatedDate, dbTrt.RefModifiedDate,
                                                             dbTrt.Cost, dbTrt.Id);
                        //_spoilSyncSvc.Update(dbTrt);
                    }
                });
            }

            await Task.FromResult <int>(1);
        }
Пример #2
0
        private void SyncSpoilChanges(SpoilDto spoilDto, TableDependency.Enums.ChangeType changeType)
        {
            var unsyncedSpoil = GetUnSyncSpoilBy(spoilDto.SpoilId);

            if (unsyncedSpoil == null && changeType != ChangeType.Delete)
            {
                return;
            }

            switch (changeType)
            {
            case ChangeType.Delete:
            {
                String spoilId       = spoilDto.SpoilId.ToString();
                var    existingSpoil = _spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == spoilId);

                if (existingSpoil != null)
                {
                    existingSpoil.IsDeleted = true;
                    Spoil.Extend(unsyncedSpoil, existingSpoil);
                    _spoilSyncSvc.Update(existingSpoil);
                }
                break;
            }

            case TableDependency.Enums.ChangeType.Insert:
            {
                unsyncedSpoil.RefModifiedDate = unsyncedSpoil.RefCreatedDate;

                var dbTrt = _spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == unsyncedSpoil.TransactionRefNo);

                if (dbTrt == null)
                {
                    unsyncedSpoil.ModifiedOnUtc = unsyncedSpoil.CreatedOnUtc = DateTime.UtcNow;
                    _spoilSyncSvc.Add(unsyncedSpoil);
                }
                else
                {
                    Spoil.Extend(unsyncedSpoil, dbTrt);
                    _spoilSyncSvc.Update(dbTrt);
                }
                break;
            }

            case TableDependency.Enums.ChangeType.Update:
            {
                if (spoilDto.IsDeleted)
                {
                    goto case ChangeType.Delete;
                }

                var dbTrt = _spoilSyncSvc.FirstOrDefault(t => t.TransactionRefNo == unsyncedSpoil.TransactionRefNo);

                if (dbTrt == null)
                {
                    unsyncedSpoil.CreatedOnUtc  = DateTime.UtcNow;
                    unsyncedSpoil.ModifiedOnUtc = DateTime.UtcNow;
                    Log.Warning(String.Format("Spoil with TransactionRefNo ({0}) couldn't be retreived for update.", unsyncedSpoil.TransactionRefNo));
                    Log.Information(String.Format("Adding Spoil with TransactionRefNo ({0}) to sync table as newly created.", unsyncedSpoil.StockRefNo));
                    _spoilSyncSvc.Add(unsyncedSpoil);
                }
                else
                {
                    Spoil.Extend(unsyncedSpoil, dbTrt);
                    _spoilSyncSvc.Update(dbTrt);
                }

                break;
            }

            case TableDependency.Enums.ChangeType.None:
            default:
                break;
            }
        }