public void m_command_Click() // open map { string aMapGuid = m_command.ToolTip; string _mapName = m_command.Caption; string _mapPlacePath = ""; string aStorage = ""; string _mapLocalPath = ""; bool mapnotfound = true; using (MapsDB _db = new MapsDB()) { System.Data.DataTable _dt = _db.ExecuteQuery("select * from MAPS where MAPGUID=`" + aMapGuid + "`"); if (_dt.Rows.Count != 0) { mapnotfound = false; _mapLocalPath = _dt.Rows[0]["LOCALPATH"].ToString(); _mapPlacePath = _dt.Rows[0]["PATHTOPLACE"].ToString(); aStorage = _dt.Rows[0]["STORAGE"].ToString(); } } if (mapnotfound) { System.Windows.Forms.MessageBox.Show(String.Format(MMUtils.GetString("maps.mapnoexists.message"), _mapName), MMUtils.GetString("maps.mapnoexists.caption")); return; // TODO нужно предложить удалить ее - из БД и из меню } // if map is opened already foreach (Document _map in MMUtils.MindManager.AllDocuments) { if (SUtils.SynergyMapGuid(_map) == aMapGuid) { _map.Activate(); return; } } if (Directory.Exists(_mapPlacePath)) // TODO если по причине неподключенного сетевого диска - { string _latestfile = Directory.GetFiles(_mapPlacePath, "*.mmap").Last().ToString(); long localmap_lastwrite = Convert.ToInt64(File.GetLastWriteTimeUtc(_mapLocalPath).ToString("yyyyMMddHHmmssfff")); long placemap_time = Convert.ToInt64(Path.GetFileNameWithoutExtension(_latestfile)); // Check if map in Place is newer than local map, if yes - replace local map if (placemap_time > localmap_lastwrite) { try { File.Copy(_latestfile, _mapLocalPath, true); // copy (overwrite) map from its Place to local Synergy } catch { } // TODO } } DocumentStorage.reopenmap = false; System.IO.File.SetAttributes(_mapLocalPath, System.IO.FileAttributes.Normal); MMUtils.MindManager.AllDocuments.Open(_mapLocalPath); }
public void Init() { login_timer = new Timer(); login_timer.Interval = 50; login_timer.Tick += new EventHandler(Login_timer_Tick); // Init databases MapsDB _dbMaps = new MapsDB(); _dbMaps.Dispose(); UsersDB _dbUsers = new UsersDB(); _dbUsers.Dispose(); StoragesDB _dbStorages = new StoragesDB(); _dbStorages.Dispose(); PlacesDB _dbMyPlaces = new PlacesDB(); _dbMyPlaces.Dispose(); ProjectsDB _dbMyProjects = new ProjectsDB(); _dbMyProjects.Dispose(); CreateLogin(); }
private void BtnOK_Click(object sender, EventArgs e) { string _docName = publishDoc.Name; string aPlaceName = comboMyPlaces.Text; string aGuid = publishDoc.Guid; string aLocalPath = ""; string aPath = ""; // full path to published map string aSite = ""; // website to check for Internet connection string aProcess = ""; // cloud app process to check if started string _projectName = ""; string aStorage = ""; // name of cloud app string aProjectPath = ""; bool singleMap = chBoxSingleMap.Checked; if (!singleMap) { _projectName = comboMyProjects.Text; } // Single Maps if (singleMap) { using (PlacesDB _db = new PlacesDB()) { DataTable _dt = _db.ExecuteQuery("select * from PLACES where PLACENAME='" + aPlaceName + "'"); aProjectPath = _dt.Rows[0]["PLACEPATH"].ToString(); aStorage = _dt.Rows[0]["STORAGE"].ToString(); aLocalPath = MMUtils.m_SynergyLocalPath + aPlaceName + "\\"; } } // Projects else { using (ProjectsDB _db = new ProjectsDB()) { DataTable _dt = _db.ExecuteQuery( "select * from PROJECTS where PROJECTNAME='" + _projectName + "' and PLACENAME='" + aPlaceName + "'"); aProjectPath = _dt.Rows[0]["PROJECTPATH"].ToString(); aStorage = _dt.Rows[0]["STORAGE"].ToString(); aLocalPath = MMUtils.m_SynergyLocalPath + aPlaceName + "\\" + _projectName + "\\"; } } if (publishDoc.Path == "") // new map not saved yet { using (NewMapDlg _dlg = new NewMapDlg()) { if (_dlg.ShowDialog(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd)) == DialogResult.Cancel) { return; } _docName = _dlg.textBox_MapName.Text + ".mmap"; } } aLocalPath = aLocalPath + _docName; using (StoragesDB _db = new StoragesDB()) { DataTable _dt = _db.ExecuteQuery("select * from STORAGES where STORAGENAME='" + aStorage + "'"); aProcess = _dt.Rows[0]["PROCESS"].ToString(); aSite = _dt.Rows[0]["SITE"].ToString(); } // Full path to map in Place aPath = Path.Combine(aProjectPath, _docName); // TODO предложить выбрать сохранение под другим именем if (Directory.Exists(aPath)) // map with this name is stored already in this place { System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show( MMUtils.GetString("publishmapdlg.mapexists.message"), MMUtils.GetString("publishmapdlg.mapexists.caption"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); return; } string fail = ""; string messageSite = MMUtils.GetString("internet.sitefailed.message"); string messageProcess = MMUtils.GetString("internet.processfailed.message"); string messagePlace = MMUtils.GetString("internet.placefail.message"); string endMessage = MMUtils.GetString("internet.failed.endpubmessage"); while ((fail = Internet.CheckInternetAndProcess(aGuid, aStorage, aProcess, aSite, "", "publish")) != "") { string _message = "", arg = ""; if (fail == "processfail") { _message = messageProcess; arg = aStorage; } else if (fail == "placefail") { _message = messagePlace; arg = aPath; } else if (fail == "sitefail") { _message = messageSite; arg = aSite; } if (System.Windows.Forms.MessageBox.Show( String.Format(_message, arg) + endMessage, String.Format(MMUtils.GetString("internet.failed.caption"), _docName), System.Windows.Forms.MessageBoxButtons.RetryCancel, System.Windows.Forms.MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Cancel) { this.DialogResult = DialogResult.Cancel; publishDoc = null; return; } if (fail == "sitefail") { System.Diagnostics.Process.Start(arg); // launch website } } try // Save map to Local { publishDoc.SaveAs(aLocalPath); } catch (Exception _e) // TODO cause!!! read-only, etc... имя файла уже исключено выше { MessageBox.Show("Error: " + _e.Message, "PublishMapDlg", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; publishDoc = null; return; } //// Publish Map = set attributes to map, topics, relationships and boundaries and process links //// SUtils.singleMap = singleMap; Mindjet.MindManager.Interop.Transaction _tr = publishDoc.NewTransaction(""); _tr.IsUndoable = false; _tr.Execute += new Mindjet.MindManager.Interop.ITransactionEvents_ExecuteEventHandler(SUtils.PublishMap); _tr.Start(); /////////////////////////////////////////////////////////////////////////////////// publishDoc.Save(); if (SUtils.links.Count > 0) { using (LinkedFilesDlg _dlg = new LinkedFilesDlg(SUtils.links, publishDoc)) { DialogResult result = _dlg.ShowDialog(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd)); SUtils.links.Clear(); if (result == DialogResult.Cancel) { this.DialogResult = DialogResult.Cancel; publishDoc = null; return; } } } aPath = aPath + "\\"; // Map folder string mapFile = SUtils.modtime + ".mmap"; try // save map to Place { Directory.CreateDirectory(aPath + "share"); File.Copy(aLocalPath, aPath + mapFile); // copy as file!!! StreamWriter sw = new StreamWriter(File.Create(aPath + "info.ini")); sw.WriteLine(aStorage); // чтобы если нет Интернета или Процесса, выдать сообщение с именем хранилища sw.WriteLine(_projectName); // чтобы находить карту из Места в локальной папке Synergy sw.WriteLine(aGuid); sw.WriteLine(aProcess); // чтобы проверить Интернет и Процесс sw.WriteLine(aSite); // чтобы проверить Интернет и Процесс sw.Close(); } catch (Exception _e) // TODO cause!!! read-only, etc... { MessageBox.Show(this, "Error " + _e.Message, "title", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; publishDoc = null; return; } MapsDB.AddMapToDB( aStorage, aPlaceName, _projectName, aGuid, _docName, aPath, // aPath - map directory in Place, with backslash aLocalPath, DateTime.UtcNow.ToString() + ";" + SUtils.currentUserName + ";" + SUtils.currentUserEmail ); MapsGroup.m_UpdateOpenMap = true; // update Open Map submenu SUtils.ProcessMap(publishDoc); // Share map using (ShareMapDlg _dlg = new ShareMapDlg(MMUtils.ActiveDocument.Name, aPath)) { _dlg.ShowDialog(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd)); } this.DialogResult = DialogResult.OK; publishDoc = null; }
void Reopenmaps_Timer_Tick(object sender, EventArgs e) { reopenmaps_timer.Stop(); string mapPlacePath = ""; for (int i = 0; i < _reopenmaps.Count; i++) { bool mapnotfound = true; string mapLocalPath = _reopenmaps[i].FullName; File.SetAttributes(mapLocalPath, System.IO.FileAttributes.Normal); using (MapsDB _db = new MapsDB()) { DataTable _dt = _db.ExecuteQuery("select * from MAPS where LOCALPATH='" + mapLocalPath + "'"); if (_dt.Rows.Count != 0) { mapnotfound = false; mapPlacePath = _dt.Rows[0]["PATHTOPLACE"].ToString(); } } try { mapPlacePath = Directory.GetFiles(mapPlacePath, "*.mmap").Last().ToString(); } catch { mapPlacePath = ""; } if (i == _reopenmaps.Count - 1) // last document will be opened, it will be active { SUtils.skipActiveMap = false; } else { SUtils.skipActiveMap = true; } // We have to reopen map to get last map copy from its Place if (!mapnotfound && mapPlacePath != "") // map and its placepath found { long localmap_lastwrite = Convert.ToInt64(File.GetLastWriteTimeUtc(mapLocalPath).ToString("yyyyMMddHHmmssfff")); long placemap_time = Convert.ToInt64(Path.GetFileNameWithoutExtension(mapPlacePath)); if (placemap_time <= localmap_lastwrite) { string fail = SUtils.ProcessMap(_reopenmaps[i]); if (fail == "") { SUtils.GetChanges(_reopenmaps[i]); } continue; } } DocumentStorage.closeMap = true; _reopenmaps[i].Close(); // if map or map place not found this will be resolved in the afterOpenMap event if (!mapnotfound && mapPlacePath != "") { File.Copy(mapPlacePath, mapLocalPath, true); // copy (overwrite) map from its Place to local Synergy } DocumentStorage.reopenmap = false; MMUtils.MindManager.AllDocuments.Open(mapLocalPath); } _reopenmaps.Clear(); DestroyTimer(); }
public void m_cmdOpenMaps_UpdateState(ref bool pEnabled, ref bool pChecked) { pEnabled = true; pChecked = false; if (!m_UpdateOpenMap) { return; } m_UpdateOpenMap = false; int a = 1; List <string> aProjects = new List <string>(); List <string> aSingleMaps = new List <string>(); if (OpenButtons.Count != 0) { foreach (SubMenus item in OpenButtons) { item.Destroy(); } for (int i = 0; i < Labels.Count; i++) { Labels[i].Delete(); Marshal.ReleaseComObject(Labels[i]); Labels[i] = null; } } OpenButtons.Clear(); Labels.Clear(); using (ProjectsDB _db = new ProjectsDB()) { DataTable _dt = _db.ExecuteQuery("select * from PROJECTS order by PROJECTNAME"); foreach (DataRow _row in _dt.Rows) { aProjects.Add(_row["PROJECTNAME"].ToString()); } } using (PlacesDB _db = new PlacesDB()) { DataTable _dt = _db.ExecuteQuery("select * from PLACES order by PLACENAME"); foreach (DataRow _row in _dt.Rows) { aSingleMaps.Add(_row["PLACENAME"].ToString()); } } using (MapsDB _db = new MapsDB()) { bool _label = true; Control m_label = null; // Get maps by projects foreach (string _project in aProjects) { DataTable _dt = _db.ExecuteQuery("select * from MAPS where PROJECTNAME=`" + _project + "` order by MAPNAME"); foreach (DataRow _row in _dt.Rows) { if (_label) { m_label = m_ctrlOpenMaps.Controls.AddLabel(_project); _label = false; Labels.Add(m_label); } m_menus = new SubMenus(); OpenButtons.Add(m_menus); m_menus.AddMapToOpenMenu(_row["MAPGUID"].ToString(), _row["MAPNAME"].ToString(), "map" + a++); } _label = true; } //_label = true; // Get single maps foreach (string _place in aSingleMaps) { DataTable _dt = _db.ExecuteQuery("select * from MAPS where PROJECTNAME = `" + "" + "` and PLACENAME=`" + _place + "` order by MAPNAME"); //DataTable __dt = _db.ExecuteQuery("select * from MAPS"); foreach (DataRow _row in _dt.Rows) { if (_label) { m_label = m_ctrlOpenMaps.Controls.AddLabel(_place + ": " + SUtils.SingleMaps); _label = false; Labels.Add(m_label); } m_menus = new SubMenus(); OpenButtons.Add(m_menus); m_menus.AddMapToOpenMenu(_row["MAPGUID"].ToString(), _row["MAPNAME"].ToString(), "map" + a++); } _label = true; } aProjects.Clear(); aSingleMaps.Clear(); } }
private void BtnOK_Click(object sender, EventArgs e) { if (txtFolderPath.Text == "") { lblReceivedFolderPath.ForeColor = System.Drawing.Color.Red; return; } string aMapName = new DirectoryInfo(aMapFolderPath).Name; string aPlaceName = comboPlaces.Text; string mapStorage = ""; string aGuid = ""; string aProject = ""; string aLocalPath = ""; if (rbtnProject.Checked == true) { aProject = comboProjects.Text; } try { StreamReader sr = new StreamReader(aMapFolderPath + "info.ini"); mapStorage = sr.ReadLine(); sr.ReadLine(); aGuid = sr.ReadLine(); sr.Close(); } catch { MessageBox.Show("Не удается создать файл info.ini. Нет доступа к папке", "Сбой"); return; } if (aMapName.IndexOf(".mmap") == -1) { if (aMapName.IndexOf("$$") == 0) // project folder { MessageBox.Show(MMUtils.GetString("receivemapdlg.project.message"), MMUtils.GetString("receivemapdlg.project.caption")); } else // unknown folder { MessageBox.Show(MMUtils.GetString("receivemapdlg.nomap.message"), MMUtils.GetString("receivemapdlg.nomap.caption")); } return; } if (!File.Exists(aMapFolderPath + "info.ini")) { MessageBox.Show(MMUtils.GetString("getplacedlg.nomapinfo.message"), MMUtils.GetString("getplacedlg.nomapinfo.caption")); return; } if (aStorage != mapStorage) { MessageBox.Show(String.Format(MMUtils.GetString("getplacedlg.storagenomatches.message"), aStorage, mapStorage), MMUtils.GetString("getplacedlg.storagenomatches.caption")); return; } string _latestfile = ""; try { _latestfile = Directory.GetFiles(aMapFolderPath, "*.mmap").Last().ToString(); } catch { MessageBox.Show("Не удается найти файл карты", "Сбой"); return; } _latestfile = Path.GetFileName(_latestfile); string _placePath = aPlacePath; aPlacePath = aPlacePath + aMapName + "\\"; // TODO проверить, может такая карта есть!!! if (rbtnPlace.Checked == true) { aLocalPath = MMUtils.m_SynergyLocalPath + aPlaceName + "\\" + aMapName; string _newmapname = CheckMapExists(aLocalPath, aMapName); if (_newmapname == "cancel") { return; } if (_newmapname != "") { aMapName = _newmapname; aPlacePath = _placePath + aMapName + "\\"; } Directory.Move(aMapFolderPath, aPlacePath); } if (rbtnLeaveInPlace.Checked == true) { aLocalPath = MMUtils.m_SynergyLocalPath + aPlaceName + "\\" + aMapName; string _newmapname = CheckMapExists(aLocalPath, aMapName); if (_newmapname == "cancel") { return; } if (_newmapname != "") { aMapName = _newmapname; DirectoryInfo dir = new DirectoryInfo(aMapFolderPath).Parent; string newplace = dir.FullName + "\\" + aMapName + "\\"; Directory.Move(aMapFolderPath, newplace); aMapFolderPath = newplace; } aPlacePath = aMapFolderPath; } if (rbtnProject.Checked == true) { aLocalPath = MMUtils.m_SynergyLocalPath + aPlaceName + "\\" + aProject + "\\" + aMapName; string _newmapname = CheckMapExists(aLocalPath, aMapName); if (_newmapname == "cancel") { return; } if (_newmapname != "") { aMapName = _newmapname; aPlacePath = _placePath + aMapName + "\\"; } Directory.Move(aMapFolderPath, aPlacePath + aProject); } try { File.Copy(aPlacePath + _latestfile, aLocalPath); } catch { MessageBox.Show("Не могу скопировать карту в локаль", "Сбой"); return; } string _attrs = SUtils.TimeStamp + ";" + SUtils.currentUserName + ";" + SUtils.currentUserEmail; MapsDB.AddMapToDB(aStorage, aPlaceName, aProject, aGuid, aMapName, aPlacePath, aLocalPath, _attrs); Maps.MapsGroup.m_UpdateOpenMap = true; MMUtils.MindManager.AllDocuments.Open(aLocalPath); this.DialogResult = DialogResult.OK; }