/// <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); } } }
/// <summary> /// Add map to MapsDB /// </summary> /// <param name="aStorage">Storage name</param> /// <param name="aPlace">Place name</param> /// <param name="aProject"> Project name</param> /// <param name="aGuid">Map Synergy guid</param> /// <param name="aMapName">Map file name</param> /// <param name="aPathToPlace">Path to map folder in Place - with backslash!</param> /// <param name="aLocalPath">Path to map in Local Storage</param> public static void AddMapToDB(string aStorage, string aPlace, string aProject, string aGuid, string aMapName, string aPathToPlace, string aLocalPath, string pubAttrs) { using (MapsDB _db = new MapsDB()) { _db.ExecuteNonQuery("INSERT INTO MAPS VALUES(" + "`" + aStorage + "`," + "`" + aPlace + "`," + "`" + aProject + "`," + "`" + aGuid + "`," + "`" + aMapName + "`," + "`" + aPathToPlace + "`," + "`" + aLocalPath + "`," + "`" + pubAttrs + "`, ``, 0, ``, 0)"); } }
/// <summary> /// Get Storage name and Process and Site if map is in cloud storage /// </summary> /// <returns> /// true: map is in cloud storage; get refs /// false: otherwise /// </returns> public static void GetMapData(string mapGuid, ref string aStorage, ref string aProcess, ref string aSite, ref string aPath, ref string aPlaceName, ref string aProjectName, ref string aProjectPath) { using (MapsDB _db = new MapsDB()) { DataTable _dt = _db.ExecuteQuery("select * from MAPS where MAPGUID=`" + mapGuid + "`"); if (_dt.Rows.Count != 0) { aStorage = _dt.Rows[0]["STORAGE"].ToString(); aPath = _dt.Rows[0]["PATHTOPLACE"].ToString(); aPlaceName = _dt.Rows[0]["PLACENAME"].ToString(); aProjectName = _dt.Rows[0]["PROJECTNAME"].ToString(); } } if (aProjectName != "") { using (ProjectsDB _db = new ProjectsDB()) { DataTable _dt = _db.ExecuteQuery("select * from PROJECTS where PROJECTNAME=`" + aProjectName + "`"); aProjectPath = _dt.Rows[0]["PROJECTPATH"].ToString(); } } if (aStorage == "ND") { return; } using (StoragesDB _db = new StoragesDB()) { DataTable _dt = _db.ExecuteQuery("select * from STORAGES where STORAGENAME=`" + aStorage + "`"); if (_dt.Rows.Count != 0) { aProcess = _dt.Rows[0]["PROCESS"].ToString(); aSite = _dt.Rows[0]["SITE"].ToString(); } } }
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; }