Beispiel #1
0
        void m_cmdShareMap_Click()
        {
            string mapGuid = SUtils.SynergyMapGuid(MMUtils.ActiveDocument);

            foreach (Timers item in TIMERS)
            {
                if (item.m_Guid == mapGuid)
                {
                    using (ShareMapDlg _dlg = new ShareMapDlg(MMUtils.ActiveDocument.Name, item.m_PlacePath))
                        _dlg.ShowDialog(new WindowWrapper((IntPtr)MMUtils.MindManager.hWnd));
                    break;
                }
            }
        }
Beispiel #2
0
        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;
        }