コード例 #1
0
        public void Initialize()
        {
            AutosaveCycle.onTimeLeft += new EventHandler(AutosaveCycle_onTimeLeft);

            ReadSettings();

            if (AutosaveOn)
            {
                AutosaveCycle.Start();
            }

            if (RestartAutosaveCycleOnDocSave)
            {
                Application.DocumentManager.DocumentActivated       += DcDocumentActivated;
                Application.DocumentManager.DocumentToBeDeactivated += DcDocumentToBeDeactivated;

                var doc = Application.DocumentManager.MdiActiveDocument;
                var db  = doc.Database;
                db.SaveComplete += new DatabaseIOEventHandler(DbSaveComplete);
            }

            if (SaveAsInAutosaveDirDocOpenedForReadOnly)
            {
                Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DcDocumentCreated);
            }
        }
コード例 #2
0
        public static void SendCommand(string CommadName)
        {
            //через COM так как там есть объект nanoCAD.State - по нему можно определить занят NC или нет
            nanoCAD.Application NC = null;
            GetAcadApplication.GetNC(ref NC);

            if (NC == null)
            {
                //Обработка ошибки COM
                if (Application.DocumentManager.Count == 0)
                {
                    return;
                }

                var doc0 = Application.DocumentManager.MdiActiveDocument;
                var ed0  = doc0.Editor;

                ed0.WriteMessage("Не удалось получить nanoCAD.Application. Операция прекращена");
                //остановка таймера
                AutosaveCycle.Stop();

                return;
            }

            nanoCAD.Document doc = null;
            if (NC.Documents.Count > 0)
            {
                doc = NC.ActiveDocument;
            }

            if (doc != null)
            {
                //тут надо запускать таймер на предеьное время ожидания, и выходить если оно превышено
                if (WaitIdleNc(ref NC, 300)) //дожидаемся когда NC освободится, 5 минут максимум
                {
                    doc.SendCommand(CommadName);
                }
                else
                {
                    //ждали больше 5 мин и приложение так и не освободилось
                }
            }
        }
コード例 #3
0
 public static void ResetCustomAutosaveCycleCmd()
 {
     AutosaveCycle.Stop();
     Thread.Sleep(100);
     AutosaveCycle.Start();
 }
コード例 #4
0
        public static void CustomAutosaveSettingsCmd()
        {
            var s = new SettingsForm();

            Autosave1.ReadSettings();

            s.checkBox1.Checked = Autosave1.AutosaveOn;

            s.checkBox4.Checked = Autosave1.RestartAutosaveCycleOnDocSave;

            s.checkBox3.Checked = Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly;

            for (int i1 = 1; i1 < 61; i1++)
            {
                s.comboBox1.Items.Add(i1.ToString());
            }

            int AutosaveCycleTimeMin = -1; int.TryParse(((double)Autosave1.AutosaveCycleTime / 60000).ToString(), out AutosaveCycleTimeMin);

            if (AutosaveCycleTimeMin != -1)
            {
                s.comboBox1.Text = AutosaveCycleTimeMin.ToString();
            }

            for (int i1 = 1; i1 < 31; i1++)
            {
                s.comboBox2.Items.Add(i1.ToString());
            }

            s.comboBox2.Text = Autosave1.StorageTime.ToString();

            s.textBox1.Text = Autosave1.DirName;

            s.checkBox2.Checked = Autosave1.CreateDir;

            s.textBox2.Text = Autosave1.DirPath;

            var dr = s.ShowDialog();

            if (dr != DialogResult.OK)
            {
                s.shouldStop = true;
                return;
            }

            if (!Autosave1.AutosaveOn && s.checkBox1.Checked)
            {
                AutosaveCycle.Start();
            }
            else if (Autosave1.AutosaveOn && !s.checkBox1.Checked)
            {
                AutosaveCycle.Stop();
            }

            Autosave1.AutosaveOn = s.checkBox1.Checked;


            if (!Autosave1.RestartAutosaveCycleOnDocSave && s.checkBox4.Checked)
            {
                Application.DocumentManager.DocumentActivated       += Autosave1.DcDocumentActivated;
                Application.DocumentManager.DocumentToBeDeactivated += Autosave1.DcDocumentToBeDeactivated;

                var doc = Application.DocumentManager.MdiActiveDocument;
                var db  = doc.Database;
                db.SaveComplete += new DatabaseIOEventHandler(Autosave1.DbSaveComplete);
            }
            else if (Autosave1.RestartAutosaveCycleOnDocSave && !s.checkBox4.Checked)
            {
                Application.DocumentManager.DocumentActivated       -= Autosave1.DcDocumentActivated;
                Application.DocumentManager.DocumentToBeDeactivated -= Autosave1.DcDocumentToBeDeactivated;

                var doc = Application.DocumentManager.MdiActiveDocument;
                var db  = doc.Database;
                db.SaveComplete -= new DatabaseIOEventHandler(Autosave1.DbSaveComplete);
            }

            Autosave1.RestartAutosaveCycleOnDocSave = s.checkBox4.Checked;


            if (!Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly && s.checkBox3.Checked)
            {
                Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(Autosave1.DcDocumentCreated);
            }
            else if (Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly && !s.checkBox3.Checked)
            {
                Application.DocumentManager.DocumentCreated -= new DocumentCollectionEventHandler(Autosave1.DcDocumentCreated);
            }

            Autosave1.SaveAsInAutosaveDirDocOpenedForReadOnly = s.checkBox3.Checked;


            int.TryParse(s.comboBox1.Text, out Autosave1.AutosaveCycleTime);
            Autosave1.AutosaveCycleTime = Autosave1.AutosaveCycleTime * 60000;

            int.TryParse(s.comboBox2.Text, out Autosave1.StorageTime);

            Autosave1.DirName = s.textBox1.Text;

            Autosave1.CreateDir = s.checkBox2.Checked;

            Autosave1.DirPath = s.textBox2.Text;

            Autosave1.WriteSettings();

            s.shouldStop = true;
        }