Beispiel #1
0
        public ActionResult Create(int?id, CustomerModel vm, int?ViewType)
        {
            vm.ViewType = ViewType != null ? (int)ViewType : 2;

            var segments = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = "", State = true
            }).Result;

            vm.Segments = segments.Select(s => new SelectListItem()
            {
                Value = s.ID.ToString(), Text = s.Name + "------>>详情>>" + s.Description
            });
            if (id != null && id > 0)
            {
                string segmentId = new SegmentService().GetSegmentByCursterId((int)base.UserInfo.ProjectID, (int)id).Result;
                vm.SelectedCustomerOrShipperSegment = long.Parse(segmentId);
                CustomerService customer = new CustomerService();
                Customer        cus      = customer.selectCustomer((int)id);
                vm.ConvertDesc(cus);
            }
            else
            {
                vm.State = true;
            }

            return(View(vm));
        }
Beispiel #2
0
        public JsonResult EditDetail(long detailID, long segmentID, long startVal, long endVal, string description)
        {
            var response = new SegmentService().UpdateSegmentDetail(new SegmentDetailRequest()
            {
                SegmentDetail = new SegmentDetail()
                {
                    ID          = detailID,
                    SegmentID   = segmentID,
                    StartVal    = startVal,
                    EndVal      = endVal,
                    Description = description,
                }
            });

            if (response.IsSuccess)
            {
                return(Json(new { ID = response.Result }));
            }
            else
            {
                if (response.Result == -1)
                {
                    return(Json(new { ID = 0, ErrorMessage = "已存在此段位" }));
                }

                return(Json(new { ID = 0, ErrorMessage = "编辑段位失败!" }));
            }
        }
Beispiel #3
0
        public ActionResult Create(CreateSegmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                Segment segment = new Segment()
                {
                    Name = model.Name, Description = model.Description, State = model.State, Creator = base.UserInfo.Name, CreateTime = DateTime.Now, Str1 = model.Str1, Str2 = model.Str2, Str3 = model.Str3
                };
                var response = new SegmentService().AddSegment(new AddSegmentRequest()
                {
                    Segment = segment
                });
                if (response.IsSuccess)
                {
                    return(RedirectToAction("CreateDetail", new { segmentID = response.Result }));
                }
                else
                {
                    if (response.Result == -1)
                    {
                        ViewBag.Message = "已存在相同名称的段位";
                    }
                    else
                    {
                        ViewBag.Message = "新增段位失败!.";
                    }
                }
            }

            return(View(model));
        }
Beispiel #4
0
        public ActionResult Schedule()
        {
            ViewData["Message"]  = "BookTV Schedule";
            ViewData["Segments"] = new SegmentService().GetSegments();

            return(View());
        }
Beispiel #5
0
        public JsonResult CreateDetail(long segmentID, float startVal, float endVal, string description)
        {
            var response = new SegmentService().AddSegmentDetail(new SegmentDetailRequest()
            {
                SegmentDetail = new SegmentDetail()
                {
                    SegmentID   = segmentID,
                    StartVal    = startVal,
                    EndVal      = endVal,
                    Description = description,
                    Creator     = base.UserInfo.Name,
                    CreateTime  = DateTime.Now
                }
            });

            if (response.IsSuccess)
            {
                return(Json(new { ID = response.Result }));
            }
            else
            {
                if (response.Result == -1)
                {
                    return(Json(new { ID = 0, ErrorMessage = "已存在此段位" }));
                }

                return(Json(new { ID = 0, ErrorMessage = "新增段位失败!" }));
            }
        }
        public IEnumerable <Contact> GetContacts(int Id)
        {
            var segment = new SegmentService().GetById(Id);

            return(new OrganisationService()
                   .GetByIds(segment.OrganisationIds)
                   .Select(x => new ContactService().GetByOrganisationId(x.Id))
                   .SelectMany(x => x)
                   .Distinct());
        }
