// // See if the method is a default constructor – constructor that does nothing // except call the constructor in its base class, usually inserted into your // assemblies by the compiler. // private bool IsDefaultCtor(Method method) { InstructionCollection ops = method.Instructions; if (ops.Count.Equals(4)) { // // Filter out default ctor generated by the compiler. // LocalCollection localList = ops[0].Value as LocalCollection; if (localList != null && localList.Count != 0) { return(false); } if (ops[1].OpCode != OpCode.Ldarg_0) { return(false); } if (ops[2].OpCode != OpCode.Call) { return(false); } InstanceInitializer init = ops[2].Value as InstanceInitializer; if (init == null) { return(false); } if (ops[3].OpCode != OpCode.Ret) { return(false); } return(true); } return(false); }
protected virtual void RemoveCore(TEntity entity) { try { LocalCollection.Remove(entity); } catch (Exception ex) { throw DbExceptionsConverter.Convert(ex); } }
public void ConfirmDependencyConstraintsOverride() { var mod1 = new ModNetworkContent("@test-mod-1", GameGuids.Arma3); var mod2 = new ModNetworkContent("@test-mod-2", GameGuids.Arma3); mod1.Dependencies.Add(new NetworkContentSpec(mod2, "1.0.0")); var collection = new LocalCollection(GameGuids.Arma3, "Test collection", new[] { new ContentSpec(mod1), new ContentSpec(mod2, "2.0.0") }); collection.GetRelatedContent().First().Constraint.ShouldEqual("2.0.0"); }
TEntity IRepository <TEntity, TPrimaryKey> .Reload(TEntity entity) { int index = this.LocalCollection.IndexOf(entity); UnitOfWork.Context.Detach(entity); TEntity newEntity = FindCore(GetPrimaryKeyCore(entity)); if (newEntity == null) { LocalCollection.RemoveAt(index); } else if (index >= 0) { LocalCollection[index] = newEntity; } return(newEntity); }
TEntity IRepository <TEntity, TPrimaryKey> .Find(TPrimaryKey primaryKey) { try { var entity = LocalCollection.SingleOrDefault(x => object.Equals(GetPrimaryKeyCore(x), primaryKey)); if (entity != null) { return(entity); } entity = FindCore(primaryKey); if (entity != null) { LocalCollection.Load(entity); } return(entity); } catch (DataServiceQueryException) { return(null); } }
/// <summary> /// Sets the denormalised data /// </summary> protected internal override void Denormalise() { // Reconstruct the collection of templates from the concrete types _templates = new LocalCollection <LocalTemplateModel, ITemplateModel>( this.Trainers.OfType <LocalTemplateModel>().Concat( this.Resources.OfType <LocalTemplateModel>().Concat( this.Rooms.OfType <LocalTemplateModel>() ) ) ); if (this.Id == null && string.IsNullOrWhiteSpace(this.ChildProductId)) { this.ChildProductId = this.MasterProductId; this.MainSession = 1; if (this.MasterProduct.SyProduct == 1) { this.Type = "Syllabus"; } if (this.StartDay == null) { this.StartDay = 0; } if (this.EndDay == null) { if (this.MasterProduct.CourseLen > 0) { if (Convert.ToDecimal(this.MasterProduct.CourseLen) == Math.Round(Convert.ToDecimal(this.MasterProduct.CourseLen))) { this.EndDay = Convert.ToDouble(this.MasterProduct.CourseLen) - 1; } else { this.EndDay = this.MasterProduct.CourseLen; } } else { this.EndDay = 0; } } } }
public void DeleteLocalVideo(string dir, string thumbdir) { dir = dir.Replace('*', '\\'); thumbdir = thumbdir.Replace('*', '\\'); try { string path = @"wwwroot" + '\\' + dir; System.IO.File.Delete(path); Logger.Info("Deleted local video at " + path); } catch (Exception e) { Logger.Info("Could not delete Video"); Logger.Error(e.Message); return; } try { string path = @"wwwroot" + '\\' + thumbdir; System.IO.File.Delete(path); Logger.Info("Deleted thumbnail at " + path); } catch (Exception e) { Logger.Info("Could not delete thumbnail"); Logger.Error(e.Message); return; } LocalCollection.CollectAllDownloadedVideos(); }
public override ProblemCollection Check(Member member) { Method method = member as Method; if (method == null) { return(null); } if (method.Instructions == null || method.Instructions.Count == 0) { return(null); } LocalCollection locals = method.Locals; //LocalList locals = method.Instructions[0].Value as LocalList; if (locals == null) { return(null); } foreach (var item in locals) { if (RuleUtilities.IsCompilerGenerated(item)) { continue; } string localVariableName = item.Name.Name; string camelLocalVariableName = localVariableName.ToCamelString(); if (!item.Name.Name.Equals(camelLocalVariableName)) { this.Problems.Add(new Problem(this.GetResolution(), item.SourceContext)); } } return(Problems); }
/// <summary> /// Updates the page configuration. /// </summary> public void Update(ArrayList customFields) { foreach (Dictionary <String, Object> customField in customFields) { // Get the custom field object LocalScreenCustomFieldModel fieldObject = null; if (customField.ContainsKey("Id")) { int Id = 0; string sId = customField["Id"].ConvertTo <String>().TrimOrNullify(); // TODO: can simplify this if Id is already an int? if (int.TryParse(sId, out Id)) { fieldObject = this.Provider.UserInterface.ScreenCustomField.FetchById(Id); } } if (customField.ContainsKey("DeleteMe") && customField["DeleteMe"].ToString() == "1") { if (fieldObject != null) { fieldObject.Delete(); } } else { if (fieldObject == null) { fieldObject = this.Provider.UserInterface.ScreenCustomField.Create(); } Type objType = fieldObject.GetType(); // Apply the properties foreach (string key in customField.Keys) { System.Reflection.PropertyInfo fieldInfo = objType.GetProperty(key); if (fieldInfo != null && fieldInfo.SetMethod != null && key != "Cftype" && key != "CustomFieldValues" && key != "CustomFieldListItems" ) { object currValue = fieldInfo.GetValue(fieldObject); if (currValue != null) { fieldInfo.SetValue(fieldObject, customField[key].ConvertTo(fieldInfo.PropertyType, fieldInfo.GetValue(fieldObject).ConvertTo(fieldInfo.PropertyType))); } else { fieldInfo.SetValue(fieldObject, customField[key].ConvertTo(fieldInfo.PropertyType)); } } } if (customField.ContainsKey("CustomFieldListItems")) { ArrayList listItems = customField["CustomFieldListItems"] as ArrayList; LocalCollection <LocalScreenCustomFieldListitemModel, IScreenCustomFieldListitemModel> listObjects = fieldObject.CustomFieldListItems; foreach (Dictionary <string, object> listItem in listItems) { LocalScreenCustomFieldListitemModel listObject; if (listItem.ContainsKey("Id") && !string.IsNullOrEmpty(listItem["Id"].ToString())) { listObject = listObjects.FirstOrDefault(i => i.Id == listItem["Id"].ConvertTo <int>()); if (listItem.ContainsKey("DeleteMe") && listItem["DeleteMe"].ToString() == "1") { listObject.Delete(); listObjects.Remove(listObject); } else { if (listItem.ContainsKey("IdValue")) { listObject.IdValue = listItem["IdValue"].ConvertTo <String>().TrimOrNullify(); } if (listItem.ContainsKey("Text")) { listObject.Text = listItem["Text"].ConvertTo <String>().TrimOrNullify(); } } } else { if (!(listItem.ContainsKey("DeleteMe") && listItem["DeleteMe"].ToString() == "1")) { listObject = this.Provider.UserInterface.ScreenCustomFieldListitem.Create(); if (listItem.ContainsKey("IdValue")) { listObject.IdValue = listItem["IdValue"].ConvertTo <String>().TrimOrNullify(); } if (listItem.ContainsKey("Text")) { listObject.Text = listItem["Text"].ConvertTo <String>().TrimOrNullify(); } listObjects.Add(listObject); } } } } // When creating a new record, ensure that the url and page are set if (!fieldObject.IsPersisted && fieldObject.IsModified) { fieldObject.Page = customField["Page"].ConvertTo <String>(); fieldObject.Url = customField["Url"].ConvertTo <String>(); } fieldObject.Save(); } } }
public async Task <ImportedCards> Import() { ProtoCollection collection; if (remoteCollectionFirst) { try { collection = await new GoogleSheetsCollection().Fetch(); } catch (Exception e) when(e is WebException || e is FormatException) { Debug.LogError("[CollectionImporter] Import from Google Sheets failed: " + e.Message); Debug.LogWarning("[CollectionImporter] Trying local collection..."); collection = LocalCollection.Fetch(); if (collection.cards.Count == 0) { Debug.LogWarning("[CollectionImporter] Import from local collection returned 0 cards"); } } } else { collection = LocalCollection.Fetch(); if (collection.cards.Count == 0) { Debug.LogWarning("[CollectionImporter] Import from local collection returned 0 cards, " + "trying Google Sheets..."); try { collection = await new GoogleSheetsCollection().Fetch(); } catch (Exception e) when(e is WebException || e is FormatException) { Debug.LogError("[CollectionImporter] Import from Google Sheets failed: " + e.Message); } } } Dictionary <int, Sprite> sprites = new Dictionary <int, Sprite>(); foreach (ProtoImage image in collection.images) { if (sprites.ContainsKey(image.id)) { Debug.LogWarning("[CollectionImporter] Duplicate id found in Images"); continue; } if (image.url == null) { Debug.LogWarning("[CollectionImporter] Image (id: " + image.id + ") has a null URL"); continue; } Debug.Log("[CollectionImporter] Fetching image from " + image.url + " ..."); HttpWebResponse imageResponse; try { HttpWebRequest imageRequest = WebRequest.CreateHttp(image.url); imageResponse = (HttpWebResponse)await imageRequest.GetResponseAsync(); } catch (WebException e) { Debug.LogError("[CollectionImporter] Request failed: " + e.Message); continue; } if (imageResponse.StatusCode != HttpStatusCode.OK) { Debug.LogWarning( "[CollectionImporter] " + image.url + ": " + (int)imageResponse.StatusCode + " " + imageResponse.StatusDescription); continue; } Stream imageStream; if ((imageStream = imageResponse.GetResponseStream()) == null) { Debug.LogWarning( "[CollectionImporter] Remote host returned no image in response (URL: " + image.url + ")"); continue; } byte[] imageData = Util.BytesFromStream(imageStream); Texture2D texture = new Texture2D(1, 1); if (!texture.LoadImage(imageData)) { Debug.LogWarning( "[CollectionImporter] Could not create sprite texture from image (URL: " + image.url + ")"); continue; } Sprite sprite = Sprite.Create( texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f)); sprites.Add(image.id, sprite); } Dictionary <int, Character> characters = new Dictionary <int, Character>(); foreach (ProtoCharacter protoCharacter in collection.characters) { if (characters.ContainsKey(protoCharacter.id)) { Debug.LogWarning("[CollectionImporter] Duplicate id found in Characters"); continue; } Character character = new Character(protoCharacter.name, defaultSprite); sprites.TryGetValue(protoCharacter.imageId, out character.sprite); characters.Add(protoCharacter.id, character); } Dictionary <int, Card> cards = new Dictionary <int, Card>(); foreach (ProtoCard protoCard in collection.cards) { if (cards.ContainsKey(protoCard.id)) { Debug.LogWarning("[CollectionImporter] Duplicate id found in Cards"); continue; } IFollowup leftActionFollowup = null; ProtoAction leftAction = protoCard.leftAction; if (leftAction.followup != null && leftAction.followup.Count > 0) { if (leftAction.followup.Count > 1) { Debug.LogWarning( "[CollectionImporter] Card (id: " + protoCard.id + ") left action has more than one Followup"); continue; } leftActionFollowup = leftAction.followup[0]; } if (leftAction.specialFollowup != null && leftAction.specialFollowup.Count > 0) { if (leftAction.specialFollowup.Count > 1) { Debug.LogWarning( "[CollectionImporter] Card (id: " + protoCard.id + ") left action has more than one SpecialFollowup"); continue; } if (leftActionFollowup != null) { Debug.LogWarning( "[CollectionImporter] Card (id: " + protoCard.id + ") left action has both types of followups"); continue; } leftActionFollowup = leftAction.specialFollowup[0]; } IFollowup rightActionFollowup = null; ProtoAction rightAction = protoCard.rightAction; if (rightAction.followup != null && rightAction.followup.Count > 0) { if (rightAction.followup.Count > 1) { Debug.LogWarning( "[CollectionImporter] Card (id: " + protoCard.id + ") right action has more than one Followup"); continue; } rightActionFollowup = rightAction.followup[0]; } if (rightAction.specialFollowup != null && rightAction.specialFollowup.Count > 0) { if (rightAction.specialFollowup.Count > 1) { Debug.LogWarning( "[CollectionImporter] Card (id: " + protoCard.id + ") right action has more than one SpecialFollowup"); continue; } if (rightActionFollowup != null) { Debug.LogWarning( "[CollectionImporter] Card (id: " + protoCard.id + ") right action has both types of followups"); continue; } rightActionFollowup = rightAction.specialFollowup[0]; } ActionOutcome leftActionOutcome = new ActionOutcome(leftAction.statsModification, leftActionFollowup); ActionOutcome rightActionOutcome = new ActionOutcome(rightAction.statsModification, rightActionFollowup); List <ICardPrerequisite> prerequisites = new List <ICardPrerequisite>(); bool failed = false; foreach (ProtoCardPrerequisite prereq in protoCard.cardPrerequisites) { CardPrerequisite cardPrerequisite = new CardPrerequisite(prereq.id); try { foreach (string s in prereq.status) { cardPrerequisite.Status |= CardStatusFor(s); } } catch (ArgumentException e) { Debug.LogWarning("[CollectionImporter] Card (id: " + protoCard.id + "): " + e.Message); failed = true; break; } prerequisites.Add(cardPrerequisite); } if (failed) { continue; } foreach (ProtoSpecialCardPrerequisite prereq in protoCard.specialCardPrerequisites) { SpecialCardPrerequisite cardPrerequisite = new SpecialCardPrerequisite(prereq.id); try { foreach (string s in prereq.status) { cardPrerequisite.Status |= CardStatusFor(s); } } catch (ArgumentException e) { Debug.LogWarning("[CollectionImporter] Card (id: " + protoCard.id + "): " + e.Message); failed = true; break; } prerequisites.Add(cardPrerequisite); } if (failed) { continue; } Card card = new Card( protoCard.cardText, leftAction.text, rightAction.text, null, leftActionOutcome, rightActionOutcome, prerequisites); characters.TryGetValue(protoCard.characterId, out card.character); cards.Add(protoCard.id, card); } Dictionary <string, SpecialCard> specialCards = new Dictionary <string, SpecialCard>(); foreach (ProtoSpecialCard protoSpecialCard in collection.specialCards) { if (protoSpecialCard.id == null) { Debug.LogWarning("[CollectionImporter] Null id found in SpecialCards"); continue; } if (specialCards.ContainsKey(protoSpecialCard.id)) { Debug.LogWarning("[CollectionImporter] Duplicate id found in SpecialCards"); continue; } IFollowup leftActionFollowup = null; ProtoSpecialAction leftAction = protoSpecialCard.leftAction; if (leftAction.followup != null && leftAction.followup.Count > 0) { if (leftAction.followup.Count > 1) { Debug.LogWarning( "[CollectionImporter] SpecialCard (id: " + protoSpecialCard.id + ") left action has more than one Followup"); continue; } leftActionFollowup = leftAction.followup[0]; } if (leftAction.specialFollowup != null && leftAction.specialFollowup.Count > 0) { if (leftAction.specialFollowup.Count > 1) { Debug.LogWarning( "[CollectionImporter] SpecialCard (id: " + protoSpecialCard.id + ") left action has more than one SpecialFollowup"); continue; } if (leftActionFollowup != null) { Debug.LogWarning( "[CollectionImporter] SpecialCard (id: " + protoSpecialCard.id + ") left action has both types of followups"); continue; } leftActionFollowup = leftAction.specialFollowup[0]; } IFollowup rightActionFollowup = null; ProtoSpecialAction rightAction = protoSpecialCard.rightAction; if (rightAction.followup != null && rightAction.followup.Count > 0) { if (rightAction.followup.Count > 1) { Debug.LogWarning( "[CollectionImporter] SpecialCard (id: " + protoSpecialCard.id + ") right action has more than one Followup"); continue; } rightActionFollowup = rightAction.followup[0]; } if (rightAction.specialFollowup != null && rightAction.specialFollowup.Count > 0) { if (rightAction.specialFollowup.Count > 1) { Debug.LogWarning( "[CollectionImporter] SpecialCard (id: " + protoSpecialCard.id + ") right action has more than one SpecialFollowup"); continue; } if (rightActionFollowup != null) { Debug.LogWarning( "[CollectionImporter] SpecialCard (id: " + protoSpecialCard.id + ") right action has both types of followups"); continue; } rightActionFollowup = rightAction.specialFollowup[0]; } IActionOutcome leftActionOutcome = null; IActionOutcome rightActionOutcome = null; if (protoSpecialCard.id == "gameover_coal" || protoSpecialCard.id == "gameover_food" || protoSpecialCard.id == "gameover_health" || protoSpecialCard.id == "gameover_hope") { leftActionOutcome = new GameOverOutcome(); rightActionOutcome = new GameOverOutcome(); } SpecialCard specialCard = new SpecialCard( protoSpecialCard.cardText, leftAction.text, rightAction.text, null, leftActionOutcome, rightActionOutcome); characters.TryGetValue(protoSpecialCard.characterId, out specialCard.character); specialCards.Add(protoSpecialCard.id, specialCard); } return(new ImportedCards(cards, specialCards)); }
protected virtual void AddCore(TEntity entity) { LocalCollection.Add(entity); }