예제 #1
0
 public void RemoveHierarchicalWithoutParents(List <BadHierarchicalData> toRepair)
 {
     foreach (var grouppedTechRoutese in toRepair)
     {
         var ss        = new SepDrawingDataManager(_database, grouppedTechRoutese.IdCollection);
         var list      = ss.GetListCollection();
         var childrens = list.Where(x => x.ParentId == grouppedTechRoutese.IdRecord).ToList();
         foreach (var doc in childrens)
         {
             ss.Delete(doc);
         }
     }
 }
예제 #2
0
        public List <TechRoute> CheckUnusableTechRoutes()
        {
            var result = new List <TechRoute>();

            var dmTechRoutes = new MongoDbDataManager <TechRoute>(_database);
            var techRoutes   = dmTechRoutes.GetListCollection();

            var parentsIds = GetParentIds().ToList();

            var dictDrawings = new Dictionary <int, List <Drawing> >();
            var collStandart = new MongoDbDataManager <StandartDrawing>(_database);
            var stCollection = collStandart.GetListCollection();

            foreach (var techRoute in techRoutes)
            {
                var usage = false;

                foreach (var parentsId in parentsIds)
                {
                    if (!dictDrawings.ContainsKey(parentsId))
                    {
                        var coll = new SepDrawingDataManager(_database, parentsId);
                        dictDrawings.Add(parentsId, coll.GetListCollection());
                    }

                    usage = dictDrawings[parentsId].Any(x => x.TechRouteId == techRoute.Id);
                    if (usage)
                    {
                        break;
                    }
                }

                usage = usage || stCollection.Any(x => x.TechRouteId == techRoute.Id);

                if (!usage)
                {
                    result.Add(techRoute);
                }
            }

            return(result);
        }
예제 #3
0
        public List <GrouppedTechRoutes> CheckDeletedTechOpers()
        {
            var result = new List <GrouppedTechRoutes>();

            var dmTechRoutes = new MongoDbDataManager <TechRoute>(_database);
            var dmTechOpers  = new MongoDbDataManager <TechOperation>(_database);
            var orders       = new MongoDbDataManager <Order>(_database).GetListCollection();

            var parentsIds = GetParentIds().ToList();

            var techRoutes   = dmTechRoutes.GetListCollection();
            var techOpers    = dmTechOpers.GetListCollection();
            var dictDrawings = new Dictionary <int, List <Drawing> >();
            var dictOrders   = new List <Order>();

            foreach (var techRoute in techRoutes)
            {
                var actualTechOpers = new List <TechOperation>();

                foreach (var actualTo in techRoute.TechOperations.Select(techOperation => techOpers.FirstOrDefault(x => x.Id == techOperation.Id)))
                {
                    if (actualTo != null)
                    {
                        actualTechOpers.Add(actualTo);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }

                actualTechOpers = actualTechOpers.OrderBy(x => x.OrderInPrint).ToList();

                if (actualTechOpers.Any(x => x.IsDelete))
                {
                    foreach (var parentsId in parentsIds)
                    {
                        if (!dictDrawings.ContainsKey(parentsId))
                        {
                            var coll = new SepDrawingDataManager(_database, parentsId);
                            dictDrawings.Add(parentsId, coll.GetListCollection());
                        }

                        if (dictDrawings[parentsId].Any(x => x.TechRouteId == techRoute.Id))
                        {
                            var ss = orders.FirstOrDefault(x => x.DrawingId == parentsId);
                            if (dictOrders.All(x => x.Id != ss.Id))
                            {
                                dictOrders.Add(ss);
                                Debug.WriteLine($"Tech route {techRoute.Name}. Order no: {ss.OrderNo}");
                            }
                        }

                        result.Add(new GrouppedTechRoutes()
                        {
                            Name = techRoute.Name, Count = parentsId
                        });
                    }
                }
            }

            foreach (var dictOrder in dictOrders)
            {
                Debug.WriteLine(dictOrder.OrderNo);
            }

            return(result);
        }
예제 #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);
        }
예제 #5
0
 public void RemoveHierarchicalWithoutParents(List<BadHierarchicalData> toRepair)
 {
     foreach (var grouppedTechRoutese in toRepair)
     {
         var ss = new SepDrawingDataManager(_database, grouppedTechRoutese.IdCollection);
         var list = ss.GetListCollection();
         var childrens = list.Where(x => x.ParentId == grouppedTechRoutese.IdRecord).ToList();
         foreach (var doc in childrens)
         {
             ss.Delete(doc);
         }
     }
 }
예제 #6
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);
        }
예제 #7
0
        public List<TechRoute> CheckUnusableTechRoutes()
        {
            var result = new List<TechRoute>();

            var dmTechRoutes = new MongoDbDataManager<TechRoute>(_database);
            var techRoutes = dmTechRoutes.GetListCollection();

            var parentsIds = GetParentIds().ToList();

            var dictDrawings = new Dictionary<int, List<Drawing>>();
            var collStandart = new MongoDbDataManager<StandartDrawing>(_database);
            var stCollection = collStandart.GetListCollection();

            foreach (var techRoute in techRoutes)
            {
                var usage = false;

                foreach (var parentsId in parentsIds)
                {
                    if (!dictDrawings.ContainsKey(parentsId))
                    {
                        var coll = new SepDrawingDataManager(_database, parentsId);
                        dictDrawings.Add(parentsId, coll.GetListCollection());
                    }

                    usage = dictDrawings[parentsId].Any(x => x.TechRouteId == techRoute.Id);
                    if (usage)
                        break;
                }

                usage = usage || stCollection.Any(x => x.TechRouteId == techRoute.Id);

                if (!usage)
                    result.Add(techRoute);
            }

            return result;
        }