Beispiel #7
0
        public async void EnqueueTask(HyperServerTask task)
        {
            var path = Path.Combine(SystemPath, task.Path);

            try
            {
                Interlocked.Increment(ref _activeOperations);

                if (task.IsSegmentRequest)
                {
                    using (
                        var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, task.Length,
                                                FileOptions.Asynchronous))
                    {
                        fs.Position = task.Offset;
                        var read = await fs.ReadAsync(task.Buffer.Object, 0, task.Length).ConfigureAwait(false);

                        if (read != task.Length)
                        {
                            Logger.Error("Can't read all bytes {0}/{1} {2}", read, task.Length, task.Path);
                            return;
                        }

                        SegmentService.Update(task.SinceCreatedMs);
                        SegmentsPerSecond.Update(1);
                    }
                }
                else
                {
                    task.FileLength = new FileInfo(path).Length;
                }

                task.Done();
            }
            catch (Exception x)
            {
                if (x is FileNotFoundException)
                {
                    OnFileGone(new FileGoneEventArgs {
                        RelativePath = task.Path,
                        SystemPath   = path
                    });
                }

                Logger.Error($"Error when reading the file {task.Path} {x.Message}");
            }
            finally
            {
                Interlocked.Decrement(ref _activeOperations);
            }
        }
        public async Task SegmentServiceSegmentsHealthCheckAsyncReturnsSuccess()
        {
            // arrange
            var segmentService = new SegmentService(
                logService,
                overviewBannerSegmentService,
                howToBecomeSegmentService,
                whatItTakesSegmentService,
                whatYouWillDoSegmentService,
                careerPathSegmentService,
                currentOpportunitiesSegmentService,
                relatedCareersSegmentService);

            var expectedResult = new HealthCheckItems
            {
                Source      = new Uri("http://somewhere.com"),
                HealthItems = new List <HealthCheckItem>
                {
                    new HealthCheckItem
                    {
                        Service = "Unit test",
                        Message = "All ok",
                    },
                },
            };

            A.CallTo(() => careerPathSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));
            A.CallTo(() => currentOpportunitiesSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));
            A.CallTo(() => howToBecomeSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));
            A.CallTo(() => overviewBannerSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));
            A.CallTo(() => relatedCareersSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));
            A.CallTo(() => whatItTakesSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));
            A.CallTo(() => whatYouWillDoSegmentService.HealthCheckAsync()).Returns(Task.FromResult(expectedResult));

            // act
            var results = await segmentService.SegmentsHealthCheckAsync().ConfigureAwait(false);

            // assert
            A.CallTo(() => careerPathSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => currentOpportunitiesSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => howToBecomeSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => overviewBannerSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => relatedCareersSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => whatItTakesSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => whatYouWillDoSegmentService.HealthCheckAsync()).MustHaveHappenedOnceExactly();

            results.Count.Should().Be(NumberOfSegmentServices);
            results[0].Service.Should().Be(expectedResult.HealthItems[0].Service);
            results[0].Message.Should().Be(expectedResult.HealthItems[0].Message);
        }
Beispiel #9
0
        public ActionResult SegmentDetail()
        {
            var titleHash      = Convert.ToInt32(RouteData.Values["ID"]);
            var segmentService = new SegmentService();
            var segments       = segmentService.GetSegments();

            //HACK: To keep working on UI, try to find one with the same title+airing, else return the last one in the list
            var segment = (segments.FirstOrDefault(s => (s.Title + s.DayDescription + s.Time).GetHashCode() == titleHash) ?? segments.Last());

            segment.SegmentDetail = segmentService.GetSegmentDetail(segment);

            ViewData.Model = segment;

            return(View());
        }
Beispiel #10
0
        public ActionResult DelOrReuseSegment(long segmentID, bool state)
        {
            var response = new SegmentService().SetSegmentState(new SetSegmentStateRequest()
            {
                ID = segmentID, State = !state
            });

            if (!response.IsSuccess)
            {
                string msg = state ? "禁用" : "启用";
                ViewBag.Message = msg + "段位失败!";
            }

            return(RedirectToAction("List"));
        }
Beispiel #11
0
        public ActionResult List()
        {
            SegmentListViewModel vm = new SegmentListViewModel();
            var response            = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = "", State = true
            });

            if (response.IsSuccess)
            {
                vm.Segments = response.Result;
                vm.State    = true;
            }

            return(View(vm));
        }
