public SetEntity InsertSetEntity(SetEntity set) { _context.Sets.Add(_context.SetAudit <SetEntity>(set)); _context.SaveChanges(); return(set); }
public ActionResult DeleteSet(string setName) { try { Repository <SetEntity> setsRepository = new Repository <SetEntity>(); SetEntity set = setsRepository.GetList().Where(s => s.Name == setName).FirstOrDefault(); if (set != null) { setsRepository.Delete(set.Id); string setDirectoryPath = Server.MapPath("~/Content/Images/Sets/" + setName); if (Directory.Exists(setDirectoryPath)) { Directory.Delete(setDirectoryPath, true); } return(Json(new { result = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { result = "Fail" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(ProcessException(ex)); } }
public SetModel(string key, string value) { _set = new SetEntity { Id = Guid.NewGuid(), Key = key, Value = value, Score = 0.0 }; }
private static SetInfo CreateSetInfoFromEntity(CloudTableClient client, SetEntity set) { SetInfo setInfo = new SetInfo(); setInfo.CompletedAt = set.CompletedOn; setInfo.CompletedWorkItems = new List <WorkItem>(); setInfo.Container = set.ResultContainer; setInfo.ExpectedWorkItems = set.TextureTilesX * set.TextureTilesY; setInfo.Id = set.RowKey; setInfo.InProgressWorkItems = new List <WorkItem>(); setInfo.Path = set.ResultPath; setInfo.QueuedAt = set.CreatedOn; setInfo.Status = "NotStarted"; TableQuery <WorkEntity> workQuery = new TableQuery <WorkEntity>().Where( TableQuery.GenerateFilterCondition( "PartitionKey", QueryComparisons.Equal, WorkEntity.EncodeResultPath(set.ResultPath, set.ResultContainer)) ); IEnumerable <WorkEntity> workEntities = client.GetTableReference(WorkTableName).ExecuteQuery(workQuery); foreach (var workEntity in workEntities) { WorkItem workItem = new WorkItem(); workItem.X = workEntity.TextureTileX; workItem.Y = workEntity.TextureTileY; workItem.StartedAt = workEntity.StartTime; workItem.CompletedAt = workEntity.CompletedTime; if (workItem.CompletedAt.HasValue) { setInfo.CompletedWorkItems.Add(workItem); } else { setInfo.Status = "InProgress"; setInfo.InProgressWorkItems.Add(workItem); } } if (set.Completed) { setInfo.Status = "Completed"; } else if (set.Failed) { setInfo.Status = "Failed"; } return(setInfo); }
public async Task Test_for_all_Facts(int homePoints, int guestPoints, bool isTieBreak, SingleSetValidator.FactId expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new OrganizationContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 2, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 2 })); var result = await sv.CheckAsync(CancellationToken.None); Assert.AreEqual(expected, sv.GetFailedFacts().First(r => !r.Success).Id); }
public async Task Test_for_all_Facts_Should_Succeed(int homePoints, int guestPoints, bool isTieBreak) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 2, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 2 })); var result = await sv.CheckAsync(CancellationToken.None); Assert.AreEqual(0, sv.GetFailedFacts().Count); }
public static void InsertSetMetadata(CloudTableClient client, SetEntity set) { // Create the CloudTable object that represents the "sets" table. CloudTable table = client.GetTableReference(SetsTableName); table.CreateIfNotExists(); // Create the TableOperation that inserts the set entity. TableOperation insertOperation = TableOperation.Insert(set); // Execute the insert operation. table.Execute(insertOperation); }
public void All_Ids_Have_A_Check_Function() { var set = new SetEntity(); var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1))); var enums = Enum.GetNames(typeof(SingleSetValidator.FactId)).ToList(); foreach (var e in enums) { var fact = sv.Facts.First(f => f.Id.Equals(Enum.Parse <SingleSetValidator.FactId>(e))); Console.WriteLine(fact.Id); Assert.IsTrue(fact.CheckAsync != null); } }
protected override void Initialize() { var cce1 = new ContainedEntity(); var cse1 = new SetEntity(); cse1.Entities.Add(cce1); using (var tx = Session.BeginTransaction()) { cce1_id = (long)Session.Save(cce1); cse1_id = (int)Session.Save(cse1); tx.Commit(); } }
public void Overrule_Set_Points(int homeBallPts, int guestBallPts, int homeSetPts, int guestSetPts) { var set = new SetEntity { HomeBallPoints = homeBallPts, GuestBallPoints = guestBallPts, IsTieBreak = true, IsOverruled = false }; set.Overrule(homeBallPts, guestBallPts, homeSetPts, guestSetPts); Assert.Multiple(() => { Assert.AreEqual(homeSetPts, set.HomeSetPoints); Assert.AreEqual(guestSetPts, set.GuestSetPoints); Assert.IsFalse(set.IsTieBreak); Assert.IsTrue(set.IsOverruled); }); }
public async Task Ball_Points_Are_Not_Negative(int homePoints, int guestPoints, bool expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1))); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.BallPointsNotNegative, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public void Calculate_Set_Points(int homeBallPts, int guestBallPts, int expectedHomeSetPts, int expectedGuestSetPts) { var set = new SetEntity { HomeBallPoints = homeBallPts, GuestBallPoints = guestBallPts }; var setRule = new SetRuleEntity { PointsSetWon = 3, PointsSetLost = 1, PointsSetTie = 2 }; set.CalculateSetPoints(setRule); Assert.Multiple(() => { Assert.AreEqual(expectedHomeSetPts, set.HomeSetPoints); Assert.AreEqual(expectedGuestSetPts, set.GuestSetPoints); }); }
public async Task Disallow_Tie_In_Regular_Sets(int homePoints, int guestPoints, bool expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = false }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { PointsDiffToWinRegular = 2, PointsDiffToWinTiebreak = 2 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.TieIsAllowed, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
[TestCase(15, 14, true, true)] // only points to win are checked here public async Task Num_Of_BallPoints_To_Win_Is_Reached(int homePoints, int guestPoints, bool isTieBreak, bool expected) { var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, NumOfPointsToWinTiebreak = 15 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.NumOfPointsToWinReached, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public async Task Regular_Win_Reached_With_One_Point_Ahead(int homePoints, int guestPoints, bool isTieBreak, bool expected) { // tie-break is ignored var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new OrganizationContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 1, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 1 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.RegularWinReachedWithOnePointAhead, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public async Task TieBreak_Win_Reached_With_TwoOrMore_Points_Ahead(int homePoints, int guestPoints, bool isTieBreak, bool expected) { // regular sets are ignored var set = new SetEntity { HomeBallPoints = homePoints, GuestBallPoints = guestPoints, IsTieBreak = isTieBreak }; var sv = new SingleSetValidator(set, (new TenantContext(), new SetRuleEntity(1) { NumOfPointsToWinRegular = 25, PointsDiffToWinRegular = 2, NumOfPointsToWinTiebreak = 15, PointsDiffToWinTiebreak = 2 })); var factResult = await sv.CheckAsync(SingleSetValidator.FactId.TieBreakWinReachedWithTwoPlusPointsAhead, CancellationToken.None); Assert.Multiple(() => { Assert.AreEqual(expected, factResult.Success); Assert.IsNotNull(factResult.Message); Assert.IsNull(factResult.Exception); }); }
public ActionResult ChangeSet(string setName) { try { ViewBag.Title = "Admin Change Set " + setName; AdminChangeSetViewModel viewModel = new AdminChangeSetViewModel(); Repository <SetsInfo> repositorySetInfo = new Repository <SetsInfo>(); SetsInfo setInfo = repositorySetInfo.GetList().First(); if (setInfo.TempSetNumber == int.MaxValue) { setInfo.TempSetNumber = 0; } setInfo.TempSetNumber++; repositorySetInfo.Update(setInfo); Repository <SetEntity> setEntityRepository = new Repository <SetEntity>(); SetEntity set = setEntityRepository.GetList().Where(s => s.Name == setName).First(); string setPath = Server.MapPath("~/Content/Images/Sets/" + set.Name); DirectoryInfo setDirectory = new DirectoryInfo(setPath); FileInfo[] images = setDirectory.GetFiles(); foreach (FileInfo image in images) { if (image.Name.Contains("ImageMainImage")) { viewModel.MainImageName = image.Name; break; } } viewModel.TempSetNumber = setInfo.TempSetNumber; viewModel.SetName = set.Name; viewModel.Html = set.Html; viewModel.Tags = set.Tags; return(View(viewModel)); } catch (Exception ex) { return(ProcessException(ex)); } }
public ActionResult Set(string name) { try { Repository <SetEntity> setRepostory = new Repository <SetEntity>(); SetEntity set = setRepostory.GetList().FirstOrDefault(s => s.Name == name); ViewBag.Title = "Set " + name; ViewBag.Controller = "Work"; int imageCount = new Regex("imgLoaded").Matches(set.HtmlWithoutNotResultElements).Count; SetViewModel vm = new SetViewModel { Name = name, Html = set.HtmlWithoutNotResultElements, ImagesCount = imageCount }; return(View(vm)); } catch (Exception ex) { return(ProcessException(ex)); } }
static void Main(string[] args) { // Get storage account CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Settings.Default.StorageConnectionString); // Create the clients CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); BlobClient = storageAccount.CreateCloudBlobClient(); TableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to a queue WorkQueue = queueClient.GetQueueReference(Settings.Default.Queue); // Create the queue if it doesn't already exist WorkQueue.CreateIfNotExists(); CloudOptions opt; try { opt = CliParser.Parse <CloudOptions>(args); if (opt.ForceCubical) { int longestGridSide = Math.Max(Math.Max(opt.XSize, opt.YSize), opt.ZSize); opt.XSize = opt.YSize = opt.ZSize = longestGridSide; Console.WriteLine("Due to -ForceCubical grid size is now {0},{0},{0}", longestGridSide); } var options = new SlicingOptions { OverrideMtl = opt.MtlOverride, GenerateEbo = opt.Ebo, GenerateOpenCtm = opt.OpenCtm, Debug = opt.Debug, GenerateObj = opt.Obj, Texture = Path.GetFileName(opt.Texture), Obj = Path.GetFileName(opt.Input.First()), WriteMtl = opt.WriteMtl, TextureScale = opt.ScaleTexture, TextureSliceX = opt.TextureXSize, TextureSliceY = opt.TextureYSize, ForceCubicalCubes = opt.ForceCubical, CubeGrid = new Vector3 { X = opt.XSize, Y = opt.YSize, Z = opt.ZSize } }; string objPath; if (opt.Input.First().StartsWith("http")) { objPath = opt.Input.First(); } else { objPath = StorageUtilities.UploadBlob(BlobClient, opt.Input.First(), Guid.NewGuid().ToString(), "processingdata"); } string texPath; if (opt.Texture.StartsWith("http")) { texPath = opt.Texture; } else { texPath = StorageUtilities.UploadBlob(BlobClient, opt.Texture, Guid.NewGuid().ToString(), "processingdata"); } options.CloudObjPath = objPath; options.CloudTexturePath = texPath; options.CloudResultContainer = opt.OutputContainer; options.CloudResultPath = opt.OutputPath; // Get texture set size Vector2 setSize; if (!string.IsNullOrEmpty(options.Texture) && (options.TextureSliceX + options.TextureSliceY) > 2) { setSize = new Vector2(options.TextureSliceX, options.TextureSliceY); } else { setSize = new Vector2(1, 1); } // Queue work var setEntity = new SetEntity("Set", DateTime.UtcNow) { ResultPath = options.CloudResultPath, ResultContainer = options.CloudResultContainer, TextureTilesX = setSize.X, TextureTilesY = setSize.Y }; options.SetKey = setEntity.RowKey; StorageUtilities.InsertSetMetadata(TableClient, setEntity); SpatialUtilities.EnumerateSpace(setSize, (x, y) => { options.TextureTile = new Vector2(x, y); string message = JsonConvert.SerializeObject(options); WorkQueue.AddMessage(new CloudQueueMessage(message)); }); } catch (ParserExit) { return; } catch (ParseException) { Console.WriteLine("usage: PyriteCli --help"); } }
public SetRepository() { setEntity = new SetEntity(); }
public SetModel(SetEntity set) { _set = set; }
public ActionResult SaveSet(string setName, string setTags, string resultHtml, string resultHtmlWithoutNotResultElements, string tempSetNumber) { try { string mainImageName = null; string setPath = Server.MapPath("~/Content/Images/Sets/" + setName.Trim()); DirectoryInfo setDirectory = new DirectoryInfo(setPath); setDirectory.Create(); string tempDirectoryPath = Server.MapPath("~/Content/Images/Temp/" + "Set" + tempSetNumber); DirectoryInfo tempSetDirectory = new DirectoryInfo(tempDirectoryPath); FileInfo[] images = tempSetDirectory.GetFiles(); foreach (FileInfo image in images) { string fileName = image.Name.Substring(0, image.Name.LastIndexOf('.')); if (resultHtmlWithoutNotResultElements.Contains(fileName)) { using (Image imageFromPath = Image.FromFile(image.FullName)) { double height = imageFromPath.Height; double width = imageFromPath.Width; double proportion = height / width; double newHeight = 1000; int newWidth = (int)(newHeight / proportion); if (newWidth > 5120) { newWidth = 3000; newHeight = (int)(newWidth * proportion); } Bitmap resizedImage = changeMainImageSize(image.FullName, (int)newHeight, newWidth); if (resizedImage != null) { resizedImage.Save(setPath + "/" + image.Name); } } } else if (fileName == "ImageMainImage") { mainImageName = image.Name; Bitmap resizedImage = changeMainImageSize(image.FullName, 300, 450); if (resizedImage != null) { resizedImage.Save(setPath + "/" + image.Name); } } } tempSetDirectory.Delete(true); string html = resultHtmlWithoutNotResultElements.Replace("<", "<").Replace(">", ">"); string resultTags = String.Empty; if (!String.IsNullOrEmpty(setTags)) { Char[] separators = { ',', ';', ' ' }; string[] tagsList = DeleteLastSemicolon(setTags.Trim()).Split(separators); for (int i = 0; i < tagsList.Length; i++) { if (tagsList[i] == "") { continue; } string tag = tagsList[i].Trim().ToLower(); resultTags += tag; resultTags += ";"; } } SetEntity set = new SetEntity { Name = setName.Trim(), Html = resultHtml.Replace("<", "<").Replace(">", ">"), HtmlWithoutNotResultElements = html, Tags = resultTags != string.Empty ? DeleteLastSemicolon(resultTags) : null, AddingTime = DateTime.Now, MainImageName = mainImageName }; Repository <SetEntity> repository = new Repository <SetEntity>(); repository.Create(set); ViewBag.Text = "Set is saved!"; ViewBag.Title = "Info"; DeleteTempFolders(); return(View("ShowInfo")); } catch (Exception ex) { return(ProcessException(ex)); } }