Esempio n. 1
0
        public IHttpActionResult RegisterMobileDevice([FromBody] iTicketConfigurationModel model, DateTime eventsAfter)
        {
            try
            {
                string pointA = model.PointAIpAddress + ":" + model.PointAPort;
                string pointB = model.PointBIpAddress + ":" + model.PointBPort;

                SectionConfigurationModel sectionModel = GetSectionByIP(pointA, pointB, eventsAfter);
                if (sectionModel == null)
                {
                    string processToStart = ConfigurationManager.AppSettings["DistanceOverTimeAdapter"].ToString();

                    Process process = new Process();

                    if (!string.IsNullOrEmpty(model.PointAIpAddress) && model.PointAPort > 0 && !string.IsNullOrEmpty(model.PointBIpAddress) && model.PointBPort > 0)
                    {
                        process.StartInfo = new ProcessStartInfo
                        {
                            FileName  = processToStart,
                            Arguments = string.Format("-listenerType=S -listenMs={0} -ipA={1}:{2} -ipB={3}:{4}", model.PollMs, model.PointAIpAddress, model.PointAPort, model.PointBIpAddress, model.PointBPort)
                        };
                    }

                    process.Start();
                }

                DateTime timeout = DateTime.Now.AddMinutes(2);

                while (true)
                {
                    if (DateTime.Now >= timeout)
                    {
                        return(this.BadRequestEx(Error.RegisterMobileDeviceTimeout));
                    }

                    sectionModel = GetSectionByIP(pointA, pointB, eventsAfter);

                    if (sectionModel != null)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }

                return(Ok(sectionModel));
            }
            catch (Exception ex)
            {
                return(this.BadRequestEx(Error.PopulateUnexpectedException(ex)));
            }
        }
Esempio n. 2
0
        public SectionConfigurationModel RegisterMobileDevice(iTicketConfigurationModel model, DateTime eventsAfter)
        {
            var request = new RestRequest("api/Configuration/DOT/Registration/MobileDevice", Method.POST);

            request.AddQueryParameter("eventsAfter", eventsAfter.ToString());
            request.AddJsonBody(model);

            var response = RestClient.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw CreateException(response);
            }

            return(JsonConvert.DeserializeObject <SectionConfigurationModel>(response.Content));
        }