Пример #1
0
        // Event handlers
        void m_afterObjectAdded_Fire(int eventFlag, MmEventTime time, object pSource, ref object pExtra)
        {
            if (received)
            {
                return;
            }

            if (copypast) // Skip all add-events in a paste scope
            {
                return;
            }
            else
            {
                if (paste)
                {
                    MMBase.SendMessage("paste", m_document);
                    copypast = true; // resets in the m_afterObjectChanged_Fire via SendMessage()
                    return;
                }
            }

            string _what = "", _extra = "";

            objectAdded = true;

            foreach (MMBase _parent in DocumentStorage.m_parent)
            {
                _parent.onAfterObjectAddedBase(new MMEventArgs(pSource, _what, _extra, this));
            }
        }
Пример #2
0
        void m_beforeObjectDeleted_Fire(int eventFlag, MmEventTime time, object pSource, ref object pExtra)
        {
            if (received)
            {
                return;
            }

            if (pSource is Topic _topic && !_topic.IsFloatingTopic) // плавающий пропускаем дальше
            {
                if (!_topic.IsSelected)                             // если топик не выбран - отбой, удалится вместе с родителем
                {
                    _topic = null; return;
                }

                Topic _t = _topic;
                // пропускаем дальше выноски связей и выноски границ
                while (!_t.IsCentralTopic && !_t.IsFloatingTopic && _t.ParentRelationship == null && _t.ParentBoundary == null)
                {
                    if (_t.ParentTopic.IsSelected)  // если выше по ветке находится выбранный топик - отбой, удалится вместе с ним
                    {
                        _topic = null; _t = null; return;
                    }
                    _t = _t.ParentTopic;
                }

                _t = null;
            }

            String _what = "", _extra = "";

            if (pSource is Boundary bnd)
            {
                if (!bnd.IsSelected) // если граница не выбрана, значит удаляется ее топик и она удалится вместе с топиком
                {
                    bnd = null; return;
                }
            }

            if (pSource is Relationship rel)
            {
                if (!rel.IsSelected) // если связь не выбрана, значит удаляется ее топик и она удалится вместе с топиком
                {
                    rel = null; return;
                }
            }

            foreach (MMBase _parent in DocumentStorage.m_parent)
            {
                _parent.onBeforeObjectRemovedBase(new MMEventArgs(pSource, _what, _extra, this));
            }

            _topic = null; bnd = null; rel = null;
        }
Пример #3
0
        // For catch delete image event only
        void m_beforeObjectChanged_Fire(int eventFlag, MmEventTime time, object pSource, ref object pExtra) //TODO needed?
        {
            if (received)
            {
                return;
            }

            Topic _topic = pSource as Topic;

            if (_topic == null)
            {
                return;
            }

            string _what = "";

            if (pExtra is Array)
            {
                Array _pExtraAsArray = pExtra as Array;

                if (_pExtraAsArray.GetLength(0) > 0 && eventFlag == DocumentStorage.EventObjectModified)
                {
                    _what = _pExtraAsArray.GetValue(0).ToString().ToLower();
                }
            }

            if (_what == "oneimage")
            {
                reset++;
                if (reset > 1)  // reset сбрасывается на 0 в таймере
                {
                    return;     // иначе будет куча проходов и запуска таймера, нужен только один для удаления картинки
                }
                extracase  = "deleteimage";
                extraTopic = _topic;
                DocumentStorage.m_timer200.Start();
            }

            _topic = null;
        }