Beispiel #12
0
        public ActionResult CustomerOrShipperSegmentAllocate(int id)
        {
            var customerOrShippers = new ProjectService().GetProjectCustomersOrShippers(new GetProjectCustomersOrShippersRequest()
            {
                ProjectID = base.UserInfo.ProjectID, Target = id
            }).Result.Where(cs => cs.State);
            var customers = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID);
            var segments  = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = "", State = true
            }).Result;

            if (customerOrShippers == null || !customerOrShippers.Any())
            {
                return(Error("请先设置项目" + (id == 0 ? "客户" : "承运商")));
            }

            if (segments == null || !segments.Any())
            {
                return(Error("请先配置段位"));
            }

            if (id == 1 && (customers == null || !customers.Any()))
            {
                return(Error("请先分配项目客户"));
            }

            CustomerOrShipperSegmentViewModel vm = new CustomerOrShipperSegmentViewModel()
            {
                Target    = id,
                ProjectID = base.UserInfo.ProjectID,
                CustomerOrShippersCollection = customerOrShippers.Select(s => new SelectListItem()
                {
                    Value = s.CustomerOrShipperID.ToString(), Text = s.CustomerOrShipperName
                }),
                Segments = segments.Select(s => new SelectListItem()
                {
                    Value = s.ID.ToString(), Text = s.Name
                }),
                Customers = customers.Select(c => new SelectListItem()
                {
                    Value = c.CustomerID.ToString(), Text = c.CustomerName
                })
            };

            return(View(vm));
        }
Beispiel #13
0
        private IEnumerable <SelectListItem> GetSegments()
        {
            var response = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = "", State = true
            });

            if (response.IsSuccess)
            {
                return(response.Result.Select(r => new SelectListItem()
                {
                    Value = r.ID.ToString(), Text = r.Name
                }));
            }

            return(Enumerable.Empty <SelectListItem>());
        }
Beispiel #14
0
        public ActionResult List(SegmentListViewModel vm)
        {
            var response = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = string.IsNullOrEmpty(vm.Name) ? "" : vm.Name, State = vm.State
            });

            if (response.IsSuccess)
            {
                vm.Segments = response.Result;
            }
            else
            {
                ViewBag.Message = "查询失败";
            }

            return(View(vm));
        }
Beispiel #15
0
        static void detectAnomalies()
        {
            var anomalyDetectionModel      = Serializer.Load <SupportVectorMachine <Gaussian> >(AnomalyDetectionModelFileName);
            var anomalyClassificationModel = Serializer.Load <SupportVectorMachine <Gaussian> >(AnomalyClassificationModelFileName);

            MLService      service        = new MLService();
            SegmentService serviceService = new SegmentService();

            var chains = service.GetAllSegments_SegmentChain7_AnomalySpreaded();

            int numberOfAnomalies = 0;
            int numberOfPotholes  = 0;

            foreach (var chain in chains)
            {
                double[] inputs           = new double[] { chain.MaxSpeed.Value, chain.MinSpeed.Value, chain.SpeedRange.Value, chain.TotalTime.Value, chain.MinTime.Value, chain.MaxTime.Value, chain.TimeRange.Value, chain.MaxSpeedVar.Value, chain.MinSpeedVar.Value, chain.SpeedVarRange.Value, chain.MaxTimeVar.Value, chain.MinTimeVar.Value, chain.TimeVarRange.Value };
                bool     isContainAnomaly = anomalyDetectionModel.Decide(inputs);
                bool     isPothole        = false;
                if (isContainAnomaly)
                {
                    numberOfAnomalies++;

                    isPothole = anomalyClassificationModel.Decide(inputs);
                    if (isPothole)
                    {
                        numberOfPotholes++;
                    }

                    SegmentChain sc = new SegmentChain()
                    {
                        Segment1Id           = chain.Segment1Id,
                        Segment2Id           = chain.Segment2Id,
                        Segment3Id           = chain.Segment3Id,
                        Segment4Id           = chain.Segment4Id,
                        Segment5Id           = chain.Segment5Id,
                        Segment6Id           = chain.Segment6Id,
                        Segment7Id           = chain.Segment7Id,
                        PredictedAnomalyType = (short)(isContainAnomaly? (isPothole?2:1):0),
                        CreationDate         = DateTime.Now
                    };
                    serviceService.CreateSegmentChain(sc);
                }
            }
        }
Beispiel #16
0
        public ActionResult CreateDetail(long segmentID)
        {
            var response = new SegmentService().GetSegmentAndDetail(new SegmentRequest {
                ID = segmentID
            });
            CreateSegmentDetailViewModel vm = new CreateSegmentDetailViewModel();

            if (response.IsSuccess)
            {
                vm.Segment = response.Result.Segment;
                vm.SegmentDetailCollection = response.Result.SegmentDetailCollection;
            }
            else
            {
                ViewBag.Message = "获取段位信息失败!";
            }

            return(View(vm));
        }
