Exemple #1
0
        // 2015/9/15
        public static void EnvironmentReport(MainForm mainForm)
        {
#if NO
            MessageBar _messageBar = null;

            _messageBar         = new MessageBar();
            _messageBar.TopMost = false;
            //_messageBar.BackColor = SystemColors.Info;
            //_messageBar.ForeColor = SystemColors.InfoText;
            _messageBar.Text          = "dp2Circulation 出现异常";
            _messageBar.MessageText   = "正在向 dp2003.com 发送异常报告 ...";
            _messageBar.StartPosition = FormStartPosition.CenterScreen;
            _messageBar.Show(_mainForm);
            _messageBar.Update();
#endif
            int    nRet     = 0;
            string strError = "";
            try
            {
                string strSender = "";
                if (mainForm != null)
                {
                    strSender = mainForm.GetCurrentUserName() + "@" + mainForm.ServerUID;
                }
                // 崩溃报告
                nRet = LibraryChannel.CrashReport(
                    strSender,
                    "dp2circulation 环境报告",
                    GetEnvironmentDescription().Replace("\t", "    "),
                    out strError);
            }
            catch (Exception ex)
            {
                strError = "CrashReport() 过程出现异常: " + ExceptionUtil.GetDebugText(ex);
                nRet     = -1;
            }
            finally
            {
#if NO
                _messageBar.Close();
                _messageBar = null;
#endif
            }

#if NO
            if (nRet == -1)
            {
                strError = "向 dp2003.com 发送异常报告时出错,未能发送成功。详细情况: " + strError;
                MessageBox.Show(_mainForm, strError);
                // 写入错误日志
                if (_mainForm != null)
                {
                    _mainForm.WriteErrorLog(strError);
                }
                else
                {
                    WriteWindowsLog(strError, EventLogEntryType.Error);
                }
            }
#endif
        }
Exemple #2
0
        // 验证性连接服务器
        int TestConnectServer(out string strError)
        {
            strError = "";

            // 如果是即将访问 dp2libraryXE 单机版,这里要启动它
            if (string.Compare(this.textBox_server_dp2LibraryServerUrl.Text,
                               CirculationLoginDlg.dp2LibraryXEServerUrl, true) == 0)
            {
                string strShortcutFilePath = PathUtil.GetShortcutFilePath("DigitalPlatform/dp2 V3/dp2Library XE V3");
                if (File.Exists(strShortcutFilePath) == false)
                {
                    // 安装和启动
                    DialogResult result = MessageBox.Show(this,
                                                          "dp2libraryXE 在本机尚未安装。\r\ndp2Circulation (内务)即将访问 dp2LibraryXE 单机版服务器,需要安装它才能正常使用。\r\n\r\n是否立即从 dp2003.com 下载安装?",
                                                          "dp2Circulation",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button1);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        FormClientUtil.StartDp2libraryXe(
                            this,
                            "dp2Circulation",
                            this.Font,
                            false);
                    }
                }
                else
                {
                    if (FormClientUtil.HasDp2libraryXeStarted() == false)
                    {
                        FormClientUtil.StartDp2libraryXe(
                            this,
                            "dp2Circulation",
                            this.Font,
                            true);
                    }
                }
            }


            MessageBar _messageBar = null;

            _messageBar               = new MessageBar();
            _messageBar.TopMost       = false;
            _messageBar.Font          = this.Font;
            _messageBar.BackColor     = SystemColors.Info;
            _messageBar.ForeColor     = SystemColors.InfoText;
            _messageBar.Text          = "欢迎使用 dp2Circulation";
            _messageBar.MessageText   = "正在验证连接服务器,请等待 ...";
            _messageBar.StartPosition = FormStartPosition.CenterScreen;
            _messageBar.Show(this);
            _messageBar.Update();

            try
            {
                int nRet = TouchServer(true, out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                return(0);
            }
            finally
            {
                _messageBar.Close();
                _messageBar = null;
            }
        }
