Ejemplo n.º 1
0
        /// <summary>
        /// Clean up duplicate serial numbers in the event the truck added a module with a serial number that existed at the gin
        /// in this scenario the truck will get the gin module and the module it created, only the gin module should stay
        /// </summary>
        /// <param name="uow"></param>
        /// <param name="repo"></param>
        /// <param name="cToken"></param>
        private static void cleanDupedModules(IUnitOfWork uow, IModuleRepository repo, CancellationToken cToken)
        {
            if (cToken.IsCancellationRequested)
            {
                return;
            }

            var modulesWithTruckSource = repo.FindMatching(m => m.Source == InputSource.TRUCK);
            var modulesWithGinSource   = repo.FindMatching(m => m.Source == InputSource.GIN);

            foreach (var m in modulesWithTruckSource.Where(m => modulesWithGinSource.Any(g => g.Name == m.Name)))
            {
                repo.Delete(m);
            }

            uow.SaveChanges();
        }
Ejemplo n.º 2
0
        private static async Task pushModules(IUnitOfWork uow, IModuleRepository repo, CancellationToken cToken, IEnumerable <ModuleEntity> remoteEntities, params string[] includes)
        {
            try
            {
                Logging.Logger.Log("INFO", "Pushing entities of type Module");
                //var remoteIds = remoteEntities.Select(t => t.Id).ToList();

                //only push modules if they are not already in cloud, they were created on the truck, and they are not on the unassigned list
                //TODO PICKUP LIST ID
                var newEntities = repo.FindMatching(t => t.Source == InputSource.TRUCK && t.PickupListId != GUIDS.UNASSIGNED_LIST_ID, includes).ToList();

                int count = 1;
                foreach (var entity in newEntities /*.Where(t => !remoteIds.Contains(t.Id))*/)
                {
                    Console.WriteLine("Pushing entity: " + entity.Name);

                    if (cToken.IsCancellationRequested)
                    {
                        return;
                    }
                    await DocumentDBContext.UpsertItemAsync <ModuleEntity>(entity);

                    var remoteEntity = remoteEntities.SingleOrDefault(m => m.Id == entity.Id);
                    if (remoteEntity != null)
                    {
                        remoteEntity.PickupListId = entity.PickupListId;
                        remoteEntity.FieldId      = entity.FieldId;
                    }

                    repo.Update(entity, true);
                    count++;
                    if (count == 100)
                    {
                        count = 1;
                        Console.WriteLine("Saving changes");
                        uow.SaveChanges();
                    }
                }
                Console.WriteLine("Saving changes");
                uow.SaveChanges();
            }
            catch (Exception exc)
            {
                Logging.Logger.Log(exc);
            }
        }