/// <inheritdoc /> public async Task UpdateStatus(SiteDTO model) { if (model == null) { throw new ArgumentException("Передана пустая объектная модель."); } var site = await Context.Sites.Select(x => x) .FirstOrDefaultAsync(x => x.Id == model.Id); if (site != null) { var siteStatus = await Context.SiteStatuses.Select(x => x) .FirstOrDefaultAsync(x => x.Site.Id == model.Id); var siteStatusEntry = Context.Entry(siteStatus); siteStatusEntry.Entity.IsAvailable = model.IsAvailable; siteStatusEntry.Entity.JobId = model.JobId; siteStatusEntry.Entity.LastUpdatedDate = model.LastUpdatedDate; siteStatusEntry.State = EntityState.Modified; await Context.SaveChangesAsync(); } }
private static bool CreateSiteInIIS(SiteCollection sites, SiteDTO dto) { try { var site = sites.CreateElement(); site.Id = dto.SiteId; site.SetAttributeValue("name", dto.SiteName); sites.Add(site); var app = site.Applications.CreateElement(); app.SetAttributeValue("path", "/"); app.SetAttributeValue("applicationPool", dto.PoolName); site.Applications.Add(app); var vdir = app.VirtualDirectories.CreateElement(); vdir.SetAttributeValue("path", "/"); vdir.SetAttributeValue("physicalPath", string.Format(@"{0}\{1}", dto.RootDir, dto.SiteName)); app.VirtualDirectories.Add(vdir); var binding = site.Bindings.CreateElement(); binding.SetAttributeValue("protocol", "http"); binding.SetAttributeValue("bindingInformation", string.Format(@":{0}:{1}", dto.Port, dto.SiteName)); site.Bindings.Add(binding); } catch (Exception ex) { Console.WriteLine("Create site {0} failed. Reason: {1}", dto.SiteName, ex.Message); return false; } return true; }
private void LoadRow(string sheetName, Dictionary <string, string> values) { ValidationIssues issues = generalDet.ValidationIssues; if (sheetName == "DET_PreySurveys") { PreySurveyDTO newDto = new PreySurveyDTO(values); newDto.Validate(); issues.Merge(newDto.ValidationIssues); bool success = generalDet.PreySurveys.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The prey survey with code {0} is not unique.", newDto.LookupKey)); } } else if (sheetName == "DET_Prey") { PreyDTO newDto = new PreyDTO(values); newDto.Validate(); issues.Merge(newDto.ValidationIssues); bool success = generalDet.Prey.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The prey with code {0} is not unique.", newDto.LookupKey)); } } else if (sheetName == "LIST_Sites") { SiteDTO newDto = new SiteDTO(values); newDto.Validate(); issues.Merge(newDto.ValidationIssues); bool success = generalDet.Sites.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The site with code {0} is not unique.", newDto.LookupKey)); } } else if (sheetName == "LIST_Species") { SpeciesDTO newDto = new SpeciesDTO(values); newDto.Validate(); issues.Merge(newDto.ValidationIssues); bool success = generalDet.Species.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The species with code {0} is not unique.", newDto.LookupKey)); } } //else if (sheetName == "LIST_LifeStages") //{ // LifeStageDTO newDto = new LifeStageDTO(values); // newDto.Validate(); // issues.Merge(newDto.ValidationIssues); // bool success = generalDet.LifeStages.Add(newDto); // if (!success) // { // issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The life stage with code {0} is not unique.", newDto.LookupKey)); // } //} }
public static void CreateSite(SiteDTO siteDto) { var mgr = new ServerManager(); var sites = mgr.Sites; CreateSiteInIIS(sites, siteDto); mgr.CommitChanges(); }
public async Task <ActionResult <Site> > PostSite(SiteDTO siteDTO) { SiteManager siteManager = _context.SiteManagers.FirstOrDefault(e => e.StaffId == siteDTO.SiteManagerId); Site site = new Site { SiteCode = siteDTO.SiteCode, SiteName = siteDTO.SiteName, SiteAddress = siteDTO.SiteAddress, Description = siteDTO.Description, SiteOfficeNo = siteDTO.SiteOfficeNo, SiteManager = siteManager }; _context.Sites.Add(site); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (SiteExists(site.SiteCode)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetSite", new { id = site.SiteCode }, site)); }
public void Init() { this.Site = new SiteDTO() { CheckedInterval = 5, Description = "Test", IsAvailable = false, JobId = Guid.NewGuid().ToString(), LastUpdatedDate = DateTime.MaxValue, Name = "Test", Url = "http://test.tu" }; var options = new DbContextOptionsBuilder <SiteContext>() .UseInMemoryDatabase(databaseName: "testDB") .Options; Context = new SiteContext(options); var loggerFactory = (ILoggerFactory) new LoggerFactory(); var logger = loggerFactory.CreateLogger <SiteRepository>(); var checkService = Substitute.For <ICheckSiteService>(); checkService.AddOrUpdateJob(Arg.Any <SiteDTO>()) .Returns(Site); this.SiteRepository = new SiteRepository(logger, Context, checkService); }
public ViewResult CheckRequest(int?page, int id) { if (ModelState.IsValid) { int size = 20; int pageNumber = (page ?? 1); SiteDTO tempSite = _siteService.GetSite(id); var mapperPaged = new MapperConfiguration(cfg => cfg.CreateMap <RequestDTO, RequestViewModel>()).CreateMapper(); var temp = mapperPaged.Map <List <RequestDTO>, List <RequestViewModel> >(tempSite.RequestsDTO); foreach (var b in temp) { ViewBag.PaggedList = temp.ToPagedList(pageNumber, size); } SiteViewModel siteVM = new SiteViewModel { Id = tempSite.Id, RequestIp = tempSite.RequestIp, SummaryTime = tempSite.SummaryTime, Url = tempSite.Url, RequestsVM = temp }; var slowResult = (from b in siteVM.RequestsVM select new { Time = b.TimeRequest, Url = b.SitemapUrl }).Where(t => t.Time == siteVM.RequestsVM.Max(y => y.TimeRequest)).First(); var fastResult = (from b in siteVM.RequestsVM select new { Time = b.TimeRequest, Url = b.SitemapUrl }).Where(t => t.Time == siteVM.RequestsVM.Min(y => y.TimeRequest)).First(); ViewBag.Slow = slowResult.Url + " - " + slowResult.Time; ViewBag.Fast = fastResult.Url + " - " + fastResult.Time; ViewBag.DataPoints = JsonConvert.SerializeObject(siteVM.RequestsVM.OrderBy(p => p.TimeRequest)); return(View(siteVM)); } return(View()); }
private async Task <Dictionary <string, int> > BulkSaveSites(IEnumerable <SiteDTO> allSites, IEnumerable <JobUploadModel> recs, Action <SiteDTO> onNewSiteCreated) { var comparer = StringComparer.InvariantCultureIgnoreCase; var sitesBySiteName = new Dictionary <string, int>(comparer); foreach (var rec in recs.Select(z => z.SiteName.Trim()).Distinct()) { var matchedSite = await SaveForMatchingField(allSites, matchCriteria : (site, field) => site.SiteName.Trim().Equals(field, StringComparison.InvariantCultureIgnoreCase), factory : async(field) => { var site = new SiteDTO() { SiteID = await _sitesRepository.Create(new SiteDTO() { SiteName = field }), SiteName = field }; onNewSiteCreated(site); return(site); }, field : rec); sitesBySiteName.TryAdd(matchedSite.SiteName.Trim(), matchedSite.SiteID); } return(sitesBySiteName); }
private void CheckHeaders(XlWorksheet worksheet) { if (worksheet != null) { Schema s; List <string> h; if (worksheet.Name == "DET_Deployments") { s = DeploymentDTO.GetSchema(); } else if (worksheet.Name == "DET_Measurements") { s = MeasurementDTO.GetSchema(); } else if (worksheet.Name == "LIST_Sites") { s = SiteDTO.GetSchema(); } else if (worksheet.Name == "LIST_Sensors") { s = SensorDTO.GetSchema(); } else { return; } h = new List <string>(); List <string> hdrs = ExcelBaseDet.Headers(worksheet); bool bad = false; for (int i = 0; i < hdrs.Count - 1; i++) { string t = hdrs[i]; for (int j = i + 1; j < hdrs.Count; j++) { if (t == hdrs[j]) { bad = true; break; //inner } } if (bad) { break; //outer } } if (bad) { generalDet.ValidationIssues.Add(ValidationIssue.Code.DuplicateHeader, "Duplicate column header in " + worksheet.Name); } foreach (SchemaEntry c in s) { h.Add(c.LowerColumnName); } if (!ExcelBaseDet.HasHeaders(hdrs, h)) { generalDet.ValidationIssues.Add(ValidationIssue.Code.MissingFieldHeader, "Missing column header in " + worksheet.Name); } } }
// Public methods /// <summary> /// Basically the Site DTO passed as paramenter has all the information about the broker site. /// </summary> /// <param name="o"> Site DTO </param> public override void Init(Object o) { SiteDTO site = o as SiteDTO; Console.Write(site); IsRoot = site.IsRoot; SiteName = site.Name; this.remoteProxy = new BrokerSiteFrontEnd(site.Brokers, SiteName); if (!IsRoot) { parentSiteBroker = new BrokerSiteFrontEnd(site.Parent.Brokers, site.Parent.Name); parentName = site.Parent.Name; } else { parentName = null; } foreach (BrokerPairDTO dto in site.Brokers) { brothers.Add(Activator.GetObject(typeof(IBroker), dto.Url) as IBroker); } foreach (SiteDTO.SiteBrokers dto in site.Childs) { childSites.Add(dto.Name, new BrokerSiteFrontEnd(dto.Brokers, dto.Name)); } logServer = Activator.GetObject(typeof(IPuppetMasterLog), pmLogServerUrl) as IPuppetMasterLog; Console.WriteLine("Broker up and running......."); }
private static bool CreateSiteInIIS(SiteCollection sites, SiteDTO dto) { try { var site = sites.CreateElement(); site.Id = dto.SiteId; site.SetAttributeValue("name", dto.SiteName); sites.Add(site); var app = site.Applications.CreateElement(); app.SetAttributeValue("path", "/"); app.SetAttributeValue("applicationPool", dto.PoolName); site.Applications.Add(app); var vdir = app.VirtualDirectories.CreateElement(); vdir.SetAttributeValue("path", "/"); vdir.SetAttributeValue("physicalPath", string.Format(@"{0}\{1}", dto.RootDir, dto.SiteName)); app.VirtualDirectories.Add(vdir); var binding = site.Bindings.CreateElement(); binding.SetAttributeValue("protocol", "http"); binding.SetAttributeValue("bindingInformation", string.Format(@":{0}:{1}", dto.Port, dto.SiteName)); site.Bindings.Add(binding); } catch (Exception ex) { Console.WriteLine("Create site {0} failed. Reason: {1}", dto.SiteName, ex.Message); return(false); } return(true); }
/// <summary> /// Проверить сайт /// </summary> public bool CheckSite(SiteDTO site, bool isSendUpdate = true) { try { if (site == null) { throw new ArgumentException($"Не передана объектная модель {nameof(site)}."); } if (string.IsNullOrWhiteSpace(site.Url)) { throw new ArgumentException($"Не передан URL."); } var request = WebRequest.Create(site.Url); using (var response = (HttpWebResponse)request.GetResponse()) { site.IsAvailable = response.StatusCode == HttpStatusCode.OK; site.LastUpdatedDate = DateTime.Now; if (isSendUpdate) { SiteService.UpdateSiteStatus(site); } return(site.IsAvailable); } } catch (Exception exception) { this.Logger.LogError("Что-то пошло не так.", exception); } return(false); }
public void AddSite(SiteDTO siteDTO) { var site = _mapper.Map <SiteDTO, Site>(siteDTO); site.AdminId = AdminIdRemember.Id; _siteRepository.AddSite(site); }
//public IEnumerable<SiteDTO> FindCarsByLicensePlate(string licensePlate) //{ // if (String.IsNullOrEmpty(licensePlate)) return null; // return _uow.Sites.All().Where(x => x.LicensePlate.Contains(licensePlate)) // .Select(car => _siteFactory.Create(car)).ToList(); //} //public IEnumerable<SiteDTO> FindCarsByPersonId(int personId) //{ // return _uow.Sites.All().Where(x => x.PersonId == personId) // .Select(car => _siteFactory.Create(car)).ToList(); //} //public List<SiteDTO> FindCars(string licensePlate, int personId) //{ // List<Site> cars = new List<Site>(); // if (licensePlate != null) // { // cars = _uow.Sites.FindByLicensePlate(licensePlate); // } else if (personId != 0) // { // cars = _uow.Sites.FindByPersonId(personId); // } // if (cars == null || cars.Count == 0) return null; // var carCollection = new List<SiteDTO>(); // foreach (var car in cars) // { // carCollection.Add(_siteFactory.Create(car)); // } // return carCollection; //} public SiteDTO AddNewSite(SiteDTO dto) { var newSite = _siteFactory.Create(dto); _uow.Sites.Add(newSite); _uow.SaveChanges(); return(_siteFactory.Create(newSite)); }
public static void CreateSite(SiteDTO siteDto) { var mgr = new ServerManager(); var sites = mgr.Sites; CreateSiteInIIS(sites, siteDto); mgr.CommitChanges(); }
// Public specific methods public override void Init(Object o) { SiteDTO siteDto = o as SiteDTO; brokerSite = new BrokerSiteFrontEnd(siteDto.Brokers, siteDto.Name); Console.Write(brokerSite.ToString()); Console.WriteLine("Subscriber up and running........"); }
private void SaveSite(OrionDbContext inMemDb, SiteDTO dto) { var site = TestAutoMapper.Instance.Map <Site>(dto); inMemDb.Sites.Add(site); inMemDb.SaveChanges(); dto.SiteID = site.SiteID; }
public static SiteDTO CreatePhonySite(int count) { SiteDTO dto = new SiteDTO(); dto.Key = String.Format("SiteID {0}", count); dto.Name = String.Format("Name {0}", count); return(dto); }
public override void beforeAll() { _site = new ObjectMother(AdministratorClarifySession).CreateSite(); _contact = new ObjectMother(AdministratorClarifySession).CreateContact(_site); var assembler = Container.GetInstance <IModelBuilder <TableToViewWithManyDTOs> >(); _viewModel = assembler.GetOne(_contact.ObjId); }
public override void Init(Object o) { SiteDTO dto = o as SiteDTO; siteName = dto.Name; brokerSite = new BrokerSiteFrontEnd(dto.Brokers, dto.Name); Console.Write(brokerSite.ToString()); Console.WriteLine("Publisher Up and running........"); }
public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle instruments) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); WaterQualityDET det = new WaterQualityDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + instruments.PrincipalOrgId.Identity.ToString(); int ct = 0; foreach (BundleElement cur in sites.Elements) { SiteDTO tmp = new SiteDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Sites.Add(tmp); ct++; } if (ct > 0) //has to be elements in the collection { ct = 0; foreach (BundleElement cur in instruments.Elements) { InstrumentDTO tmp = new InstrumentDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Instruments.Add(tmp); ct++; } if (ct > 0) { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelWaterQualityDET excel = new ExcelWaterQualityDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } return(null); }
public async Task <ActionResult <Site> > SaveAsync([FromBody] SiteDTO site) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(await SiteRepository.SaveAsync(site)); }
public ActionResult <SiteDTO> Post([FromBody] SiteDTO model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(JobService.AddOrUpdateJob(model)); }
public void CheckSite() { var obj = new SiteDTO { Url = "https://google.com" }; var result = CheckSiteJob.CheckSite(obj, false); Assert.IsTrue(result); }
public void AddSite(SiteDTO siteDTO) { Site site = new Site(); SiteConvertor.ConvertToSiteEntity(ref site, siteDTO, false); UnitOfWork unitOfWork = new UnitOfWork(); unitOfWork.SiteRepository.Add(site); unitOfWork.SaveChanges(); }
public void UpdateSite(SiteDTO siteDTO) { Site site = new Site(); SiteConvertor.ConvertToSiteEntity(ref site, siteDTO, true); UnitOfWork unitOfWork = new UnitOfWork(); unitOfWork.SiteRepository.Update(site); unitOfWork.SaveChanges(); }
public void CheckNotUrl() { var obj = new SiteDTO { Url = null }; var result = CheckSiteJob.CheckSite(obj, false); Assert.IsFalse(result); }
public async Task <ActionResult> UpdateStatus([FromBody] SiteDTO site) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await SiteRepository.UpdateStatus(site); return(this.Ok()); }
public IActionResult Post([FromBody] SiteDTO site) { if (!ModelState.IsValid) { return(BadRequest()); } var newCar = _siteService.AddNewSite(site); return(CreatedAtAction("Get", new { id = newCar.SiteId }, newCar)); }
public SiteDTO GetSiteById(int siteId) { SiteDTO siteDTO = null; var site = unitOfWork.SiteRepository.GetById(siteId); if (site != null) { siteDTO = SiteConvertor.ConvertToSiteDTO(site); } return(siteDTO); }
private void LoadRow(string sheetName, Dictionary <string, string> values) { ValidationIssues issues = generalDet.ValidationIssues; if (sheetName == "DET_Deployments") { DeploymentDTO newDto = new DeploymentDTO(values); newDto.Validate(); //issues.Merge(newDto.ValidationIssues); issues.Add(newDto.ValidationIssues.Collapse("Deployment " + newDto.DeployCode)); bool success = generalDet.Deployments.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The deployment with code {0} is not unique.", newDto.LookupKey)); } } else if (sheetName == "DET_Measurements") { values["measuredatetime"] = ExcelBaseDet.ParseDate(values["measuredatetime"]); MeasurementDTO newDto = new MeasurementDTO(values); newDto.Validate(); //issues.Merge(newDto.ValidationIssues); issues.Add(newDto.ValidationIssues.Collapse("Measurement " + newDto.DeployCode + " " + newDto.MeasureDateTime)); bool success = generalDet.Measurements.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The measurment with code {0} is not unique.", newDto.LookupKey)); } } else if (sheetName == "LIST_Sites") { SiteDTO newDto = new SiteDTO(values); newDto.Validate(); //issues.Merge(newDto.ValidationIssues); issues.Add(newDto.ValidationIssues.Collapse("Site " + newDto.Key)); bool success = generalDet.Sites.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The site with code {0} is not unique.", newDto.LookupKey)); } } else if (sheetName == "LIST_Sensors") { InstrumentDTO newDto = new InstrumentDTO(values); newDto.Validate(); //issues.Merge(newDto.ValidationIssues); issues.Add(newDto.ValidationIssues.Collapse("Instrument " + newDto.Key)); bool success = generalDet.Instruments.Add(newDto); if (!success) { issues.Add(ValidationIssue.Code.NonUniqueKeyCode, string.Format("The instrument with code {0} is not unique.", newDto.LookupKey)); } } }
public Site Create(SiteDTO dto) { return(new Site { Name = dto.Name, AddressFirstLine = dto.AddressFirstLine, Locality = dto.Locality, PostCode = dto.PostCode, Country = dto.Country, Description = dto.Description }); }
public SiteDTO GetSiteDTO() { SiteDTO.SiteBrokers parentSite = null; if (!IsRoot) parentSite = new SiteDTO.SiteBrokers(parent.Name, parent.GetSiteBrokersDTO()); SiteDTO dto = new SiteDTO(Name, IsRoot, parentSite,GetSiteBrokersDTO()); foreach(Site site in child) { dto.AddSiteChild(site.Name, site.GetSiteBrokersDTO()); } return dto; }