Exemple #3
0
        static void CrashReport(string strText)
        {
            // MainForm main_form = Form.ActiveForm as MainForm;

            MessageBar _messageBar = null;

            _messageBar         = new MessageBar();
            _messageBar.TopMost = false;
            //_messageBar.BackColor = SystemColors.Info;
            //_messageBar.ForeColor = SystemColors.InfoText;
            _messageBar.Text          = "dp2Circulation 出现异常";
            _messageBar.MessageText   = "正在向 dp2003.com 发送异常报告 ...";
            _messageBar.StartPosition = FormStartPosition.CenterScreen;
            _messageBar.Show(_mainForm);
            _messageBar.Update();

            int    nRet     = 0;
            string strError = "";

            try
            {
                string strSender = "";
                if (_mainForm != null)
                {
                    strSender = _mainForm.GetCurrentUserName() + "@" + _mainForm.ServerUID;
                }
                // 崩溃报告
                nRet = LibraryChannel.CrashReport(
                    strSender,
                    "dp2circulation",
                    strText,
                    out strError);
            }
            catch (Exception ex)
            {
                strError = "CrashReport() 过程出现异常: " + ExceptionUtil.GetDebugText(ex);
                nRet     = -1;
            }
            finally
            {
                _messageBar.Close();
                _messageBar = null;
            }

            if (nRet == -1)
            {
                strError = "向 dp2003.com 发送异常报告时出错,未能发送成功。详细情况: " + strError;
                MessageBox.Show(_mainForm, strError);
                // 写入错误日志
                MainForm.WriteErrorLog(strError);
#if NO
                if (_mainForm != null)
                {
                    _mainForm.WriteErrorLog(strError);
                }
                else
                {
                    WriteWindowsLog(strError, EventLogEntryType.Error);
                }
#endif
            }
        }
Exemple #4
0
        // parameters:
        //      bLocal  是否从本地启动。 false 表示连安装带启动
        public static void StartDp2libraryXe(
            IWin32Window owner,
            string strDialogTitle,
            Font font,
            bool bLocal)
        {
            MessageBar messageBar = null;

            messageBar         = new MessageBar();
            messageBar.TopMost = false;
            if (font != null)
            {
                messageBar.Font = font;
            }
            messageBar.BackColor     = SystemColors.Info;
            messageBar.ForeColor     = SystemColors.InfoText;
            messageBar.Text          = "dp2 内务";
            messageBar.MessageText   = "正在启动 dp2Library XE V3,请等待 ...";
            messageBar.StartPosition = FormStartPosition.CenterScreen;
            messageBar.Show(owner);
            messageBar.Update();

            Application.DoEvents();
            try
            {
                TimeSpan waitTime = new TimeSpan(0, 1, 0);

                string strShortcutFilePath = "";
                if (bLocal == true)
                {
                    strShortcutFilePath = PathUtil.GetShortcutFilePath("DigitalPlatform/dp2 V3/dp2Library XE V3");
                }
                else
                {
                    strShortcutFilePath = "http://dp2003.com/dp2libraryxe/v3/dp2libraryxe.application";
                    waitTime            = new TimeSpan(0, 5, 0); // 安装需要的等待时间更长
                }

                // TODO: detect if already started
                using (EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset,
                                                                             "dp2libraryXE V3 library host started"))
                {
                    Application.DoEvents();

                    Process.Start(strShortcutFilePath);

                    DateTime start = DateTime.Now;
                    while (true)
                    {
                        Application.DoEvents();
                        // wait till started
                        // http://stackoverflow.com/questions/6816782/windows-net-cross-process-synchronization
                        if (eventWaitHandle.WaitOne(100, false) == true)
                        {
                            break;
                        }

                        // if timeout, prompt continue wait
                        if (DateTime.Now - start > waitTime)
                        {
                            DialogResult result = MessageBox.Show(owner,
                                                                  "dp2libraryXE V3 暂时没有响应。\r\n\r\n是否继续等待其响应?",
                                                                  strDialogTitle,
                                                                  MessageBoxButtons.YesNo,
                                                                  MessageBoxIcon.Question,
                                                                  MessageBoxDefaultButton.Button1);
                            if (result == System.Windows.Forms.DialogResult.No)
                            {
                                break;
                            }

                            start = DateTime.Now;   //
                        }
                    }
                }
            }
            finally
            {
                messageBar.Close();
            }
        }
