public dynamic GetMaritalStatus() { Response <List <MaritalStatus> > maritalStatusesR = new Response <List <MaritalStatus> > { IsSuccess = false }; Response <object> apiResponse = ApiService.Get <Response <List <MaritalStatus> > >(ManagmentHelper.GetBaseUrl(), ManagmentHelper.GetBaseAPI(), ManagmentHelper.GetKey("Proxy.MaritalStatus.Get"), string.Empty); string randomNumber = Utility.GetNewNumber(); string message = string.Empty; if (apiResponse.IsSuccess) { maritalStatusesR = (Response <List <MaritalStatus> >)apiResponse.Result; if (!maritalStatusesR.IsSuccess) { message = $"ShowError('{string.Format(ManagmentHelper.GetKey("MaritalStatus.Get.Message.Error"))}');"; maritalStatusesR.Message = new List <MessageResult> { new MessageResult { Message = message } }; } } else { message = $"ShowError('{string.Format(ManagmentHelper.GetKey("ApiService.Message.Error"), randomNumber)}');"; maritalStatusesR.Message = new List <MessageResult> { new MessageResult { Message = message } }; ExceptionLogging.LogException( new Exception( string.Format("There was an error to trying load Marital Statuses of the user, API Response: {0}", apiResponse.Message.Select(c => string.Format("{0}|", c.Message)).FirstOrDefault())), SessionHelper.Id, randomNumber); } return(maritalStatusesR); }
public Response <bool> ValidateCaptcha(string recaptcha) { Response <bool> response = new Response <bool> { IsSuccess = false, }; //Response<object> apiResponse = ApiService.Post<Response<bool>>(ManagmentHelper.GetBaseUrl(), // ManagmentHelper.GetBaseAPI(), // ManagmentHelper.GetKey("Proxy.ValidateRecaptcha"), null, recaptcha); //string randomNumber = Utility.GetNewNumber(); //string message = string.Empty; //if (apiResponse.IsSuccess) //{ // response = (Response<bool>)apiResponse.Result; // if (!response.IsSuccess) // { // message = $"ShowError('{string.Format(ManagmentHelper.GetKey("MaritalStatus.Get.Message.Error"))}');"; // response.Message = new List<MessageResult> { new MessageResult { Message = message } }; // } //} //else //{ // message = $"ShowError('{string.Format(ManagmentHelper.GetKey("ApiService.Message.Error"), randomNumber)}');"; // response.Message = new List<MessageResult> { new MessageResult { Message = message } }; // ExceptionLogging.LogException( // new Exception( // string.Format("There was an error to trying load Marital Statuses of the user, API Response: {0}", // apiResponse.Message.Select(c => string.Format("{0}|", c.Message)).FirstOrDefault())), // SessionHelper.Id, // randomNumber); //} //return response; bool isHuman = false; try { string secretKey = ManagmentHelper.GetKey("reCaptchaPrivateKey"); Uri uri = new Uri("https://www.google.com/recaptcha/api/siteverify" + $"?secret={secretKey}&response={recaptcha}"); HttpWebRequest request = WebRequest.CreateHttp(uri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = 0; HttpWebResponse recaptchaResponse = (HttpWebResponse)request.GetResponse(); Stream responseStream = recaptchaResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string result = streamReader.ReadToEnd(); var serializer = new JavaScriptSerializer(); //ReCaptchaResponse reCaptchaResponse = JsonConvert.DeserializeObject<ReCaptchaResponse>(result); ReCaptchaResponse reCaptchaResponse = serializer.Deserialize <ReCaptchaResponse>(result); isHuman = reCaptchaResponse.Success; response.IsSuccess = true; response.Result = isHuman; } catch (Exception ex) { response.Message.Add(new MessageResult { Message = ex.Message }); } return(response); }
public Response <User> Login(UserLoginRequest model) { Response <User> response = new Response <User> { IsSuccess = false }; var apiResponse = ApiService.Post <Response <User> >(ManagmentHelper.GetBaseUrl(), ManagmentHelper.GetBaseAPI(), ManagmentHelper.GetKey("Proxy.User.Login"), string.Empty, model); //Response<User> userResponse = (Response<User>)response.Result; string randomNumber = Utility.GetNewNumber(); string message = string.Empty; //Petición correcta. if (apiResponse.IsSuccess) { var resultApiResponse = (Response <User>)apiResponse.Result; if (resultApiResponse.IsSuccess) { response.Result = resultApiResponse.Result; if (response.Result != null) { response.IsSuccess = true; } else { message = $"ShowError('{string.Format(ManagmentHelper.GetKey("User.Login.Invalid"))}');"; response.Message = new System.Collections.Generic.List <MessageResult> { new MessageResult { Message = message } }; } } else { message = $"ShowError('{string.Format(ManagmentHelper.GetKey("User.Login.Invalid"), randomNumber)}');"; response.Message = new System.Collections.Generic.List <MessageResult> { new MessageResult { Message = message } }; ExceptionLogging.LogException( new Exception( string.Format("Error al validar email de usuario, API Response: {0}", apiResponse.Message.Select(c => string.Format("{0}|", c.Message)).FirstOrDefault())), SessionHelper.Id, randomNumber); } } else { message = $"ShowError('{string.Format(ManagmentHelper.GetKey("User.Login.Message.Error"), randomNumber)}');"; response.Message = new System.Collections.Generic.List <MessageResult> { new MessageResult { Message = message } }; ExceptionLogging.LogException( new Exception( string.Format("Error al validar Email de usuario, API Response: {0}", apiResponse.Message.Select(c => string.Format("{0}|", c.Message)).FirstOrDefault())), SessionHelper.Id, randomNumber); } return(response); }
//Старт программы static void Main(string[] args) { //конфигурация логгера XmlConfigurator.Configure(); //настройка ограничений по потокам int workerThreads = 0; int completionPortThreads = 0; ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); ThreadPool.SetMinThreads(MIN_THREAD_COUNT, completionPortThreads); #region API - соединение с Api var connector = UnityManager.Instance.Resolve <IConnector>(); while (!connector.Relogin()) { logger.Warn(string.Format("не удалось соединиться с сервером, повтор через 5 сек.")); Thread.Sleep(5000); } connector.Subscribe(); #endregion #region RabbitMQ - соединение с шиной var bus = new Bus(); bus.OnMessageReceived += (se, ea) => { Task.Run(() => { try { logger.Debug("получено сообщение из шины, {0}", ea.Message.head.what); if (ea.Message.head.what.StartsWith("poll")) { logger.Debug(string.Format("получена задача {0} для {1} объектов", ea.Message.head.what, ea.Message.body.objectIds.Count)); var ids = new List <Guid>(); foreach (dynamic id in ea.Message.body.objectIds) { Guid nodeId = Guid.Empty; if (Guid.TryParse((string)id, out nodeId)) { ids.Add(nodeId); } } var nodes = NodeManager.Instance.GetByIds(ids); var priority = PollTask.PRIORITY_USER; var darg = ea.Message.body.arg as IDictionary <string, object>; if (darg.ContainsKey("auto") && ea.Message.body.arg.auto == true) { priority = PollTask.PRIORITY_AUTO; } if (darg.ContainsKey("all") && ea.Message.body.arg.all == true) { ids = NodeManager.Instance.GetNodes <TubeNode>().Select(t => t.GetId()).ToList(); } PollTaskManager.Instance.CreateTasks(ea.Message.body.what, nodes, ea.Message.body.arg, priority); } if (ea.Message.head.what.StartsWith("check-poll")) { var msg = bus.MakeMessageStub(Guid.NewGuid().ToString(), "check"); msg.body.objectIds = new Guid[] { }; msg.body.arg = new ExpandoObject(); msg.body.what = "poll"; bus.SendCheck(msg); logger.Debug("сработал check"); } } catch (Exception ex) { logger.Error(ex, "ВНИМАНИЕ ПРОБЛЕМА ПРИ ПРИЕМЕ ЗАЯВОК"); } }); }; bus.Start(); #endregion //загрузка драйверов и нодов DriverManager.Instance.Load(); NodeManager.Instance.Load(); #region Обработчики API //регистрация обработчиков сообщений api HandlerManager.Instance.Register(new Handlers.PollHandler()); HandlerManager.Instance.Register(new Handlers.DriverHandler()); HandlerManager.Instance.Register(new Handlers.ManagmentHandler()); HandlerManager.Instance.Register(new Handlers.ChangesHandler()); #endregion #region Команды console, ожидание exit var cmd = ""; while (!(cmd = Console.ReadLine()).Contains("exit")) { switch (cmd) { case "modems": { var modems = NodeManager.Instance.GetNodes <PoolModem>(); var report = string.Format("---модемы в пуле {0:dd.MM.yy HH:mm:ss.fff}---\r\n{1}", DateTime.Now, string.Join("\r\n", modems.Select(m => m.GetInfo()))); string fileName = string.Format("{1}_{0:dd.HH-mm-ss}.txt", DateTime.Now, cmd); File.WriteAllText(fileName, report); Process.Start(fileName); break; } case "nodes": { var nodes = NodeManager.Instance.GetNodes <TubeNode>(); var report = string.Format("---тюбы в пуле {0:dd.MM.yy HH:mm:ss.fff}---\r\n{1}", DateTime.Now, string.Join("\r\n", nodes.Select(n => n.GetInfo()))); File.WriteAllText("reports.txt", report); Process.Start("reports.txt"); break; } case "status": { string fileName = "status.txt"; StringBuilder text = new StringBuilder(); text.AppendLine("---Poll Task Manager---").Append(PollTaskManager.Instance.GetInfo()).AppendLine("").AppendLine(""); text.AppendLine("---Records Acceptor---").Append(RecordsAcceptor.Instance.GetStatus()).AppendLine("").AppendLine(""); text.AppendLine("---Node Paths---"); var nodes = NodeManager.Instance.GetNodes <TubeNode>(); foreach (var node in nodes.Where(n => !n.IsDisabled())) { text.AppendLine($"id:{node.GetId()} description:{node.ToString()}"); text.AppendLine($"name:{GetParam(node.GetArguments(), "name")}; networkAddress:{GetParam(node.GetArguments(), "networkAddress")}; "); text.AppendLine("paths:"); if (node.GetPaths().Where(p => p.Where(n => n.Node.IsDisabled()).Any()).Any()) { text.Append("[DISABLED] "); } foreach (var path in node.GetPaths()) { text.AppendLine(string.Join(" -> ", path.Select(p => $"{p.Node.ToString()}{(p.Node.IsDisabled() ? " [X]" : "")}"))); } text.AppendLine(""); } text.AppendLine("").AppendLine(""); text.AppendLine("---Bus---").Append(bus.GetStatus()).AppendLine("").AppendLine(""); text.AppendLine("---Api Connector---").Append(connector.ToString()).AppendLine("").AppendLine(""); File.WriteAllText(fileName, text.ToString()); Process.Start(fileName); break; } case "info": { var nodes = NodeManager.Instance.GetNodes <PollNode>(); var report = new StringBuilder(string.Format("---статистика {0:dd.MM.yy HH:mm:ss.fff}\r\n---", DateTime.Now)); report.AppendLine(string.Format("мин потоков в пуле: {0}", workerThreads)); report.AppendLine(string.Format("всего нодов: {0}", nodes.Count())); string fileName = string.Format("{1}_{0:dd.HH-mm-ss}.txt", DateTime.Now, cmd); File.WriteAllText(fileName, report.ToString()); Process.Start(fileName); break; } case "dump": { string fileName = string.Format("dump_{0:dd.HH-mm-ss}.txt", DateTime.Now); File.WriteAllText(fileName, PollTaskManager.Instance.Dump()); Process.Start(fileName); break; } case "sys": { var sys = ""; foreach (ProcessThread thread in Process.GetCurrentProcess().Threads) { sys += string.Format("{0} {1}\n", thread.StartTime, thread.TotalProcessorTime); } string fileName = string.Format("sys_{0:dd.HH-mm-ss}.txt", DateTime.Now); File.WriteAllText(fileName, sys); break; } case "all": { //var tubes = new List<TubeNode>(); //tubes.Add((TubeNode)NodeManager.Instance.GetById(Guid.Parse("bdb15ed9-bbda-41d3-918d-e915b31764ac"))); //var tubes = NodeManager.Instance.GetNodes<TubeNode>(); //string what = "all"; //dynamic arg = new ExpandoObject(); //arg.components = "Current;Hour;Day;"; //PollTaskManager.Instance.CreateTasks(what, tubes, arg, PollTask.PRIORITY_AUTO); logger.Info("сработал стимулятор"); var tubes = NodeManager.Instance.GetNodes <TubeNode>(); string what = "all"; dynamic arg = new ExpandoObject(); arg.components = "Day:3:60;Hour:3:3"; PollTaskManager.Instance.CreateTasks(what, tubes, arg, PollTask.PRIORITY_AUTO); break; } case "cancel": { PollTaskManager.Instance.RemoveTasks(); break; } case "connect": { connector.Subscribe(); break; } //case "bus start": // { // bus.Start(); // break; // } //case "bus stop": // { // bus.Stop(); // break; // } case "bus restart": { bus.Stop(); bus.Start(); break; } //case "api restart": // { // Console.WriteLine("Перезапуск API"); // connector.Restart(); // break; // } case "reset": { ManagmentHelper.ResetServer(ConfigurationManager.AppSettings["name"]); break; } case "killcom": { Console.WriteLine("введите порт: "); var port = Console.ReadLine(); ManagmentHelper.KillCom(port); break; } case "startcom": { Console.WriteLine("введите порт: "); var port = Console.ReadLine(); ManagmentHelper.StartCom(port); break; } case "jobs": { //Stimulator.Instance.Reload(); break; } case "test": { dynamic request = Helper.BuildMessage("managment-test"); dynamic answer = connector.SendMessage(request); break; } } } #endregion #region освобождение ресурсов bus.Stop(); PollTaskManager.Instance.Dispose(); //Synchronizer.Instance.Dispose(); RecordsAcceptor.Instance.Dispose(); StateSaveCollector.Instance.Dispose(); //RecordsRepository2.Instance.Dispose(); connector.Dispose(); NodeManager.Instance.Dispose(); #endregion }