Beispiel #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            Logger.Initialize(PathUtil.GetLog4netPath());
            Logger.LogError("开始");
            string strAppType = CommonHelp.GetConfig("apptype", "0");

            if (strAppType == "0")
            {
                try
                {
                    var hostConfiguration = new HostConfiguration
                    {
                        UrlReservations = new UrlReservations()
                        {
                            CreateAutomatically = true
                        }
                    };
                    string strIP = appsetingB.GetValueByKey("ip");
                    string port  = appsetingB.GetValueByKey("port");

                    string url       = string.Format("http://{0}:{1}", strIP, port);
                    var    rootPath  = appsetingB.GetValueByKey("path");
                    var    nancyHost = new NancyHost(new RestBootstrapper(), hostConfiguration, new Uri(url));
                    nancyHost.Start();
                    System.Console.WriteLine("文件中心服务开启,管理地址:" + url.ToString());

                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Logger.LogError("启动NancyHost失败.");
                    Logger.LogError4Exception(ex);
                }
            }
            else
            {
                if (!Environment.UserInteractive)
                {
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
                    {
                        new QJ_FileCenterService()
                    };
                    ServiceBase.Run(ServicesToRun);
                }
                else
                {
                    QJ_FileCenterService service = new QJ_FileCenterService();
                    System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);  // forces debug to keep VS running while we debug the service
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取页面html(excel)
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <param name="UserInfo"></param>
        public void GETHTML(JObject context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            string strWDYM = CommonHelp.GetConfig("WDYM");

            FT_File ff = new FT_FileB().GetEntities(p => p.YLCode == P1).FirstOrDefault();

            if (ff != null)
            {
                //定义局部变量
                HttpWebRequest  httpWebRequest  = null;
                HttpWebResponse httpWebRespones = null;
                Stream          stream          = null;
                string          htmlString      = string.Empty;
                string          url             = strWDYM + ff.YLPath;

                //请求页面
                try
                {
                    httpWebRequest = WebRequest.Create(url + ".html") as HttpWebRequest;
                }
                //处理异常
                catch
                {
                    msg.ErrorMsg = "建立页面请求时发生错误!";
                }
                httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Maxthon 2.0)";
                //获取服务器的返回信息
                try
                {
                    httpWebRespones = (HttpWebResponse)httpWebRequest.GetResponse();
                    stream          = httpWebRespones.GetResponseStream();
                }
                //处理异常
                catch
                {
                    msg.ErrorMsg = "接受服务器返回页面时发生错误!";
                }

                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.UTF8);
                //读取返回页面
                try
                {
                    htmlString = streamReader.ReadToEnd();
                }
                //处理异常
                catch
                {
                    msg.ErrorMsg = "读取页面数据时发生错误!";
                }
                //释放资源返回结果
                streamReader.Close();
                stream.Close();

                msg.Result  = htmlString;
                msg.Result1 = url;
            }
            else
            {
                msg.ErrorMsg = "此文件不存在或您没有权限!";
            }
        }