Exemple #5
0
        /// <summary>
        /// Calls RunCMD with additional parameters taken from the classes @mtasc doc tag
        /// </summary>
        public override bool BuildCMD(bool failSilently)
        {
            // check if @mtasc is defined
            Match mCmd = null;

            if (IsFileValid() && CurrentClass.Comments != null)
            {
                mCmd = re_CMD_BuildCommand.Match(CurrentClass.Comments);
            }

            if (mCmd == null || !mCmd.Success)
            {
                if (!failSilently)
                {
                    MessageBar.ShowWarning("This class is invalid or does not include a @mtasc build command.");
                }
                return(false);
            }

            // build command
            string command = mCmd.Groups["params"].Value.Trim();

            try
            {
                command = " " + MainForm.ProcessArgString(command) + " ";
                if (command == null || command.Length == 0)
                {
                    if (!failSilently)
                    {
                        throw new Exception("Preprocessor returned an empty command.");
                    }
                    return(false);
                }
                builtSWF        = null;
                builtSWFSize    = "";
                trustFileWanted = false;

                // get SWF url
                MatchCollection mPar       = re_SplitParams.Matches(command + "-eof");
                int             mPlayIndex = -1;
                bool            noPlay     = false;
                if (mPar.Count > 0)
                {
                    string op;
                    for (int i = 0; i < mPar.Count; i++)
                    {
                        op = mPar[i].Groups["switch"].Value;
                        if ((op == "-swf") && (builtSWF == null) && (mPlayIndex < 0))
                        {
                            int start = mPar[i].Index + mPar[i].Length;
                            int end   = mPar[i + 1].Index;
                            if (end > start)
                            {
                                builtSWF = command.Substring(start, end - start).Trim();
                            }
                        }
                        else if ((op == "-out") && (mPlayIndex < 0))
                        {
                            int start = mPar[i].Index + mPar[i].Length;
                            int end   = mPar[i + 1].Index;
                            if (end > start)
                            {
                                builtSWF = command.Substring(start, end - start).Trim();
                            }
                        }
                        else if (op == "-header")
                        {
                            int start = mPar[i].Index + mPar[i].Length;
                            int end   = mPar[i + 1].Index;
                            if (end > start)
                            {
                                string[] dims = command.Substring(start, end - start).Trim().Split(':');
                                if (dims.Length > 2)
                                {
                                    builtSWFSize = ";" + dims[0] + ";" + dims[1];
                                }
                            }
                        }
                        else if (op == "-play")
                        {
                            int start = mPar[i].Index + mPar[i].Length;
                            int end   = mPar[i + 1].Index;
                            if (end > start)
                            {
                                mPlayIndex = i;
                                builtSWF   = command.Substring(start, end - start).Trim();
                            }
                        }
                        else if (op == "-trust")
                        {
                            trustFileWanted = true;
                        }
                        else if (op == "-noplay")
                        {
                            noPlay = true;
                        }
                    }
                }
                if (builtSWF.Length == 0)
                {
                    builtSWF = null;
                }

                // cleaning custom switches
                if (mPlayIndex >= 0)
                {
                    command = command.Substring(0, mPar[mPlayIndex].Index) + command.Substring(mPar[mPlayIndex + 1].Index);
                }
                if (trustFileWanted)
                {
                    command = command.Replace("-trust", "");
                }
                if (noPlay)
                {
                    command  = command.Replace("-noplay", "");
                    builtSWF = null;
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.ShowError("Error while preprocessing the build command.", ex);
                return(false);
            }

            // run
            RunCMD(command);
            return(true);
        }
 /// <summary>
 /// Depending on the context UI, display some message
 /// </summary>
 public void DisplayError(string message)
 {
     MessageBar.ShowWarning(message);
 }