Beispiel #17
0
        public ActionResult Create(CustomerModel vm)
        {
            CustomerService  service  = new CustomerService();
            IList <Customer> customer = new List <Customer>();

            var segments = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = "", State = true
            }).Result;

            vm.Segments = segments.Select(s => new SelectListItem()
            {
                Value = s.ID.ToString(), Text = s.Name + "------>>详情>>" + s.Description
            });
            vm.Types = vm.StoreStatus > 0 ? 1 : 0;
            customer.Add(vm.Convert());
            Response <IEnumerable <Customer> > response = service.AddCustomer(new AddCustomerRequest()
            {
                customers = customer
            }, base.UserInfo.ID.ToString(), base.UserInfo.Name, (int)base.UserInfo.ProjectID, vm.SelectedCustomerOrShipperSegment.ToString() == "" ? 0 : (int)vm.SelectedCustomerOrShipperSegment);

            if (vm.ID > 0)
            {
                Customer cus = service.selectCustomer((int)vm.ID);
                vm.ConvertDesc(cus);
            }

            if (response.IsSuccess)
            {
                ApplicationConfigHelper.RefreshApplicationCustomers();
                ApplicationConfigHelper.RefreshGetApplicationCustomer();
                ApplicationConfigHelper.RefreshCustomers();
                if (vm.StoreType > 1)
                {
                    ViewBag.Message = response.Result.Select(c => c.ID).FirstOrDefault().ToString();
                }
                else
                {
                    ViewBag.Message = "0";
                }
            }
            return(View(vm));
        }
Beispiel #18
0
        public JsonResult DeleteSegmentDetail(long detailID)
        {
            var response = new SegmentService().DeleteSegmentDetail(new SegmentRequest()
            {
                ID = detailID
            });

            if (response.IsSuccess)
            {
                return(Json(new { ID = response.Result }));
            }
            else
            {
                if (response.Result == -1)
                {
                    return(Json(new { ID = 0, ErrorMessage = "此段位已使用,无法删除" }));
                }

                return(Json(new { ID = 0, ErrorMessage = "删除段位失败!" }));
            }
        }
Beispiel #19
0
        public ActionResult ShiperSegment(int id, string message)
        {
            var customerOrShippers = new ProjectService().GetProjectCustomersOrShippers(new GetProjectCustomersOrShippersRequest()
            {
                ProjectID = base.UserInfo.ProjectID, Target = 1
            }).Result.Where(cs => cs.CustomerOrShipperID == id);
            var customers = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID);
            var segments  = new SegmentService().GetSegmentsByCondition(new GetSegmentsByConditionRequest()
            {
                Name = "", State = true
            }).Result;
            var projectShipperSegments = ApplicationConfigHelper.GetProjectCustomerOrShiperSegment().Where(p => p.Target == 1 && p.CustomerOrShipperID == id && p.ProjectID == base.UserInfo.ProjectID);


            CustomerOrShipperSegmentViewModel vm = new CustomerOrShipperSegmentViewModel()
            {
                Target = 1,
                SelectedCustomerOrShipperID = id.ToString(),
                ProjectID = base.UserInfo.ProjectID,
                ProjectCustomerOrShipperSegments = projectShipperSegments,
                ShipperName = customerOrShippers.Where(c => c.CustomerOrShipperID == id).FirstOrDefault().CustomerOrShipperName,
                CustomerOrShippersCollection = customerOrShippers.Select(s => new SelectListItem()
                {
                    Value = s.CustomerOrShipperID.ToString(), Text = s.CustomerOrShipperName
                }),
                Segments = segments.Select(s => new SelectListItem()
                {
                    Value = s.ID.ToString(), Text = s.Name + "------>>详情>>" + s.Description
                }),
                Customers = customers.Select(c => new SelectListItem()
                {
                    Value = c.CustomerID.ToString(), Text = c.CustomerName
                })
            };

            return(View(vm));
        }
 public string DebugLine()
 {
     return($"Storage {SystemPath} SVC: {(int)SegmentService.GetAverage()} RPS: {(int)SegmentsPerSecond.GetSpeed()} Q: {QueueSize}");
 }
