Esempio n. 1
0
        public static void ApplyPendingStoryMerges()
        {
            Helpers.RunSqlStatement(Name, "update ignore StoryMerges s1 join StoryMerges s2 on s2.StoryID1=s1.StoryID2 set s2.StoryID1=s1.StoryID1", false);

            //Get user-initiated merge actions. The actions are grouped as a user may have merged stories recursively.
            Dictionary<long, HashSet<long>> mergeGroups = new Dictionary<long, HashSet<long>>();
            Helpers.RunSelect(Name, "select StoryID1, StoryID2, IP, UserID from StoryMerges where MergedAt is null order by StoryID2 desc;",
                mergeGroups,
                (values, reader) =>
                {
                    long keepID = reader.GetInt64("StoryID1");
                    long mergeID = reader.GetInt64("StoryID2");
                    if (mergeGroups.ContainsKey(mergeID))
                    {
                        HashSet<long> tmp = mergeGroups[mergeID];
                        tmp.Add(mergeID);
                        mergeGroups.Remove(mergeID);
                        if (mergeGroups.ContainsKey(keepID))
                            mergeGroups[keepID].UnionWith(tmp);
                        else
                            mergeGroups.Add(keepID, tmp);
                    }
                    else if (mergeGroups.ContainsKey(keepID))
                    {
                        mergeGroups[keepID].Add(mergeID);
                    }
                    else
                    {
                        mergeGroups.Add(keepID, new HashSet<long>());
                        mergeGroups[keepID].Add(mergeID);
                    }
                    long ip = reader.GetInt64("IP");
                    long userID = reader.GetInt64("UserID");

                    string sql = @"insert into StoryLog (IP, UserID, Timestamp, EventType, StoryAgeInSeconds, StoryID, MergedWithStoryID, TweetCount, RetweetCount, UserCount, TopUserCount)
                        select " + ip + "," + userID + ", utc_timestamp(), 12, unix_timestamp(utc_timestamp())-unix_timestamp(StartTime), StoryID, " + keepID + @", TweetCount, RetweetCount, UserCount, TopUserCount
                        from Story where StoryID = " + mergeID + ";";
                    Helpers.RunSqlStatement(Name, sql, false);
                }
            );

            var mergeActions = mergeGroups.SelectMany(n =>
                n.Value.Select(m => new MergeAction() { KeptStoryID = n.Key, MergedStoryID = m }));

            //Perform merge actions
            MergeStories(mergeActions, isAutomerge: false);

            //Clean old actions
            Helpers.RunSqlStatement(Name, "delete from StoryMerges where MergedAt is not null and MergedAt < (utc_timestamp() - interval 1 hour);", false);
        }
Esempio n. 2
0
 private static void DestroyInstances(Dictionary<string, List<StaticObject>> instanceDictionary)
 {
     foreach (StaticObject i in instanceDictionary.SelectMany(ins => ins.Value))
     {
         DestroySoInstance(i);
     }
 }
Esempio n. 3
0
        public static void Check(IEnumerable idsBlRefs, HashSet<string> ignoreBlocks)
        {
            curDepth = 0;
            _ignoreBlocks = ignoreBlocks;
            Database db = HostApplicationServices.WorkingDatabase;
            _errors = new List<Error>();
            attemptedblocks = new HashSet<ObjectId>();
            AllDublicBlRefInfos = new List<BlockRefDublicateInfo>();
            dictBlRefInfos = new Dictionary<string, Dictionary<PointTree, List<BlockRefDublicateInfo>>>();
            try
            {
                using (var t = db.TransactionManager.StartTransaction())
                {

                    if (idsBlRefs == null)
                    {
                        var ms = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForRead) as BlockTableRecord;
                        idsBlRefs = ms;
                    }
                    GetDublicateBlocks(idsBlRefs, Matrix3d.Identity, 0);
                    t.Commit();
                }

                // дублирующиеся блоки
                AllDublicBlRefInfos = dictBlRefInfos.SelectMany(s => s.Value.Values).Where(w => w.Count > 1)
                                        .SelectMany(s => s.GroupBy(g => g).Where(w => w.Skip(1).Any()))
                                        .Select(s =>
                                           {
                                               var bi = s.First();
                                               bi.CountDublic = s.Count();
                                               bi.Dublicates = s.Skip(1).ToList();
                                               return bi;
                                           }).ToList();

                // Добавление дубликатов в результирующий список
                //AddTransformedToModelDublic(dublicBlRefInfos);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, $"CheckDublicateBlocks - {db.Filename}. {ex.StackTrace}");
                return;
            }

            if (AllDublicBlRefInfos.Count == 0)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nДубликаты блоков не найдены.");
            }
            else
            {
                foreach (var dublBlRefInfo in AllDublicBlRefInfos)
                {
                    Error err = new Error($"Дублирование блоков '{dublBlRefInfo.Name}' - {dublBlRefInfo.CountDublic} шт. в точке {dublBlRefInfo.Position.ToString()}",
                       dublBlRefInfo.IdBlRef, dublBlRefInfo.TransformToModel, System.Drawing.SystemIcons.Error);
                    err.Tag = dublBlRefInfo;
                    _errors.Add(err);
                }
            }

            if (_errors.Count>0)
            {
                var formDublicates = new FormError(_errors, true);
                formDublicates.Text = "Дублирование блоков";
                formDublicates.EnableDublicateButtons();
                if (Application.ShowModalDialog(formDublicates) != System.Windows.Forms.DialogResult.OK)
                {
                    formDublicates.EnableDialog(false);
                    Application.ShowModelessDialog(formDublicates);
                    throw new Exception("Отменено пользователем.");
                }
            }
        }