Пример #4
0
        void m_afterObjectChanged_Fire(int eventFlag, MmEventTime time, object pSource, ref object pExtra)
        {
            if (received)
            {
                return;
            }

            if (extracase == "deleteimage")
            {
                extracase = "";  // отбиваем таймер удаления картинки
            }

            // TODO при добавлении связи может быть _what "AutoRoute"! И выходит исключение

            string _what = "", _extra = "";

            if (pExtra is Array)
            {
                Array _pExtraAsArray = pExtra as Array;
                if (_pExtraAsArray.GetLength(0) > 0 && eventFlag == DocumentStorage.EventObjectModified)
                {
                    _what = _pExtraAsArray.GetValue(0).ToString().ToLower();
                }
                if (_pExtraAsArray.GetLength(0) > 1)
                {
                    _extra = _pExtraAsArray.GetValue(1).ToString();
                }
            }

            // TODO если выбран не топик, не граница и не связь, то выбран фоновой объект!
            if (_what == "collapsed" || _what == "selection")
            {
                return;
            }

            //if (paste && _what == "oneimage")
            //{
            //    extraTopic = null;
            //    return;
            //}

            if (objectAdded)
            {
                if (_what != "offset") // все оффсетные события нахер
                {
                    objectAdded = false;
                }
                return;
            }

            string sMessage = MMBase.SynergyMessage(m_document);

            //// Message sent from m_beforeObjectChanged_Fire when image deleted
            //if (sMessage == "deleteimage" && _what != "oneimage")
            //{
            //    MMBase.SendMessage("", m_document);
            //    _what = "oneimage";
            //    pSource = extraTopic;
            //}

            //extraTopic = null;

            if (paste && sMessage != "paste") // отбиваем все пасты, которые не от копипаста или драгдропа ТОПИКОВ
            {
                paste = false;
            }
            if (paste && _what == "offset")
            {
                return;
            }
            //if (paste && !_topic.IsCentralTopic) // учитываем только paste, который пришел от message
            //    return;

            if (_extra == SUtils.SYNERGYNAMESPACE) // отбиваются synergy-изменения в атрибутах объекта
            {
                return;
            }

            Topic _topic = pSource as Topic;

            if (_what == "custom" && _topic != null)                          // TODO (addins only?) addins: Synergy, Numbering, Rollup(Gantt)
            {
                if (_topic.IsCentralTopic && _extra == SUtils.SYNERGYMESSAGE) //SendMessage went off
                {
                    if (sMessage == "paste")                                  // SendMessage was emited from m_afterObjectAdded_Fire at starting paste copied objects
                    {                                                         // so, paste events now is ended, we can process pasted objects
                        foreach (MMBase _parent in DocumentStorage.m_parent)
                        {
                            _parent.onAfterPasteBase(new MMEventArgs(pSource, _what, _extra, this));
                        }
                        paste    = false;
                        copypast = false;
                    }
                    //else if (sMessage == "received") // SendMessage was emited from ReceiveChanges
                    //    received = false; // прием закончен

                    m_document.CentralTopic.get_Attributes(SUtils.SYNERGYMESSAGE).DeleteAll();

                    _topic = null;
                    return;
                }

                if (_extra == SUtils.SYNERGYNAMESPACE && rollup) // all subtopics already skipped, rollup operation finished
                {
                    rollup = false;
                    _topic = null;
                    return;
                }
            }

            if (rollup) // skip all rollup subtopics, change only parent
            {
                _topic = null;
                return;
            }

            if (_what == "task") // TODO впадает в цикл, если изменять Duration, Effort и ресурсы через панель Task Info
            {
                if (Changes.SaveChanges._topicxml == MMUtils.getCleanTopicXML(_topic.Xml))
                {
                    _topic = null; return;
                }
            }

            if (_topic != null)
            {
                // TODO надо как-то уловить последний оффсет для них и процессировать
                if ((_topic.IsFloatingTopic || _topic.IsCalloutTopic) && _what == "offset")
                {
                    _topic = null; return; // number of offsets = number of floating topics in the map
                }

                if (_what == "task" && _extra == "")
                {   // если при запуске карты выбран топик с задачей, то почему-то сразу срабатывает событие на task
                    _topic = null; return;
                }

                //if (_what == "task" && _topic.Task.IsEmpty)
                //    return; // при запуске карты может быть такое, если выбрано несколько топиков, один из который задача

                if (_extra == SUtils.numberinguri)
                {
                    _what = "numbering";
                }

                _extra = Changes.PortraitGet.TopicPortrait(_topic, ref _what, _extra, mc_MapFolderPath);
                //System.Windows.Forms.Clipboard.SetText(_extra);

                if (_extra == SUtils.rollupuri)
                {
                    System.Windows.Forms.MessageBox.Show("'Комбинировать информацию о задании' пока не поддерживается, другие пользователи не получат это изменение",
                                                         MMUtils.GetString("maps.synergywarning.caption"));
                    return;
                }

                if (_extra == "queue")
                {
                    System.Windows.Forms.MessageBox.Show("Произведенное изменение пока не поддерживается в Synergy, другие пользователи не получат это изменение",
                                                         MMUtils.GetString("maps.synergywarning.caption"));
                    return;
                }
            }

            foreach (MMBase _parent in DocumentStorage.m_parent)
            {
                _parent.onAfterObjectChangedBase(new MMEventArgs(pSource, _what, _extra, this));
            }
        }
