Esempio n. 1
0
        static void Main(string[] args)
        {
            // Dienst starten
            ServiceControllerStatus serviceStatus;

            try
            {
                Console.WriteLine("Starte NetDDE ...");
                serviceStatus = ServiceUtil.StartService("NetDDE", null, null, 2000);
                if (serviceStatus != ServiceControllerStatus.Running)
                {
                    Console.WriteLine("Der Dienst konnte nicht innerhalb " +
                                      "des Timeout gestartet werden");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fehler beim Starten: {0}", ex.Message);
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Dienst gestartet ... Return zum Anhalten");
            Console.ReadLine();

            // Dienst anhalten
            try
            {
                ServiceUtil.PauseService("NetDDE", null, 2000);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fehler beim Anhalten: {0}", ex.Message);
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Dienst angehalten ... Return zum Fortfahren");
            Console.ReadLine();

            // Dienst wieder starten
            try
            {
                serviceStatus = ServiceUtil.ContinueService("NetDDE", null, 2000);
                if (serviceStatus != ServiceControllerStatus.Running)
                {
                    Console.WriteLine("Der Dienst konnte nicht innerhalb " +
                                      "des Timeout fortgefahren werden");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fehler beim Fortfahren: {0}", ex.Message);
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Dienst fortgefahren ... Return zum Stoppen");
            Console.ReadLine();

            // Dienst stoppen
            try
            {
                serviceStatus = ServiceUtil.StopService("NetDDE", null, 2000);
                if (serviceStatus != ServiceControllerStatus.Stopped)
                {
                    Console.WriteLine("Der Dienst konnte nicht innerhalb " +
                                      "des Timeout gestoppt werden");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fehler beim Stoppen: {0}", ex.Message);
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Dienst gestoppt");
            Console.ReadLine();
        }
Esempio n. 2
0
 /// <summary>Gets how many pages of data exist for the Students method.<summary>
 public int GetStudentsPageCount()
 {
     return(ServiceUtil.GetPageCount(GetStudentsCount()));
 }
Esempio n. 3
0
 /// <summary>Gets a list of all of the Teachers in the database.</summary>
 /// <returns>An IEnumerable of Teachers.</returns>
 public IEnumerable <SO.Teacher> GetTeachers(int page)
 {
     return(ServiceUtil.GetPage(TeacherLogic.GetAll(), page).Select(o => SO.Teacher.FromDataAccessObject(o)));
 }
Esempio n. 4
0
 /// <summary>Gets a list of all of the Courses in the database.</summary>
 /// <returns>An IEnumerable of Courses.</returns>
 public IEnumerable <SO.Course> GetCourses(int page)
 {
     return(ServiceUtil.GetPage(CourseLogic.GetAll(), page).Select(o => SO.Course.FromDataAccessObject(o)));
 }
Esempio n. 5
0
 /// <summary>Gets how many pages of data exist for the Semesters method.<summary>
 public int GetSemestersPageCount()
 {
     return(ServiceUtil.GetPageCount(GetSemestersCount()));
 }
Esempio n. 6
0
 /// <summary>Gets how many pages of data exist for the Enrollments method.<summary>
 public int GetEnrollmentsPageCount()
 {
     return(ServiceUtil.GetPageCount(GetEnrollmentsCount()));
 }
Esempio n. 7
0
 /// <summary>Gets how many pages of data exist for the Enrollments by CourseID method.<summary>
 public int GetEnrollmentsByCourseIDPageCount(int courseID)
 {
     return(ServiceUtil.GetPageCount(GetEnrollmentsByCourseIDCount(courseID)));
 }
Esempio n. 8
0
        /// <summary>
        /// Determines whether the specified data is in cache registry.
        /// </summary>
        /// <param name="nameSpace">The name space.</param>
        /// <param name="name">The name.</param>
        /// <returns>
        ///     <c>true</c> if it is in the cache registry; otherwise, <c>false</c>.
        /// </returns>
        public bool IsInCacheRegistry(string nameSpace, string name)
        {
            var key = ServiceUtil.GetDictKeyString(nameSpace, name);

            return(_registry.ContainsKey(key));
        }
Esempio n. 9
0
        public string GetRegisteredPath(string nameSpace, string name)
        {
            var key = ServiceUtil.GetDictKeyString(nameSpace, name);

            return(this[key]);
        }
 /// <summary>
 /// 圈选获取责任区详细信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ZrqDetail GetZrqDetailByPoly(string id)
 {
     return(JsonConvert.DeserializeObject <ZrqDetail>(ServiceUtil.GetRemoteXmlStream(ConfigHelper.GetValueByKey("webservice.config", "圈选派出所责任区详细信息") + "?type=zrq&id=" + id, null)));
 }
Esempio n. 11
0
        static void Main(string[] args)
        {
            var context = ServiceUtil.GetContextProvider <ISampleContextProvider>().GetCurrentContext();

            var consoleProvider = ServiceUtil.GetService <IConsoleProvider>(context);

            // test output string provider with string transformers
            var outputStr = Strings.GetTransformedString(context, "MyResourceKey");

            consoleProvider.WriteLine(outputStr);

            outputStr = Strings.GetHtmlEncodedString("<span>aaa</span>");
            consoleProvider.WriteLine(outputStr);

            consoleProvider.WriteLine("================================================");

            // test service provider
            var userTokenProvider = ServiceUtil.GetService <IUserTokenProvider>(context);
            var loginData         = (SampleUserToken)userTokenProvider.GetUserToken(context, new UserTokenRequestWithCredentials("aaa", "bbb"));

            consoleProvider.WriteLine(loginData.UserId.ToString());
            consoleProvider.WriteLine("================================================");

            // test error handling
            try
            {
                throw ServiceUtil.GetService <ISampleTypeSetProvider>(context).GetSampleTypeInstanceByName(context, "First name").GetTestErrorException(context);
            }
            catch (EntityException <SampleType, TestError> exc)
            {
                consoleProvider.WriteLine(Strings.GetHtmlEncodedTransformedString(context, exc.Info.GetDescription(context)), exc.Entity);
                consoleProvider.WriteLine(exc.ContextSnapshot.UTCTime + " " + exc.ContextSnapshot.LocalTimeOffset + " " + exc.ContextSnapshot.UICulture.LCID);
                consoleProvider.WriteLine(context.GetCurrentTimeUTC() + " " + context.GetLocalTimeOffset() + " " + context.GetCurrentUICulture().LCID);
            }
            catch (EntityException <SampleType> exc)
            {
                if (exc.GetInfoEntityType() == typeof(TestError))
                {
                    consoleProvider.WriteLine(exc.GetInfo <TestError>().GetDescription(context), exc.Entity);
                }
                else
                {
                    throw;
                }
            }
            catch (EntityException exc)
            {
                if (exc.GetEntityType() != typeof(SampleType) && exc.GetInfoEntityType() == typeof(TestError))
                {
                    consoleProvider.WriteLine(exc.GetInfo <TestError>().GetDescription(context), exc.GetEntity <SampleType>());
                }
                else
                {
                    consoleProvider.WriteLine(exc.GetInfo().GetObjectDescription(context), exc.GetEntity().GetObjectDescription(context));
                    throw;
                }
            }

            consoleProvider.WriteLine("================================================");

            // test configuration provider
            var authCookieProperties = ServiceUtil.GetService <IAuthCookiePropertiesProvider>(context).GetAuthCookieProperties();

            consoleProvider.WriteLine("Auth cookie name: {0}", authCookieProperties != null ? authCookieProperties.Name : "!!!DEFAULT!!!");
            consoleProvider.WriteLine("================================================");

            // test structured entity providers
            var sampleTypes = ServiceUtil.GetService <ISampleTypeStructuredDataProvider>(context).ListSampleTypes(context);

            foreach (var sampleType in sampleTypes)
            {
                consoleProvider.WriteLine(sampleType.GetObjectDescription(context));
            }

            consoleProvider.WriteLine("================================================");

            var treeDisplayer = new TreeDisplayer(consoleProvider);

            var anotherTypesTree = ServiceUtil.GetService <IAnotherTypeStructuredDataProvider>(context).GetAnotherTypeStructuredData(context);

            anotherTypesTree.GetSidebarLikeTreeWithSeparators().TraverseDepth(treeDisplayer.DisplayTree);
            consoleProvider.WriteLine("================================================");

            var yetAnotherTypesTree = ServiceUtil.GetService <IYetAnotherTypeStructuredDataProvider>(context).GetYetAnotherTypeStructuredData(context);

            yetAnotherTypesTree.GetSidebarLikeTreeWithSeparators().TraverseDepth(treeDisplayer.DisplayTree);
            consoleProvider.WriteLine("================================================");

            var controller = new SampleController(
                ServiceUtil.GetService <ISampleContextProvider>(context),
                ServiceUtil.GetService <ICurrentUserTokenProvider>(context),
                ServiceUtil.GetService <ISampleUserTokenFactory>(context),
                ServiceUtil.GetService <IConsoleProvider>(context));

            controller.OperationWithEnvironmentContext();
            controller.OperationWithUserContext();
            controller.OperationWithUserContext(100);
            controller.OperationWithMeetingContext(100, 2, "NEW MEETING NAME");
            consoleProvider.WriteLine("================================================");

            consoleProvider.ReadKey();
        }
        /// <summary>
        /// 临时版 获取警车列表
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public List <PoliceCar> GetPoliceCarListByPoly(List <Point> polygon)
        {
            List <GridInfo> xzqhList = new List <GridInfo>();

            //从文本文件读取市局、县区列表
            String       policeCarPath = ConfigHelper.GetAssemblyPath() + "PoliceCar.txt";
            StreamReader reader        = new  StreamReader(policeCarPath);

            try
            {
                do
                {
                    string   line     = reader.ReadLine();
                    string[] lineList = line.Split(null);
                    GridInfo gridInfo = new GridInfo {
                        ZZJGDM = lineList[0], JD = lineList[1], WD = lineList[2]
                    };                                                                                            //todo
                    xzqhList.Add(gridInfo);
                }while (reader.Peek() != -1);
            }
            catch (System.IO.FileNotFoundException)
            {
                throw new FileNotFoundException("未发现警车点文件");
            }
            finally
            {
                reader.Close();
            }

            List <GridInfo> filterXzqhList = new List <GridInfo>();

            foreach (GridInfo js in xzqhList)
            {
                if (js.JD != null && js.WD != null)
                {
                    double jd, wd;
                    double.TryParse(js.JD, out jd);
                    double.TryParse(js.WD, out wd);
                    bool re = PtInPolygon(jd, wd, polygon);
                    if (re == true)
                    {
                        filterXzqhList.Add(js);
                    }
                }
            }

            List <PoliceCar> plcList   = JsonConvert.DeserializeObject <List <PoliceCar> >((ServiceUtil.GetRemoteXmlStream(ConfigHelper.GetValueByKey("webservice.config", "圈选警车统计"), null)));
            List <PoliceCar> plcListRe = new List <PoliceCar>();
            string           quxian    = null;

            foreach (GridInfo pcs in filterXzqhList)
            {
                string pcsid = pcs.ZZJGDM.Substring(0, 6);
                if (pcsid.Equals(quxian))
                {
                    continue;
                }
                else
                {
                    quxian = pcsid;
                }
                foreach (PoliceCar plc in plcList)
                {
                    string plcid = plc.ORGID.Substring(0, 6);
                    if (pcsid.Equals(plcid))
                    {
                        plcListRe.Add(plc);
                    }
                }
            }
            return(plcListRe);
        }
 public List <PoliceMan> GetPoliceManListByPoly(string polygon)
 {
     return(JsonConvert.DeserializeObject <List <PoliceMan> >(JObject.Parse(ServiceUtil.GetRemoteXmlStream(ConfigHelper.GetValueByKey("webservice.config", "圈选警员统计") + "?geom=" + polygon, null))["jyList"].ToString()));
 }
 /// <summary>
 /// 圈选获取场所列表
 /// </summary>
 /// <param name="csType">场所类型</param>
 /// <param name="polygon">圈选范围</param>
 /// <returns></returns>
 public List <PolyCS> GetCSListByPoly(string csType, string polygon)
 {
     return(JsonConvert.DeserializeObject <List <PolyCS> >(JObject.Parse(ServiceUtil.GetRemoteXmlStream((ConfigHelper.GetValueByKey("webservice.config", "圈选场所统计") + "?geom=" + polygon) + "&type=" + ConfigHelper.GetValueByKey("webservice.config", csType), null))["list"].ToString()));
 }
Esempio n. 15
0
 public T GetService <T>()
 {
     return(ServiceUtil.GetService <T>(this.Name));
 }
    public void ProcessServiceRequest(ServiceAction action, Service service, int timeout)
    {
        string[] loadOrderGroupDependencies = service.LoadOrderGroupDependencies?.ToArray<String>();
        string[] serviceDependencies = service.ServiceDependencies?.ToArray<String>();

        ServiceConfig status = null;
        ServiceReturnCode rc = ServiceReturnCode.NotSupported;
        bool success = _isDryRun;

        switch( action )
        {
            case ServiceAction.Create:
            {
                    if (!_isDryRun)
                    {
                        rc = ServiceUtil.CreateService(service.Name, service.Server, service.DisplayName, service.Description, service.BinPath,
                                                        service.StartMode, service.StartName, service.StartPassword,
                                                        service.Type, service.OnError, service.InteractWithDesktop, service.LoadOrderGroup,
                                                        loadOrderGroupDependencies, serviceDependencies);
                        if (_config.StartOnCreate == true)
                            success = ServiceUtil.Start(service.Name, service.Server, timeout, service.StartMode);
                        status = ServiceUtil.QueryService(service.Name, service.Server);
                    }
                    else
                    {
                        // DryRun : Return mocked up ServiceConfig with values that WOULD have been created.
                        ServiceConfig sc = new ServiceConfig();
                        sc.Name = service.Name;
                        sc.ServerName = service.Server;
                        sc.DisplayName = service.DisplayName;
                        sc.Description = service.Description;
                        sc.PathName = service.BinPath;
                        sc.StartMode = service.StartMode;
                        sc.StartName = service.StartName;
                        sc.ServiceType = service.Type.ToString();
                        sc.ErrorControl = service.OnError.ToString();
                        sc.DesktopInteract = service.InteractWithDesktop;
                        status = sc;
                    }

                    break;
            }
            case ServiceAction.Delete:
            {
                if (!_isDryRun)
                {
                    rc = ServiceUtil.DeleteService(service.Name, service.Server);
                }
                else
                {
                    status = ServiceUtil.QueryService(service.Name, service.Server);
                }
                break;
            }
            case ServiceAction.Query:
            {
                status = ServiceUtil.QueryService( service.Name, service.Server );
                break;
            }
            case ServiceAction.Start:
            {
                if( !_isDryRun )
                    success = ServiceUtil.Start( service.Name, service.Server, timeout, service.StartMode, service.StartParameters?.ToArray<String>() );
                status = ServiceUtil.QueryService( service.Name, service.Server );
                break;
            }
            case ServiceAction.Stop:
            {
                if( !_isDryRun )
                    success = ServiceUtil.Stop( service.Name, service.Server, timeout, service.StartMode );
                status = ServiceUtil.QueryService( service.Name, service.Server );
                break;
            }
            case ServiceAction.Restart:
            {
                if( !_isDryRun )
                {
                    success = ServiceUtil.Stop( service.Name, service.Server, timeout, ServiceStartMode.Unchanged );
                    Thread.Sleep( 5000 );
                    success = ServiceUtil.Start( service.Name, service.Server, timeout, service.StartMode );
                }
                status = ServiceUtil.QueryService( service.Name, service.Server );
            }
            break;
            case ServiceAction.StartMode:
            {
                if( !_isDryRun )
                    rc = ServiceUtil.ChangeStartMode( service.Name, service.Server, service.StartMode );
                status = ServiceUtil.QueryService( service.Name, service.Server );
                break;
            }
        }

        if( status != null )
        {
            OnLogMessage( action.ToString(), "Name : [" + status.ServiceName + "] Status : [" + status.State + "]" );
            _results.Add( status );
        }
    }
Esempio n. 17
0
 public object GetService(Type serviceType)
 {
     return(ServiceUtil.GetService(this.Name, serviceType));
 }
Esempio n. 18
0
        static void Main(string[] args)
        {
            System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

            ServiceShortName = "dp2RouterService";

            // 修改配置
            if (args.Length == 1 && args[0].Equals("setting"))
            {
                InitialConfig();

                Console.WriteLine("(直接回车表示不修改当前值)");

                Console.WriteLine("请输入数据目录: (当前值为 " + DataDir + ")");
                string strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    DataDir = strValue;
                }

                SaveConfig();
                InitialConfig();

                // 设置需要保存到数据目录 config.xml 中的其他参数
                ServerInfo.Initial(DataDir, true);

                Console.WriteLine("请输入服务器端口号: (当前值为 " + ServerInfo.ServerPort + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    ServerInfo.ServerPort = strValue;
                }

                Console.WriteLine("请输入 dp2MServer URL: (当前值为 " + ServerInfo.Url + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    ServerInfo.Url = strValue;
                }

                Console.WriteLine("请输入 dp2MServer 用户名: (当前值为 " + ServerInfo.UserName + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    ServerInfo.UserName = strValue;
                }

                Console.WriteLine("请输入 dp2MServer 密码:");
                Console.BackgroundColor = Console.ForegroundColor;
                strValue = Console.ReadLine();
                Console.ResetColor();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    ServerInfo.Password = strValue;
                }

                ServerInfo.SaveCfg(DataDir);

                ServerInfo.Exit();

                Console.WriteLine();
                Console.WriteLine("注:修改将在服务重启以后生效");
                Console.WriteLine("(按回车键返回)");
                Console.ReadLine();
                return;
            }

            if (args.Length == 1 &&
                (args[0].Equals("install") || args[0].Equals("uninstall"))
                )
            {
                bool bInstall = true;

                if (args[0].Equals("uninstall"))
                {
                    bInstall = false;
                }

                // 注册为 Windows Service
                // string strExePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
                string strExePath = Assembly.GetExecutingAssembly().Location;
                Console.WriteLine((bInstall ? "注册" : "注销") + " Windows Service ...");

                string strError = "";
                int    nRet     = ServiceUtil.InstallService(strExePath,
                                                             bInstall,
                                                             out strError);
                if (nRet == -1)
                {
                    Console.WriteLine("error: " + strError);
                }

                Console.WriteLine();
                Console.WriteLine("(按回车键返回)");
                Console.ReadLine();
                return;
            }

            if (args.Length == 1 && args[0].Equals("console"))
            {
                if (Initial() == false)
                {
                    return;
                }
                new Program().ConsoleRun();
            }
            else
            {
                // 这是从命令行启动的情况
                if (Environment.UserInteractive == true)
                {
                    Console.WriteLine("dp2Router 用法:");
                    Console.WriteLine("注册 Windows Service: dp2router install");
                    Console.WriteLine("注销 Windows Service: dp2router uninstall");
                    Console.WriteLine("以控制台方式运行: dp2router console");
                    Console.WriteLine("修改配置参数: dp2router setting");

                    Console.WriteLine("(按回车键返回)");
                    Console.ReadLine();
                    return;
                }

                if (Initial() == false)
                {
                    return;
                }

                // 这是被当作 service 启动的情况
                ServiceBase.Run(new Program());
            }
        }
Esempio n. 19
0
 /// <summary>Gets how many pages of data exist for the Enrollments by StudentID method.<summary>
 public int GetEnrollmentsByStudentIDPageCount(int studentID)
 {
     return(ServiceUtil.GetPageCount(GetEnrollmentsByStudentIDCount(studentID)));
 }
Esempio n. 20
0
        static void Main(string[] args)
        {
            ServiceShortName = "dp2MessageService";
#if NO
            // Task.Run(() => StartServer());
            StartServer();

            Console.WriteLine("Server running on {0}", ServerURI);

            Console.WriteLine("press 'x' to exit");
            // Keep going until somebody hits 'x'
            while (true)
            {
                ConsoleKeyInfo ki = Console.ReadKey(true);
                if (ki.Key == ConsoleKey.X)
                {
                    Console.WriteLine("exiting ...");
                    ServerInfo.Exit();
                    break;
                }
            }

            if (SignalR != null)
            {
                SignalR.Dispose();
                SignalR = null;
            }
#endif
            PrintLogo();

            // 修改配置
            if (args.Length == 1 && args[0].Equals("setting"))
            {
                InitialConfig();
                // config.AppSettings.Settings.Add(newKey, newValue);

                Console.WriteLine("(直接回车表示不修改当前值)");
                Console.WriteLine("请输入服务器 URI: (当前值为 " + ServerURI + ")");
                string strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    ServerURI = strValue;
                }

                Console.WriteLine("请输入服务器路径: (当前值为 " + ServerPath + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    ServerPath = strValue;
                }

                Console.WriteLine("请输入数据目录: (当前值为 " + DataDir + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    DataDir = strValue;
                }

                Console.WriteLine("请输入自动触发 URL: (当前值为 " + AutoTriggerUrl + ") [输入 空 表示希望设置为空]");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    if (strValue == "空" || strValue == "[null]")
                    {
                        AutoTriggerUrl = "";
                    }
                    else
                    {
                        AutoTriggerUrl = strValue;
                    }
                }

                string strCfgFileName = Path.Combine(DataDir, "config.xml");

                SaveConfig();

                // 创建数据目录中的 config.xml 配置文件
                if (File.Exists(strCfgFileName) == false)
                {
                    PathUtil.CreateDirIfNeed(Path.GetDirectoryName(strCfgFileName));
                    ServerInfo.CreateCfgFile(strCfgFileName);
                    Console.WriteLine("首次创建配置文件 " + strCfgFileName);
                }
#if NO
                Console.WriteLine("(直接回车表示不修改当前值)");
                Console.WriteLine("请输入服务器 URI: (当前值为 " + Settings.Default.ServerURI + ")");
                string strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    Settings.Default.ServerURI = strValue;
                }

                Console.WriteLine("请输入服务器路径: (当前值为 " + Settings.Default.ServerPath + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    Settings.Default.ServerPath = strValue;
                }

                Console.WriteLine("请输入数据目录: (当前值为 " + Settings.Default.DataDir + ")");
                strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    Settings.Default.DataDir = strValue;
                }

                Settings.Default.Save();
#endif

                Console.WriteLine();
                Console.WriteLine("注:修改将在服务重启以后生效");
                Console.WriteLine("(按回车键返回)");
                // Console.ReadLine();
                ReadLineExit();
                return;
            }

            // 创建超级用户账户
            if (args.Length == 1 && args[0].Equals("createuser"))
            {
                if (Initial(false) == false)
                {
                    return;
                }

                ServerInfo.InitialMongoDb(true);

                string strUserName = "******";
                string strPassword = "";

                Console.WriteLine("(直接回车表示不修改当前值)");
                Console.WriteLine("请输入超级用户名: (当前值为 " + strUserName + ")");
                string strValue = Console.ReadLine();
                if (string.IsNullOrEmpty(strValue) == false)
                {
                    strUserName = strValue;
                }

                Console.WriteLine("请输入超级用户密码: ");
                strValue    = Console.ReadLine();
                strPassword = strValue;

                CreateSupervisor(strUserName, strPassword);

                Console.WriteLine();
                Console.WriteLine("注:修改已经立即生效");
                Console.WriteLine("(按回车键返回)");
                //Console.ReadLine();
                //ServerInfo.Exit();  // Initial() 执行后,需要 Exit() 才能退出
                ReadLineExit();
                return;
            }

            if (args.Length == 1 &&
                (args[0].Equals("install") || args[0].Equals("uninstall"))
                )
            {
                bool bInstall = true;

                if (args[0].Equals("uninstall"))
                {
                    bInstall = false;
                }

                // 注册为 Windows Service
                // string strExePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
                string strExePath = Assembly.GetExecutingAssembly().Location;
                Console.WriteLine((bInstall ? "注册" : "注销") + " Windows Service ...");

                string strError = "";
                int    nRet     = ServiceUtil.InstallService(strExePath,
                                                             bInstall,
                                                             out strError);
                if (nRet == -1)
                {
                    Console.WriteLine("error: " + strError);
                }

                if (bInstall == true)
                {
                    // 创建事件日志目录
                    if (!EventLog.SourceExists("dp2mserver"))
                    {
                        EventLog.CreateEventSource("dp2mserver", "DigitalPlatform");
                    }
                }

                Console.WriteLine();
                Console.WriteLine("(按回车键返回)");
                // Console.ReadLine();
                ReadLineExit();
                return;
            }

            if (args.Length == 1 && args[0].Equals("console"))
            {
                if (Initial() == false)
                {
                    return;
                }
                ServerInfo.ConsoleMode = true;
                new Program().ConsoleRun();
            }
            else
            {
                // 这是从命令行启动的情况
                if (Environment.UserInteractive == true)
                {
                    Console.WriteLine("dp2MServer 用法:");
                    Console.WriteLine("注册 Windows Service: dp2mserver install");
                    Console.WriteLine("注销 Windows Service: dp2mserver uninstall");
                    Console.WriteLine("以控制台方式运行: dp2mserver console");
                    Console.WriteLine("修改配置参数: dp2mserver setting");
                    Console.WriteLine("创建超级用户: dp2mserver createuser");

                    Console.WriteLine("(按回车键返回)");
                    // Console.ReadLine();
                    ReadLineExit();
                    return;
                }

                if (Initial() == false)
                {
                    return;
                }

                // 这是被当作 service 启动的情况
                ServiceBase.Run(new Program());
            }
        }
Esempio n. 21
0
 /// <summary>Gets a list of all of the Majors in the database.</summary>
 /// <returns>An IEnumerable of Majors.</returns>
 public IEnumerable <SO.Major> GetMajors(int page)
 {
     return(ServiceUtil.GetPage(MajorLogic.GetAll(), page).Select(o => SO.Major.FromDataAccessObject(o)));
 }
Esempio n. 22
0
 /// <summary>
 /// When implemented in a derived class, executes when a Stop command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service stops running.
 /// </summary>
 protected override void OnStop()
 {
     Trace.TraceInformation("Service Stopped");
     ServiceUtil.Stop();
 }
Esempio n. 23
0
 /// <summary>Gets how many pages of data exist for the Majors method.<summary>
 public int GetMajorsPageCount()
 {
     return(ServiceUtil.GetPageCount(GetMajorsCount()));
 }
Esempio n. 24
0
        static void Main(string[] args)
        {
            // System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

            ServiceShortName = "dp2CapoService";

            PrintLogo();

            // 修改配置
            if (args.Length >= 1 && args[0].Equals("setting"))
            {
                ChangeSettings(args.Length > 1 ? args[1] : "");
                return;
            }

            // 注册或注销 Windows Service
            if (args.Length == 1 &&
                (args[0].Equals("install") || args[0].Equals("uninstall"))
                )
            {
                bool bInstall = true;

                if (args[0].Equals("uninstall"))
                {
                    bInstall = false;
                }

                // 注册为 Windows Service
                string strExePath = Assembly.GetExecutingAssembly().Location;
                Console.WriteLine((bInstall ? "注册" : "注销") + " Windows Service ...");

                try
                {
                    Console.WriteLine("停止服务 ...");
                    ServiceUtil.StopService("dp2CapoService", TimeSpan.FromMinutes(2));
                    Console.WriteLine("服务已停止。");
                }
                catch//(Exception ex)
                {
                    // Console.WriteLine("停止服务时发生异常: " + ExceptionUtil.GetExceptionText(ex));
                }
#if NO
                if (bInstall == true)
                {
                    // 创建事件日志目录
                    // 注: 创建事件日志目录应该在 InstallService 以前。因为 InstallService 过程中涉及到启动服务,可能要写入日志
                    if (!EventLog.SourceExists(ServiceShortName))   // "dp2Capo"
                    {
                        EventLog.CreateEventSource(ServiceShortName, "DigitalPlatform");
                    }
                }
#endif

                int nRet = ServiceUtil.InstallService(strExePath,
                                                      bInstall,
                                                      out string strError);
                if (nRet == -1)
                {
                    Console.WriteLine("error: " + strError);
                }

                Console.WriteLine();
                Console.WriteLine("(按回车键返回)");
                Console.ReadLine();
                return;
            }

            // 以控制台方式运行
            if (args.Length == 1 && args[0].Equals("console"))
            {
                if (Initial() == false)
                {
                    return;
                }
                new Program().ConsoleRun();
                return;
            }
            else
            {
                // 这是从命令行启动的情况
                if (Environment.UserInteractive == true)
                {
                    Console.WriteLine("dp2capo 用法:");
                    Console.WriteLine("注册 Windows Service: dp2capo install");
                    Console.WriteLine("注销 Windows Service: dp2capo uninstall");
                    Console.WriteLine("以控制台方式运行: dp2capo console");
                    Console.WriteLine("修改配置参数: dp2capo setting");
                    Console.WriteLine("修改实例配置参数: dp2capo setting 1");

                    Console.WriteLine("(按回车键返回)");
                    Console.ReadLine();
                    return;
                }

                if (Initial() == false)
                {
                    return;
                }

                // 这是被当作 service 启动的情况
                ServiceBase.Run(new Program());
            }
        }
Esempio n. 25
0
 /// <summary>Gets a list of all of the Students in the database.</summary>
 /// <returns>An IEnumerable of Students.</returns>
 public IEnumerable <SO.Student> GetStudents(int page)
 {
     return(ServiceUtil.GetPage(StudentLogic.GetAll(), page).Select(o => SO.Student.FromDataAccessObject(o)));
 }
Esempio n. 26
0
 public void AddService <TService, TImplementation>() where TImplementation : TService
 {
     ServiceUtil.AddService <TService, TImplementation>(this.Name);
 }
Esempio n. 27
0
 /// <summary>Gets how many pages of data exist for the Students by MajorID method.<summary>
 public int GetStudentsByMajorIDPageCount(int majorID)
 {
     return(ServiceUtil.GetPageCount(GetStudentsByMajorIDCount(majorID)));
 }
Esempio n. 28
0
 public void AddService(Type serviceType, Type implementationType)
 {
     ServiceUtil.AddService(this.Name, serviceType, implementationType);
 }
Esempio n. 29
0
 /// <summary>Gets how many pages of data exist for the Courses method.<summary>
 public int GetCoursesPageCount()
 {
     return(ServiceUtil.GetPageCount(GetCoursesCount()));
 }
Esempio n. 30
0
 /// <summary>Gets how many pages of data exist for the Courses by TeacherID method.<summary>
 public int GetCoursesByTeacherIDPageCount(int teacherID)
 {
     return(ServiceUtil.GetPageCount(GetCoursesByTeacherIDCount(teacherID)));
 }