Beispiel #21
0
        public async void EnqueueTask(HyperServerTask task)
        {
            try
            {
                Interlocked.Increment(ref _activeOperations);

                var normalizedPath = task.Path.Replace("/", "\\");

                if (normalizedPath.StartsWith("/"))
                {
                    normalizedPath = normalizedPath.Remove(0, 1);
                }


                string tth;
                lock (_pathIndex)
                {
                    if (!_pathIndex.TryGetValue(normalizedPath, out tth))
                    {
                        Logger.Error($"Error when requesting hyper segment {normalizedPath} No such file in share index yet");
                        return;
                    }
                }

                var ci = _share.SearchByTth(tth);

                if (ci == null)
                {
                    Logger.Error($"TTH {tth} not found in share");
                    return;
                }

                if (task.IsSegmentRequest)
                {
                    if (!_cacheManager.ReadCacheSegment(tth, task.Offset, task.Length, task.Buffer.Object, 0))
                    {
                        if (ci.Value.SystemPath.StartsWith("hyp://"))
                        {
                            var segment = await _manager.DownloadSegment(task.Path, task.Offset, task.Length);

                            task.Buffer.Dispose();
                            task.Buffer = segment;
                        }
                        else if (ci.Value.SystemPath.StartsWith("http://"))
                        {
                            using (var stream = await HttpHelper.GetHttpChunkAsync(ci.Value.SystemPath, task.Offset, task.Length))
                                using (var ms = new MemoryStream(task.Buffer.Object))
                                {
                                    stream.CopyTo(ms);
                                }
                        }
                        else
                        {
                            throw new InvalidOperationException("Not supported source type " + ci.Value.SystemPath);
                        }

                        SegmentServiceProxy.Update(task.SinceCreatedMs);
                        SegmentsPerSecondProxy.Update(1);
                    }
                    else
                    {
                        SegmentServiceCached.Update(task.SinceCreatedMs);
                        SegmentsPerSecondCached.Update(1);
                    }

                    SegmentService.Update(task.SinceCreatedMs);
                    SegmentsPerSecond.Update(1);
                }
                else
                {
                    task.FileLength = ci.Value.Magnet.Size;
                }
            }
            catch (Exception x)
            {
                Logger.Error($"Error when requesting hyper segment {task.Path} {x.Message}");
            }
            finally
            {
                Interlocked.Decrement(ref _activeOperations);
                task.Done();
            }
        }
 public SegmentController()
 {
     service        = new SegmentService();
     anomalyService = new AnomalyService();
 }
        public IEnumerable <Contact> GetContacts(int Id)
        {
            var segment = new SegmentService().GetById(Id);

            return(new ContactService().GetByIds(segment.ContactIds));
        }
        public void TestMethod1()
        {
            var s = new SegmentService().GetSegments();

            s.Count.ToString();
        }
 public void TestMethod1()
 {
     var s = new SegmentService().GetSegments();
     s.Count.ToString();
 }
        private void Worker()
        {
            while (IsEnabled)
            {
                while (_tasks.TryDequeue(out var task))
                {
                    var path = Path.Combine(SystemPath, task.Path);

                    try
                    {
                        if (task.Length > 0)
                        {
                            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, task.Length))
                            {
                                fs.Position = task.Offset;

                                var read = fs.Read(task.Buffer.Object, 0, task.Length);

                                if (read != task.Length)
                                {
                                    Logger.Error("Can't read all bytes {0}/{1} {2}", read, task.Length, task.Path);
                                    continue;
                                }

                                SegmentService.Update(task.SinceCreatedMs);
                                SegmentsPerSecond.Update(1);
                            }
                        }
                        else
                        {
                            var fi = new FileInfo(path);

                            if (!fi.Exists)
                            {
                                task.FileLength = -1;
                            }
                            else
                            {
                                task.FileLength = fi.Length;
                            }
                        }

                        task.Done();
                    }
                    catch (Exception x)
                    {
                        if (x is FileNotFoundException)
                        {
                            OnFileGone(new FileGoneEventArgs
                            {
                                RelativePath = task.Path,
                                SystemPath   = path
                            });
                        }

                        Logger.Error("Error during reading of data {0} {1}", task.Path, x.Message);
                    }
                }
                Thread.Yield();
            }
        }