Exemplo n.º 1
0
        public void DelUnusableTechRoutes(List <TechRoute> toRepair)
        {
            var dmTechRoutes = new MongoDbDataManager <TechRoute>(_database);

            foreach (var techRoute in toRepair)
            {
                Debug.WriteLine($"Delete techroute {techRoute.Id} {techRoute.Name}");
                dmTechRoutes.Delete(techRoute);
            }
        }
Exemplo n.º 2
0
        public void DeleteTest()
        {
            InsertTest();
            var dataManager = new MongoDbDataManager<Drawing>(mongoDbTest.Database);
            var data = dataManager.GetListCollection().FirstOrDefault(x => x.Name == "Test");
            Assert.NotNull(data);

            Assert.DoesNotThrow(() => dataManager.Delete(data));
            data = dataManager.GetListCollection().FirstOrDefault(x => x.Name == "Test");
            Assert.Null(data);
        }
Exemplo n.º 3
0
        public void RemoveDoublesWorkHourDrawing(List <GrouppedTechRoutes> toRepair)
        {
            var dataManager = new MongoDbDataManager <WorkHourDrawing>(_database);
            var coll        = dataManager.GetListCollection();

            foreach (var grouppedTechRoutese in toRepair)
            {
                if (grouppedTechRoutese.Tag[0] != null && grouppedTechRoutese.Tag[1] != null)
                {
                    var workHours =
                        coll.Where(
                            x =>
                            x.DrawingId == (int)grouppedTechRoutese.Tag[0] &&
                            x.TechOperationId == (int)grouppedTechRoutese.Tag[1]).OrderByDescending(x => x.DrawingId).ToList();

                    foreach (var source in workHours.Skip(1))
                    {
                        dataManager.Delete(source);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void RepairDoublesTechRoutes(List <GrouppedTechRoutes> toRepair)
        {
            var dmTechRoutes = new MongoDbDataManager <TechRoute>(_database);

            Debug.WriteLine(DateTime.Now);
            var techRoutes = dmTechRoutes.GetListCollection().Where(x => toRepair.Any(y => y.Name == x.Name)).OrderBy(x => x.Id).ToList();
            var parentsIds = GetParentIds().ToList();

            var listNormalTechroutes = new List <TechRoute>();
            var collStandart         = new MongoDbDataManager <StandartDrawing>(_database);
            var stCollection         = collStandart.GetListCollection();
            var listTasks            = new List <Task>();

            foreach (var parentsId in parentsIds)
            {
                var task = new Task(() =>
                {
                    var coll       = new SepDrawingDataManager(_database, parentsId);
                    var collection = coll.GetListCollection();
                    ProgressChanged?.Invoke($"DrawingId: {parentsId}", parentsIds.Count, parentsIds.IndexOf(parentsId));
                    Debug.WriteLine($"DrawingId: {parentsId}. ID #: {parentsIds.Count}. Index: {parentsIds.IndexOf(parentsId)}");
                    foreach (var group in toRepair.AsParallel())
                    {
                        ProgressChanged?.Invoke(group.Name, toRepair.Count, toRepair.IndexOf(group));
                        var techRoute = techRoutes.FirstOrDefault(x => x.Name == group.Name);
                        if (techRoute != null)
                        {
                            var otherRoutes = techRoutes.Where(x => x.Name == group.Name && x.Id != techRoute.Id);
                            foreach (var drawing in collection.Where(x => otherRoutes.Any(y => x.TechRouteId == y.Id)))
                            {
                                Debug.WriteLine($"Change drawings Id: {drawing.Id}. Old tech route Id {drawing.TechRouteId}. New tech route Id: {techRoute.Id}.");
                                ProgressChanged?.Invoke(group.Name, toRepair.Count, toRepair.IndexOf(group));
                                drawing.TechRouteId = techRoute.Id;
                                coll.Update(drawing);
                            }

                            lock (listNormalTechroutes)
                            {
                                if (listNormalTechroutes.All(x => x.Id != techRoute.Id))
                                {
                                    listNormalTechroutes.Add(techRoute);
                                }
                            }
                        }
                    }
                });

                task.Start();
                listTasks.Add(task);
            }

            while (!Task.WaitAll(listTasks.ToArray(), 10000))
            {
            }



            foreach (var group in toRepair)
            {
                ProgressChanged?.Invoke(group.Name, toRepair.Count, toRepair.IndexOf(group));
                var techRoute = techRoutes.FirstOrDefault(x => x.Name == group.Name);
                if (techRoute != null)
                {
                    var otherRoutes = techRoutes.Where(x => x.Name == group.Name && x.Id != techRoute.Id);

                    foreach (var standart in stCollection.Where(x => otherRoutes.Any(y => x.TechRouteId == y.Id)))
                    {
                        Debug.WriteLine($"Change standart drawings Id: {standart.Id}. Old tech route Id {standart.TechRouteId}. New tech route Id: {techRoute.Id}.");
                        standart.TechRouteId = techRoute.Id;
                        collStandart.Update(standart);
                    }

                    if (listNormalTechroutes.All(x => x.Id != techRoute.Id))
                    {
                        listNormalTechroutes.Add(techRoute);
                    }
                }
            }

            foreach (var listNormalTechroute in listNormalTechroutes)
            {
                var otherRoutes = techRoutes.Where(x => x.Name == listNormalTechroute.Name && x.Id != listNormalTechroute.Id);

                foreach (var otherRoute in otherRoutes)
                {
                    Debug.WriteLine($"Delete techroute {otherRoute.Id} {otherRoute.Name}");
                    dmTechRoutes.Delete(otherRoute);
                }
            }

            Debug.WriteLine(DateTime.Now);
        }
Exemplo n.º 5
0
        public void RemoveDoublesWorkHourDrawing(List<GrouppedTechRoutes> toRepair)
        {
            var dataManager = new MongoDbDataManager<WorkHourDrawing>(_database);
            var coll = dataManager.GetListCollection();

            foreach (var grouppedTechRoutese in toRepair)
            {
                if (grouppedTechRoutese.Tag[0] != null && grouppedTechRoutese.Tag[1] != null)
                {
                    var workHours =
                        coll.Where(
                            x =>
                                x.DrawingId == (int)grouppedTechRoutese.Tag[0] &&
                                x.TechOperationId == (int)grouppedTechRoutese.Tag[1]).OrderByDescending(x => x.DrawingId).ToList();

                    foreach (var source in workHours.Skip(1))
                    {
                        dataManager.Delete(source);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void DelUnusableTechRoutes(List<TechRoute> toRepair)
        {
            var dmTechRoutes = new MongoDbDataManager<TechRoute>(_database);

            foreach (var techRoute in toRepair)
            {
                Debug.WriteLine($"Delete techroute {techRoute.Id} {techRoute.Name}");
                dmTechRoutes.Delete(techRoute);
            }
        }
Exemplo n.º 7
0
        public void RepairDoublesTechRoutes(List<GrouppedTechRoutes> toRepair)
        {
            var dmTechRoutes = new MongoDbDataManager<TechRoute>(_database);
            Debug.WriteLine(DateTime.Now);
            var techRoutes = dmTechRoutes.GetListCollection().Where(x => toRepair.Any(y => y.Name == x.Name)).OrderBy(x => x.Id).ToList();
            var parentsIds = GetParentIds().ToList();

            var listNormalTechroutes = new List<TechRoute>();
            var collStandart = new MongoDbDataManager<StandartDrawing>(_database);
            var stCollection = collStandart.GetListCollection();
            var listTasks = new List<Task>();

            foreach (var parentsId in parentsIds)
            {
                var task = new Task(() =>
                {
                    var coll = new SepDrawingDataManager(_database, parentsId);
                    var collection = coll.GetListCollection();
                    ProgressChanged?.Invoke($"DrawingId: {parentsId}", parentsIds.Count, parentsIds.IndexOf(parentsId));
                    Debug.WriteLine($"DrawingId: {parentsId}. ID #: {parentsIds.Count}. Index: {parentsIds.IndexOf(parentsId)}");
                    foreach (var group in toRepair.AsParallel())
                    {
                        ProgressChanged?.Invoke(group.Name, toRepair.Count, toRepair.IndexOf(group));
                        var techRoute = techRoutes.FirstOrDefault(x => x.Name == group.Name);
                        if (techRoute != null)
                        {
                            var otherRoutes = techRoutes.Where(x => x.Name == group.Name && x.Id != techRoute.Id);
                            foreach (var drawing in collection.Where(x => otherRoutes.Any(y => x.TechRouteId == y.Id)))
                            {
                                Debug.WriteLine($"Change drawings Id: {drawing.Id}. Old tech route Id {drawing.TechRouteId}. New tech route Id: {techRoute.Id}.");
                                ProgressChanged?.Invoke(group.Name, toRepair.Count, toRepair.IndexOf(group));
                                drawing.TechRouteId = techRoute.Id;
                                coll.Update(drawing);
                            }

                            lock (listNormalTechroutes)
                            {
                                if (listNormalTechroutes.All(x => x.Id != techRoute.Id))
                                    listNormalTechroutes.Add(techRoute);
                            }

                        }

                    }
                });

                task.Start();
                listTasks.Add(task);
            }

            while (!Task.WaitAll(listTasks.ToArray(), 10000))
            {

            }



            foreach (var group in toRepair)
            {
                ProgressChanged?.Invoke(group.Name, toRepair.Count, toRepair.IndexOf(group));
                var techRoute = techRoutes.FirstOrDefault(x => x.Name == group.Name);
                if (techRoute != null)
                {
                    var otherRoutes = techRoutes.Where(x => x.Name == group.Name && x.Id != techRoute.Id);

                    foreach (var standart in stCollection.Where(x => otherRoutes.Any(y => x.TechRouteId == y.Id)))
                    {
                        Debug.WriteLine($"Change standart drawings Id: {standart.Id}. Old tech route Id {standart.TechRouteId}. New tech route Id: {techRoute.Id}.");
                        standart.TechRouteId = techRoute.Id;
                        collStandart.Update(standart);
                    }

                    if (listNormalTechroutes.All(x => x.Id != techRoute.Id))
                        listNormalTechroutes.Add(techRoute);
                }

            }

            foreach (var listNormalTechroute in listNormalTechroutes)
            {
                var otherRoutes = techRoutes.Where(x => x.Name == listNormalTechroute.Name && x.Id != listNormalTechroute.Id);

                foreach (var otherRoute in otherRoutes)
                {
                    Debug.WriteLine($"Delete techroute {otherRoute.Id} {otherRoute.Name}");
                    dmTechRoutes.Delete(otherRoute);
                }
            }

            Debug.WriteLine(DateTime.Now);
        }