Beispiel #1
0
        /// <summary>
        /// Get ultimate changes from "share" folder
        /// </summary>
        public static void GetChanges(Document _doc)
        {
            string mapFolderPath = "";
            string mapGuid       = SUtils.SynergyMapGuid(_doc);

            using (MapsDB _db = new MapsDB())
            {
                DataTable _dt = _db.ExecuteQuery("select * from MAPS where MAPGUID=`" + mapGuid + "`");
                mapFolderPath = _dt.Rows[0]["PATHTOPLACE"].ToString();
            }

            string _latestfile = Directory.GetFiles(mapFolderPath, "*.mmap").Last().ToString();

            _latestfile = Path.GetFileNameWithoutExtension(_latestfile);

            string[] files = Directory.GetFiles(mapFolderPath + "share", "*.txt");

            long _latestfiletime = Convert.ToInt64(_latestfile);

            foreach (string file in files)
            {
                string _file = Path.GetFileNameWithoutExtension(file);
                string _user = _file.Substring(_file.IndexOf("&") + 1);
                if (_user == currentUserName)
                {
                    continue;
                }
                long _filetime = Convert.ToInt64(_file.Substring(0, _file.IndexOf("&")));

                if (_filetime > _latestfiletime)
                {
                    Changes.ReceiveChanges.GetChanges(_doc, file);
                }
            }
        }
Beispiel #2
0
        public static void Sync(Document aDoc, bool _add, string _mapPlaceFolder = "", bool _online = true)
        {
            if (_add)
            {
                MapCompanion startevents = new MapCompanion(aDoc)
                {
                    mc_MapFolderPath = _mapPlaceFolder
                };

                SDocs.Add(new DocumentStorage()
                {
                    MGuid = SUtils.SynergyMapGuid(aDoc),
                    Sdoc  = aDoc,
                    _mc   = startevents
                });
            }
            else // unsubscribe map
            {
                foreach (DocumentStorage item in SDocs)
                {
                    if (item.MGuid == SUtils.SynergyMapGuid(aDoc))
                    {
                        SDocs.Remove(item);
                        item.Sdoc = null;
                        item._mc.Dispose();
                        break;
                    }
                }
            }
        }