Пример #5
0
        static void m_documentEventBefore_Fire(int eventFlag, MmEventTime time, object pSource, ref object pExtra)
        {
            Document _doc        = pSource as Document;
            bool     _notsynergy = true;

            if (_doc == null || !_doc.HasAttributesNamespace[SUtils.SYNERGYNAMESPACE])
            {
                return;
            }

            string mapGuid = SUtils.SynergyMapGuid(_doc);

            foreach (DocumentStorage item in SDocs)
            {
                if (mapGuid == item.MGuid)
                {
                    _notsynergy = false;
                    break;
                }
            }

            if (_notsynergy)
            {
                _doc = null;
                return;
            }

            if (eventFlag == EventDocumentClosed)
            {
                if (closeMap)
                {
                    closeMap = false;
                    _doc     = null;
                    return;
                }

                File.SetAttributes(_doc.FullName, FileAttributes.Normal);

                Sync(_doc, false); // Unsubscribe this map

                foreach (Watchers _item in Maps.MapsGroup.WATCHERS)
                {
                    if (_item.aMapGuid == mapGuid)
                    {
                        _item.Dispose();
                        Maps.MapsGroup.WATCHERS.Remove(_item);
                        break;
                    }
                }

                string m_PlacePath = "";
                bool   _isonline   = true;

                foreach (Timers _item in MapsGroup.TIMERS)
                {
                    if (_item.m_Guid == mapGuid)
                    {
                        _isonline   = (_item.m_Status == "online");
                        m_PlacePath = _item.m_PlacePath;
                        string _folder = _item.m_PlacePath;
                        _folder = Path.GetDirectoryName(_folder) + "\\";

                        try
                        {
                            string _file = _folder + "info.locker";
                            if (File.Exists(_file))
                            {
                                File.Delete(_file);
                            }

                            _file = _folder + SUtils.currentUserName + ".online";
                            if (File.Exists(_file))
                            {
                                File.Delete(_file);
                            }
                        }
                        catch { }

                        _item.Destroy();
                        MapsGroup.TIMERS.Remove(_item);
                        break;
                    }
                }

                if (MMUtils.MindManager.VisibleDocuments.Count == 1) // this map is the only document, so - it is last
                {
                    MapsGroup.dlgUsersOnline.Visible = false;
                    if (DocumentStorage.SDocs.Count > 0)
                    {
                        MessageBox.Show("All documents closed, but SDocs is not empty...", "Possible bug");
                    }

                    foreach (DocumentStorage item in SDocs)
                    {
                        item.Sdoc = null;
                        item._mc.Dispose();
                    }
                    SDocs.Clear();
                }

                if (_isonline)
                {
                    try
                    {
                        _doc.Save();
                        // Prepare last file for save in Place
                        string _path = m_PlacePath + File.GetLastWriteTimeUtc(_doc.FullName).ToString("yyyyMMddHHmmssfff") + ".mmap";
                        File.Copy(_doc.FullName, _path, true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Exception: " + e.Message, "onBeforeClosed");
                    }
                    finally
                    {
                        _doc = null;
                    }
                }

                _doc = null;
            }

            if (eventFlag == EventDocumentSaved)
            {
                _doc = null;
            }

            if (eventFlag == EventDocumentClipboardDrag) // TODO needed?
            {
                //foreach (MMBase _parent in m_parent)
                //    _parent.onBeforeDocumentClipboardDragBase(new MMEventArgs(m_documentEventBefore, _doc));
                _doc = null;
            }

            if (eventFlag == EventDocumentClipboardDrop)
            {
                MapCompanion.paste = true;
                _doc = null;
            }

            if (eventFlag == EventDocumentClipboardCopy) // TODO needed?
            {
                //foreach (MMBase _parent in m_parent)
                //    _parent.onBeforeDocumentClipboardCopyBase(new MMEventArgs(m_documentEventBefore, _doc));
                _doc = null;
            }

            if (eventFlag == EventDocumentClipboardPaste)
            {
                MapCompanion.paste = true;
                _doc = null;
            }

            _doc = null;
        }
Пример #6
0
        static void m_documentEventAfter_Fire(int eventFlag, MmEventTime time, object pSource, ref object pExtra)
        {
            Document _doc = pSource as Document;

            Maps.MapsGroup.dlgUsersOnline.Visible = false;

            if (_doc == null || !_doc.HasAttributesNamespace[SUtils.SYNERGYNAMESPACE])
            {
                return;
            }

            string mapGuid = SUtils.SynergyMapGuid(_doc);

            if ((eventFlag & EventDocumentActivated) != 0)
            {
                foreach (DocumentStorage item in SDocs)
                {
                    if (item.MGuid == mapGuid) // map was opened before
                    {
                        foreach (Timers _item in Maps.MapsGroup.TIMERS)
                        {
                            if (_item.m_Guid == mapGuid)
                            {
                                Maps.MapUsersDlg.status  = _item.m_Status;
                                Maps.MapUsersDlg.users   = _item.UsersOnline;
                                Maps.MapUsersDlg.blocker = _item.MapBlocker;
                                Maps.MapsGroup.dlgUsersOnline.Show(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd));
                                break;
                            }
                        }
                        break;
                    }
                }
                //else - map is opening, handle it in EventDocumentOpened
                _doc = null;
            }

            if ((eventFlag & EventDocumentOpened) != 0)
            {
                if (openMap)
                {
                    openMap = false;
                    _doc    = null;
                    return;
                }

                if (MapsGroup.LOGIN.logged == false) // user not logged in Synergy yet
                {
                    if (System.Windows.Forms.MessageBox.Show(MMUtils.GetString("maps.openmapnosynergy.message"),
                                                             MMUtils.GetString("maps.synergywarning.caption"), MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                        == DialogResult.Yes)
                    {
                        MapsGroup.LOGIN.m_cmdLogin_Click();
                    }

                    if (MapsGroup.LOGIN.logged == false)
                    {
                        reopentimer = false;
                        docToClose  = _doc;
                        _doc        = null;
                        closeMap_timer.Start();     // we can't close document within this event
                        return;
                    }
                }

                bool mapnotfound = false;

                using (MapsDB _db = new MapsDB())
                {
                    DataTable _dt = _db.ExecuteQuery("select * from MAPS where MAPGUID='" + mapGuid + "'");
                    if (_dt.Rows.Count == 0)
                    {
                        MessageBox.Show(String.Format(MMUtils.GetString("maps.openmapillegal.message"), _doc.Name),
                                        MMUtils.GetString("maps.synergywarning.caption"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        mapnotfound = true;
                    }
                    else // map found in MapsDB
                    {
                        docToClose = _doc;
                        docToOpen  = _dt.Rows[0]["LOCALPATH"].ToString();
                        docToCopy  = _dt.Rows[0]["PATHTOPLACE"].ToString();
                        File.SetAttributes(docToOpen, System.IO.FileAttributes.Normal);
                    }
                }

                if (mapnotfound)
                {
                    _doc = null;
                    return;
                }

                try
                {
                    docToCopy = Directory.GetFiles(docToCopy, "*.mmap").Last().ToString();
                }
                catch // can't access to _pathtofolder
                {
                    docToCopy = "";
                }

                if (docToCopy != "" && reopenmap == true)
                {
                    long localmap_lastwrite = Convert.ToInt64(File.GetLastWriteTimeUtc(docToOpen).ToString("yyyyMMddHHmmssfff"));
                    long placemap_time      = Convert.ToInt64(Path.GetFileNameWithoutExtension(docToCopy));

                    // reopen map to get last map copy from its Place
                    if (placemap_time > localmap_lastwrite)
                    {
                        reopentimer = true;
                        closeMap_timer.Start(); // we can't close document within this event
                        _doc = null;
                        return;                 // for reopen map
                    }
                }

                if (reopenmap == false)
                {
                    reopenmap = true;
                }

                docToClose = null;

                string fail = SUtils.ProcessMap(_doc);

                if (fail == "") // don't get changes if map offline
                {
                    SUtils.GetChanges(_doc);
                }

                _doc = null;
            }

            _doc = null;
        }