private void StartHTTPCompanionService(string URL)
        {
            //URL = Zeus.Lib.Extensions.ExtensionHelpers.GetAddress(URL);
            WebServiceHTTP.WebServiceBaseAddress = URL;

            string WebServiceHTTPBaseAddress = URL + "Admin/";

            try
            {
                Uri uri = new Uri(WebServiceHTTPBaseAddress);
                oWebServiceHost = new WebServiceHost(oServiceHTTPType, uri);

                var endpoint = CreateEndpoint(oServiceHTTPInterfaceType, WebServiceHTTPBaseAddress);
                oWebServiceHost.AddServiceEndpoint(endpoint);

                //oWebServiceHost.Authorization.ServiceAuthorizationManager = new RestAuthorizationManager();
                oWebServiceHost.Open();
            }
            catch (Exception ex)
            {
                ServiceLogger.Error("Companion service cannot be started, reason: " + ex.Message);
                return;
            }

            ServiceLogger.Info("SERVICE HTML ADMIN STARTED");
            ServiceLogger.Info("Listening on: " + WebServiceHTTPBaseAddress);
        }
Example #2
0
        public override void Validate(string userName, string password)
        {
            _logger.Info(string.Format("User '{0}' is trying to access to service", userName));
            var connString = ConfigurationManager.ConnectionStrings["deployer"].ConnectionString;

            using (var context = new DbDataContext(connString))
                if (!context.Users.Any(u => u.Login.Equals(userName) && u.Password.Equals(password)))
                {
                    _logger.Info(string.Format("Access for user '{0}' is denied", userName));
                    throw new SecurityTokenValidationException("User validation is failed.");
                }
                else
                {
                    _logger.Info(string.Format("Access for user '{0}' is granted", userName));
                }
        }
Example #3
0
        /// <summary>
        /// 上下文初始化
        /// </summary>
        /// <returns></returns>
        public DependencyResult Init()
        {
            ServiceLogger.Info("---------------------服务的依赖项检测--开始---------------------");
            DependencyResult result = new DependencyResult()
            {
                UnitName = GetUnitName()
            };

            //配置文件依赖检测
            result.DependencyDetails.Add(CheckAvailabilityOfConfigForService(ProtocolConfig));
            result.DependencyDetails.Add(CheckAvailabilityOfConfigForService(DatabaseConfig));
            //数据库依赖检测
            foreach (var dbConfigItem in DatabaseConfig.DbConfigItems)
            {
                result.DependencyDetails.Add(CheckAvailabilityOfDbSessionForService(dbConfigItem));
            }
            //其他依赖项检测
            foreach (var dependencyResult in InitOthers())
            {
                result.DependencyResults.Add(dependencyResult);
            }
            //更新并记录自身错误
            result.UpdateInfoFromDependencies();
            ServiceLogger.Info(result.Message);
            ServiceLogger.Info("---------------------服务的依赖项检测--结束---------------------");
            return(result);
        }