Beispiel #3
0
        void WaitOnline_timer_Tick(object sender, EventArgs e)
        {
            waitOnline_timer.Stop();

            if (Internet.CheckInternetAndProcess(m_Guid, m_Storage, m_Process, m_Site, m_PlacePath, "wait_timer") != "")
            {
                return;
            }

            MessageBox.Show(String.Format(MMUtils.GetString("internet.maponline.message"), doc.Name),
                            MMUtils.GetString("internet.maponline.caption"));

            string _lastfile     = Directory.GetFiles(m_PlacePath, "*.mmap").Last().ToString();
            long   placemap_time = Convert.ToInt64(Path.GetFileNameWithoutExtension(_lastfile));

            DocumentStorage.closeMap = true;
            doc.Close();

            File.SetAttributes(m_LocalPath, System.IO.FileAttributes.Normal);

            // Get last copy from Place
            if (placemap_time > m_FrozenTime)
            {
                File.Copy(_lastfile, m_LocalPath, true);
            }
            // Or return frozen file
            else
            {
                File.Copy(m_FrozenPath, m_LocalPath, true);
            }

            DocumentStorage.openMap = true;
            MMUtils.MindManager.AllDocuments.Open(m_LocalPath);
            doc = MMUtils.ActiveDocument;

            m_Status = "online";
            GetOnlineUsers();

            DocumentStorage.Sync(doc, true, m_PlacePath);                      // subscribe map

            Watchers WW = new Watchers(m_PlacePath + "share", m_PlacePath, "") // TODO project path!
            {
                doc      = doc,
                aMapGuid = m_Guid
            };

            Maps.MapsGroup.WATCHERS.Add(WW);

            SUtils.GetChanges(doc);

            saveMap_timer.Start();
            checkOnlineUsers_timer.Start();
            refreshIndicator_timer.Start();

            if (doc == MMUtils.ActiveDocument)
            {
                refresh = true;
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_doc">Map to process</param>
        /// <returns>fail</returns>
        public static string ProcessMap(Document _doc)
        {
            string _guid = SUtils.SynergyMapGuid(_doc);
            string _storage = "", _process = "", _site = "",
                   _placemapfolderpath = "", // full path to map folder in its Place
                   _placename          = "", // place name - for Frozen Path
                   _projectname        = "", // place name - for Frozen Path
                   _projectpath        = "",
                   _mapblocker         = "", // who blocks the map
                   _unlocktime         = "", // hh:mm when map will be unlocked
                   fail = "";

            int _secToSaveMap = 105, _secToWait = 100, _minLockTime = 1;

            string   _docName       = _doc.Name;
            FileInfo file           = new FileInfo(_doc.FullName);
            float    fileMBytesSize = file.Length / 1048576;

            file = null;

            _secToSaveMap = _secToSaveMap + Convert.ToInt32(fileMBytesSize * 15);
            _secToWait    = _secToSaveMap + Convert.ToInt32(fileMBytesSize * 20);

            GetMapData(_guid, ref _storage, ref _process, ref _site, ref _placemapfolderpath,
                       ref _placename, ref _projectname, ref _projectpath);

            if (_placemapfolderpath == "" || _placename == "")
            {
                return("nomap");
            }

            // TODO check if map is locked
            string blockerPath = _placemapfolderpath + "info.locker";

            if (File.Exists(blockerPath))
            {
                string       _datetime;
                StreamReader sr = new StreamReader(blockerPath);
                _mapblocker  = sr.ReadLine().Trim();
                _datetime    = sr.ReadLine();
                _minLockTime = Convert.ToInt32(sr.ReadLine().Trim());
                sr.Close();

                // TODO UTC??
                DateTime.TryParse(_datetime, out DateTime _lockedtime);
                TimeSpan timeleft = _lockedtime.AddMinutes(_minLockTime) - DateTime.UtcNow;
                _minLockTime = timeleft.Minutes;
                _unlocktime  = DateTime.UtcNow.AddMinutes(_minLockTime).ToLocalTime().ToString(); // hh:mm

                if (_minLockTime < 0)                                                             // время блокировки истекло
                {
                    _minLockTime = 1;
                    _mapblocker  = "";
                    File.Delete(blockerPath);
                }
            }

            string _frozenPath = MMUtils.m_SynergyTempPath + _placename + "\\";

            try
            {
                Directory.CreateDirectory(_frozenPath);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show(
                    "Невозможно создать папку\n\n" + _frozenPath, "Очень плохо. Прекратить работу");
                return("path");
            }

            if (_projectname == "")
            {
                _frozenPath = _frozenPath + _docName;
            }
            else
            {
                Directory.CreateDirectory(_frozenPath + _projectname);
                _frozenPath = _frozenPath + _projectname + "\\" + _docName;
            }

            Timers timer = new Timers(_secToSaveMap, _secToWait, _minLockTime)
            {
                doc          = _doc,
                m_Guid       = _guid,
                m_Storage    = _storage,
                m_Process    = _process,
                m_Site       = _site,
                m_PlacePath  = _placemapfolderpath,
                m_LocalPath  = _doc.FullName,
                m_FrozenPath = _frozenPath,
                MapBlocker   = _mapblocker,
                unLockTime   = _unlocktime,
                refresh      = false
            };

            Maps.MapsGroup.TIMERS.Add(timer);

            DocumentStorage.Sync(_doc, true, _placemapfolderpath);

            if (_mapblocker != "")
            {
                fail = "locked";
            }
            else
            {
                fail = Internet.CheckInternetAndProcess(_guid, _storage, _process, _site, _placemapfolderpath, "SUtils");
            }

            timer.refreshIndicator_timer.Start();
            timer.IP_timer.Start();

            if (fail == "")
            {
                timer.m_Status = "online";
                timer.GetOnlineUsers();
                timer.IP_timer.Start(); // start watching for Internet & Process
                timer.saveMap_timer.Start();
                timer.checkOnlineUsers_timer.Start();
            }
            else
            {
                if (fail == "sitefail")
                {
                    timer.m_Status = "offline";
                }

                if (fail == "processfail")
                {
                    timer.m_Status = "offline";
                }

                if (fail == "locked")
                {
                    timer.lock_timer.Start();
                    timer.m_Status = "locked";
                }
            }

            Watchers WW = new Watchers(_placemapfolderpath + "share", _placemapfolderpath, _projectpath)
            {
                doc      = _doc,
                aMapGuid = _guid
            };

            Maps.MapsGroup.WATCHERS.Add(WW);

            if (_doc == MMUtils.ActiveDocument && skipActiveMap == false)
            {
                Maps.MapUsersDlg.status = timer.m_Status;

                if (timer.m_Status == "online")
                {
                    if (timer.UsersOnline.Count > 0)
                    {
                        Maps.MapUsersDlg.users = timer.UsersOnline;
                    }
                }

                //if (timer.m_Status == "offline")
                //{
                //    // передать причину
                //}

                if (timer.m_Status == "locked")
                {
                    Maps.MapUsersDlg.blocker = _mapblocker;
                    // передать время окончания блокировки
                }

                Maps.MapsGroup.dlgUsersOnline.Show(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd));
            }

            skipActiveMap = false;

            return(fail);
        }
Beispiel #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;
        }
Beispiel #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;
        }