public async Task <bool> AddWin10Builds(NewBuildPost apiModel) { if (apiModel == null) { return(false); } if (Membership.ValidateUser(apiModel.Username, apiModel.Password)) { IEnumerable <Build> builds = apiModel.NewBuilds.Select(nb => new Build { MajorVersion = nb.MajorVersion, MinorVersion = nb.MinorVersion, Number = nb.Number, Revision = nb.Revision, Lab = nb.Lab, BuildTime = nb.BuildTime.HasValue ? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc) : null as DateTime?, Added = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak }); foreach (Build build in builds) { await _bModel.Insert(build); OneSignalClient osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); osc.PushNewBuild(build, $"https://buildfeed.net{Url.Route("Build", new { controller = "Front", action = nameof(FrontController.ViewBuild), id = build.Id, area = "", httproute = "" })}?utm_source=notification&utm_campaign=new_build"); } return(true); } return(false); }
public async Task <ActionResult> AddBulk(FormCollection values) { OneSignalClient osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); var success = new List <Build>(); var failed = new List <string>(); bool notify = bool.Parse(values[nameof(BulkAddition.SendNotifications)].Split(',')[0]); foreach (string line in values[nameof(BulkAddition.Builds)].Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) { Match m = Regex.Match(line, @"(([\d]{1,2})\.([\d]{1,2})\.)?([\d]{4,5})(\.([\d]{1,5}))?(\.| \()([a-zA-Z][a-zA-Z0-9._\(\)-]+?)\.(\d\d\d\d\d\d-\d\d\d\d)\)?"); if (m.Success) { try { Build b = new Build { MajorVersion = uint.Parse(m.Groups[2].Value), MinorVersion = uint.Parse(m.Groups[3].Value), Number = uint.Parse(m.Groups[4].Value), Revision = string.IsNullOrEmpty(m.Groups[6].Value) ? null : uint.Parse(m.Groups[6].Value) as uint?, Lab = m.Groups[8].Value, BuildTime = string.IsNullOrEmpty(m.Groups[9].Value) ? null : DateTime.SpecifyKind(DateTime.ParseExact(m.Groups[9].Value, "yyMMdd-HHmm", CultureInfo.CurrentCulture.DateTimeFormat), DateTimeKind.Utc) as DateTime?, Added = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak }; await _bModel.Insert(b); if (notify) { osc.PushNewBuild(b, $"https://buildfeed.net{Url.Action(nameof(ViewBuild), new { id = b.Id })}?utm_source=notification&utm_campaign=new_build"); } success.Add(b); } catch (Exception) { failed.Add(line); } } } ViewBag.Results = success.ToArray(); return(View(new BulkAddition { Builds = string.Join("\r\n", failed), SendNotifications = notify })); }
public async Task <ActionResult> AddBuild(Build build) { if (ModelState.IsValid) { try { build.Added = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); build.Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); if (build.BuildTime.HasValue) { build.BuildTime = DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc); } if (build.LeakDate.HasValue) { build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc); } await _bModel.Insert(build); } catch { return(View("EditBuild", build)); } OneSignalClient osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); osc.PushNewBuild(build, $"https://buildfeed.net{Url.Action(nameof(ViewBuild), new { id = build.Id })}?utm_source=notification&utm_campaign=new_build"); return(RedirectToAction(nameof(ViewBuild), new { id = build.Id })); } return(View("EditBuild", build)); }
public async Task <ActionResult> AddBuild(Build build) { if (ModelState.IsValid) { try { build.Added = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); build.Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); if (build.BuildTime.HasValue) { build.BuildTime = DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc); } if (build.LeakDate.HasValue) { build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc); } build.RegenerateCachedProperties(); BuildDetails bi = new BuildDetails { MajorVersion = build.MajorVersion, MinorVersion = build.MinorVersion, Number = build.Number, Revision = build.Revision, Lab = build.Lab, BuildTime = build.BuildTime.HasValue ? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc) : null as DateTime?, SourceType = build.SourceType, SourceDetails = build.SourceDetails }; build.History = new List <ItemHistory <BuildDetails> > { new ItemHistory <BuildDetails> { Type = ItemHistoryType.Added, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), UserName = User.Identity.Name, Item = bi } }; await _bModel.Insert(build); } catch { return(View("EditBuild", build)); } OneSignalClient osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); osc.PushNewBuild(build, $"https://buildfeed.net{Url.Action(nameof(ViewBuild), new { id = build.Id })}?utm_source=notification&utm_campaign=new_build"); return(RedirectToAction(nameof(ViewBuild), new { id = build.Id })); } return(View("EditBuild", build)); }
public async Task <bool> AddWin10Builds(NewBuildPost apiModel) { if (apiModel == null) { return(false); } if (Membership.ValidateUser(apiModel.Username, apiModel.Password) && (Roles.IsUserInRole(apiModel.Username, "Editors") || Roles.IsUserInRole(apiModel.Username, "Administrators"))) { var generateOldItem = new Func <NewBuild, BuildDetails>(nb => { var bi = new BuildDetails { MajorVersion = nb.MajorVersion, MinorVersion = nb.MinorVersion, Number = nb.Number, Revision = nb.Revision, Lab = nb.Lab, BuildTime = nb.BuildTime.HasValue ? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc) : null as DateTime?, SourceType = TypeOfSource.PrivateLeak }; return(bi); }); var builds = apiModel.NewBuilds.Select(nb => new Build { MajorVersion = nb.MajorVersion, MinorVersion = nb.MinorVersion, Number = nb.Number, Revision = nb.Revision, Lab = nb.Lab, BuildTime = nb.BuildTime.HasValue ? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc) : null as DateTime?, Added = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak, History = new List <ItemHistory <BuildDetails> > { new ItemHistory <BuildDetails> { Type = ItemHistoryType.Added, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), UserName = apiModel.Username, Item = generateOldItem(nb) } } }); foreach (Build build in builds) { await _bModel.Insert(build); var osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); osc.PushNewBuild(build, $"https://buildfeed.net{Url.Route("Build", new { controller = "Front", action = nameof(FrontController.ViewBuild), id = build.Id, area = "", httproute = "" })}?utm_source=notification&utm_campaign=new_build"); } return(true); } return(false); }
public async Task <ActionResult> AddBulk(FormCollection values) { var osc = new OneSignalClient(ConfigurationManager.AppSettings["push:OneSignalApiKey"]); var success = new List <Build>(); var failed = new List <string>(); bool notify = bool.Parse(values[nameof(BulkAddition.SendNotifications)].Split(',')[0]); foreach (string line in values[nameof(BulkAddition.Builds)] .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) { Match m = Regex.Match(line, @"(([\d]{1,2})\.([\d]{1,2})\.)?([\d]{4,5})(\.([\d]{1,5}))?(\.| \()([a-zA-Z][a-zA-Z0-9._\(\)-]+?)\.(\d\d\d\d\d\d-\d\d\d\d)\)?"); if (m.Success) { try { var b = new Build { MajorVersion = uint.Parse(m.Groups[2].Value), MinorVersion = uint.Parse(m.Groups[3].Value), Number = uint.Parse(m.Groups[4].Value), Revision = string.IsNullOrEmpty(m.Groups[6].Value) ? null : uint.Parse(m.Groups[6].Value) as uint?, Lab = m.Groups[8].Value, BuildTime = string.IsNullOrEmpty(m.Groups[9].Value) ? null : DateTime.SpecifyKind(DateTime.ParseExact(m.Groups[9].Value, "yyMMdd-HHmm", CultureInfo.CurrentCulture.DateTimeFormat), DateTimeKind.Utc) as DateTime?, Added = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), SourceType = TypeOfSource.PrivateLeak }; b.RegenerateCachedProperties(); var bi = new BuildDetails { MajorVersion = b.MajorVersion, MinorVersion = b.MinorVersion, Number = b.Number, Revision = b.Revision, Lab = b.Lab, BuildTime = b.BuildTime.HasValue ? DateTime.SpecifyKind(b.BuildTime.Value, DateTimeKind.Utc) : null as DateTime?, SourceType = b.SourceType, SourceDetails = b.SourceDetails }; b.History = new List <ItemHistory <BuildDetails> > { new ItemHistory <BuildDetails> { Type = ItemHistoryType.Added, Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), UserName = User.Identity.Name, Item = bi } }; string buildString = b.FullBuildString; Build existing = await _bModel.SelectBuildByFullBuildString(buildString); if (existing == null) { await _bModel.Insert(b); if (notify) { osc.PushNewBuild(b, $"https://buildfeed.net{Url.Action(nameof(ViewBuild), new { id = b.Id })}?utm_source=notification&utm_campaign=new_build"); } success.Add(b); } else { failed.Add(line); } } catch (Exception) { failed.Add(line); } } } ViewBag.Results = success.ToArray(); return(View(new BulkAddition { Builds = string.Join("\r\n", failed), SendNotifications = notify })); }