Example #4
0
        /// <summary>
        /// Запускает импорт
        /// </summary>
        /// <returns></returns>
        public int Start(string path)
        {
            using (var reader = new StreamReader(path, Encoding.UTF8, true))
            {
                var serializer = new XmlSerializer(typeof(FLInfoList));
                try
                {
                    var arrayOfInfo = (FLInfoList)serializer.Deserialize(reader);

                    List <SS_FlInfo> list = new List <SS_FlInfo>();
                    ServiceLogger.Info("{info}", "начало мапинга");
                    foreach (var item in arrayOfInfo.FLInfos)
                    {
                        list.Add(CustomMapper(item));
                    }
                    ServiceLogger.Info("{info}", "конец мапинга");
                    using (var db = new dbModel(connection))
                    {
                        db.CommandTimeout = 1200000;
                        using (var tr = db.BeginTransaction())
                        {
                            try
                            {
                                ServiceLogger.Info("{info}", "таблица SS_FlInfo_Dupl перезапись начало");
                                db.AbonentInfoDelete();
                                ServiceLogger.Info("{info}", "таблица SS_FlInfo_Dupl перезапись конец");
                                ServiceLogger.Info("{info}", "таблица SS_FlInfo очищена");

                                ServiceLogger.Info("{info}", "таблица SS_FlInfo запись начало");
                                InsertBulk(list, db);
                                ServiceLogger.Info("{info}", "таблица SS_FlInfo запись окончание");

                                ServiceLogger.Info("{info}", "таблица SS_FlInfo обновление начало");
                                db.AbonentInfoUpdate();
                                ServiceLogger.Info("{info}", "таблица SS_FlInfo обновление конец");

                                tr.Commit();
                                ServiceLogger.Info("{info}", "импорт завершён");

                                return(list.Count);
                            }
                            catch (Exception e)
                            {
                                ServiceLogger.Error("{error}", e.ToString());
                                return(0);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ServiceLogger.Error("{error}", e.ToString());
                    //string sd = @"�";
                    return(0);
                }
            }
        }
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            var logger = new ServiceLogger();

            foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
            {
                logger.Info(string.Format("Dispatcher at {0} is shielded by error handler.", dispatcher.BindingName));
                dispatcher.ErrorHandlers.Add(new ServiceExceptionsHandler(dispatcher.BindingName, logger));
            }
        }
Example #6
0
 /// <summary>
 /// На старт
 /// </summary>
 /// <param name="args"></param>
 protected override void OnStart(string[] args)
 {
     try
     {
         serviceWorker = new Thread(DoBackups);
         serviceWorker.Start();
     }
     catch (Exception e)
     {
         ServiceLogger.Info("{error}", "произошла ошибка");
         ServiceLogger.Error("{error}", e.ToString());
     }
 }
 protected override void OnStop()
 {
     if (oServiceHost != null)
     {
         oServiceHost.Close();
         oServiceHost = null;
     }
     if (oWebServiceHost != null)
     {
         oWebServiceHost.Close();
         oWebServiceHost = null;
     }
     ServiceLogger.Info("SERVICE STOPPED");
 }
        public void Start()
        {
            var hostConfig = new HostConfiguration
            {
                UrlReservations = new UrlReservations {
                    CreateAutomatically = true
                }
            };

            _host = new NancyHost(hostConfig, new Uri(Helper.HostPath));
            _host.Start();

            ServiceLogger.Info($"Service started and listening on: {Helper.HostPath}");
        }
Example #9
0
        /// <summary>
        /// Создание backup-ов
        /// </summary>
        private void DoBackups()
        {
            ServiceLogger.Info("{thread}", "поехали");
            while (enableService)
            {
                DateTime now = DateTime.Now;

                if (!CheckFirstSaturdayOfMonth(now))
                {
                    DateTime deltaTime = new DateTime(now.AddDays(1).Year,
                                                      now.AddDays(1).Month, now.AddDays(1).Day, 0, 0, 0);
                    Thread.Sleep(deltaTime.Subtract(now));
                    continue;
                }

                int executeWait = MilisecondsToWait(_params.StartTime);
                int hoursWait   = executeWait / 1000 / 60 / 60;
                int minutesWait = (executeWait - (hoursWait * 60 * 60 * 1000)) / 1000 / 60;
                int secWait     = (executeWait - (hoursWait * 60 * 60 * 1000) - (minutesWait * 60 * 1000)) / 1000;
                ServiceLogger.Info("{thread}", $"дата запуска: первая суббота месяца");
                ServiceLogger.Info("{thread}", $"время запуска: {_params.StartTime}");
                ServiceLogger.Info("{thread}", $"импорт будет выполнен через: " +
                                   $"{hoursWait} час. {minutesWait} мин. {secWait} сек.");

                Thread.Sleep(executeWait);

                try
                {
                    Launcher.Start(_params);
                }
                catch (Exception e)
                {
                    ServiceLogger.Error("{error}", e.ToString());
                }
                // спать день
                Thread.Sleep(86400000);
            }
        }
        protected override void OnStart(string[] args)
        {
            try
            {
                //if (!SecureWebConfig.Secured)
                //{
                //    SecureWebConfig.Secure();
                //}
            }
            catch (Exception ex)
            {
                ServiceLogger.Error("Configuration cannot be read, reason: " + ex.Message);
            }


            ServiceTasks.LoadConfig();

            // collect and pass back the list of known types
            WebServiceKnownTypesProvider.KnownTypes.Add(typeof(WebServiceStatus));

            oServiceHost = new ServiceHost(oServiceType);

            try
            {
                if (oServiceHost.BaseAddresses.Count == 0)
                {
                    string ba = DefaultHTTPUrl; //ExtensionHelpers.GetConfigString("WebServiceBaseURL");
                    if (string.IsNullOrEmpty(ba))
                    {
                        if (UseHTTPS)
                        {
                            ba = DefaultHTTPSUrl;
                        }
                        else
                        {
                            ba = DefaultHTTPUrl;
                        }
                    }
                    else
                    {
                        if (ba.Contains("http://"))
                        {
                            UseHTTPS = false;
                        }
                    }

                    var baseAddresses = new Uri[] { new Uri(ba) };
                    oServiceHost = new ServiceHost(oServiceType, baseAddresses);

                    var endpoint = CreateEndpoint(oServiceInterfaceType, ba);
                    oServiceHost.AddServiceEndpoint(endpoint);

                    ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
                    //metadataBehavior.HttpGetEnabled = true;
                    oServiceHost.Description.Behaviors.Add(metadataBehavior);
                }

                oServiceHost.Authorization.ServiceAuthorizationManager = new RestAuthorizationManager();
                oServiceHost.Open();
            }
            catch (Exception ex)
            {
                ServiceLogger.Error("Service cannot be started, reason: " + ex.Message);
                return;
            }

            //Tasks.StartTimer();
            StartHTTPCompanionService(oServiceHost.BaseAddresses[0].ToString());

            ServiceLogger.Info("SERVICE STARTED");
            foreach (var uri in oServiceHost.BaseAddresses)
            {
                ServiceLogger.Info("Listening on: " + uri);
            }
        }
 /// <summary>
 /// Stops the service
 /// </summary>
 public void Stop()
 {
     _host?.Stop();
     ServiceLogger.Info("Service stopped.");
 }