public override void Initialize() { base.Initialize(); Settings = new PersistentObject<GrangerSettings>(new GrangerSettings()); Settings.SetFilePathAndLoad(Path.Combine(base.ModuleDataDir, "settings.xml")); //init database DBSchema.SetConnectionString(Path.Combine(this.ModuleDataDir, "grangerDB.s3db")); SQLiteHelper.CreateTableIfNotExists(DBSchema.HorsesSchema, DBSchema.HorsesTableName, DBSchema.ConnectionString); SQLiteHelper.ValidateTable(DBSchema.HorsesSchema, DBSchema.HorsesTableName, DBSchema.ConnectionString); SQLiteHelper.CreateTableIfNotExists(DBSchema.TraitValuesSchema, DBSchema.TraitValuesTableName, DBSchema.ConnectionString); SQLiteHelper.ValidateTable(DBSchema.TraitValuesSchema, DBSchema.TraitValuesTableName, DBSchema.ConnectionString); SQLiteHelper.CreateTableIfNotExists(DBSchema.HerdsSchema, DBSchema.HerdsTableName, DBSchema.ConnectionString); SQLiteHelper.ValidateTable(DBSchema.HerdsSchema, DBSchema.HerdsTableName, DBSchema.ConnectionString); Context = new GrangerContext(new SQLiteConnection(DBSchema.ConnectionString)); GrangerUI = new FormGrangerMain(this, Settings, Context); LogFeedMan = new LogFeedManager(this, Context); LogFeedMan.UpdatePlayers(Settings.Value.CaptureForPlayers); GrangerUI.Granger_PlayerListChanged += GrangerUI_Granger_PlayerListChanged; }
//float? AHSkill = null; public HorseProcessor(ModuleGranger parentModule, GrangerContext context, PlayerManager playerMan, GrangerDebugLogger debugLogger) { _grangerDebug = debugLogger; _parentModule = parentModule; _context = context; _playerMan = playerMan; }
public FormHorseViewEdit(FormGrangerMain mainForm, Horse horse, GrangerContext context, HorseViewEditOpType optype, string herdID) { this.MainForm = mainForm; this.horse = horse; this.Context = context; this.HerdID = herdID; InitializeComponent(); disableAllFields(); List<string> list = new List<string>(); list.AddRange(Context.Horses.Select(x => x.Name)); list.AddRange(Context.Horses.Select(x => x.MotherName)); list.AddRange(Context.Horses.Select(x => x.FatherName)); string[] allHorseNamesInDatabase = list.Distinct().Where(x => x != null).ToArray(); comboBoxFather.Items.AddRange(allHorseNamesInDatabase); comboBoxMother.Items.AddRange(allHorseNamesInDatabase); comboBoxColor.Items.AddRange(HorseColor.GetColorsEnumStrArray()); comboBoxColor.Text = HorseColor.GetDefaultColorStr(); comboBoxAge.Items.AddRange(HorseAge.GetColorsEnumStrArray()); comboBoxAge.Text = HorseAge.GetDefaultAgeStr(); this.OpMode = optype; }
public FormGrangerMain(ModuleGranger moduleGranger, PersistentObject<GrangerSettings> settings, GrangerContext context) { this.ParentModule = moduleGranger; this.Settings = settings; this.Context = context; InitializeComponent(); RebuildValuePresets(); RefreshValuator(); RebuildAdvisors(); RefreshAdvisor(); ucGrangerHerdList1.Init(this, context); ucGrangerHorseList1.Init(this, context); ucGrangerTraitView1.Init(this, context); Context.OnTraitValuesModified += Context_OnTraitValuesModified; this.Size = Settings.Value.MainWindowSize; this.checkBoxCapturingEnabled.Checked = Settings.Value.LogCaptureEnabled; this.UpdateViewsVisibility(); this.Update_textBoxCaptureForPlayers(); _WindowInitCompleted = true; }
public BreedingAdvisor(FormGrangerMain mainForm, string advisorID, GrangerContext Context) { this.MainForm = mainForm; this.AdvisorID = advisorID; this.Context = Context; IsDisabled = false; if (advisorID == DISABLED_id) { BreedEvalutator = new DisabledBreedingEvaluator(); IsDisabled = true; } if (advisorID == DEFAULT_id) { BreedEvalutator = new DefaultBreedingEvaluator(); } if (BreedEvalutator != null) { object options = mainForm.Settings.Value.GetBreedingEvalOptions(BreedEvalutator.GetType()); if (options != null) BreedEvalutator.SetOptions(options); } }
public HorseUpdatesManager(ModuleGranger parentModule, GrangerContext context, PlayerManager playerManager) { _parentModule = parentModule; _context = context; _playerMan = playerManager; _processor = new HorseProcessor(_parentModule, _context, _playerMan, _grangerDebug); }
public FormHerdName(GrangerContext context, Form mainForm, string renamingHerd = null) { MainForm = mainForm; RenamingHerd = renamingHerd; Context = context; InitializeComponent(); allHerdNames = context.Herds.Select(x => x.HerdID).ToArray(); }
internal void Init(FormGrangerMain formGrangerMain, GrangerContext context) { MainForm = formGrangerMain; _debug_MainFormAssigned = true; Context = context; if (MainForm.Settings.Value.TraitViewState != null) objectListView1.RestoreState(MainForm.Settings.Value.TraitViewState); Manager = new TraitViewManager(MainForm, Context, objectListView1); }
public FormHerdMerge(GrangerContext context, FormGrangerMain mainForm, string sourceHerdName) { this.Context = context; this.MainForm = mainForm; this.SourceHerdName = sourceHerdName; InitializeComponent(); textBoxFromHerd.Text = SourceHerdName; comboBoxToHerd.Items.AddRange(Context.Herds.Where(x => x.HerdID != sourceHerdName).ToArray()); listBoxFromHerd.Items.AddRange(Context.Horses.Where(x => x.Herd == SourceHerdName).ToArray()); }
public FormChooseHerd(FormGrangerMain mainForm, GrangerContext Context) { this.MainForm = mainForm; this.Context = Context; InitializeComponent(); var herds = Context.Herds.ToArray(); listBox1.Items.AddRange(herds); }
static public int GenerateNewTraitValueID(GrangerContext context) { try { return context.TraitValues.Max(x => x.ID) + 1; } catch (InvalidOperationException) { return 1; } }
/// <summary> /// generates new valuator attempting to use custom values from database, /// exception when no values found /// </summary> /// <param name="valueMapID"></param> public TraitValuator(FormGrangerMain mainForm, string valueMapID, GrangerContext context) { MainForm = mainForm; Context = context; ValueMapID = valueMapID; if (valueMapID == DEFAULT_id) _usingDefault = true; else { RebuildValues(); context.OnTraitValuesModified += new EventHandler<EventArgs>(context_OnTraitValuesModified) .MakeWeak(x => context.OnTraitValuesModified -= x); } }
public FormEditValuePresetsNewNameDialog(FormEditValuePresets formEditValuePresets, GrangerContext context) { this.FormEditValuePresets = formEditValuePresets; this.Context = context; InitializeComponent(); var uniqueValMapIDs = Context.TraitValues.AsEnumerable().Select(x => x.ValueMapID).Distinct(); foreach (var mapID in uniqueValMapIDs) { TakenValueMapIDs.Add(mapID); } }
public PlayerManager(ModuleGranger parentModule, GrangerContext context, string playerName) { this._parentModule = parentModule; this._context = context; this.PlayerName = playerName; //SGManager = new ManualServerGroupManager(PlayerName); HorseUpdateManager = new HorseUpdatesManager(_parentModule, _context, this); InitSkill(); WurmLogs.SubscribeToLogFeed(PlayerName, new EventHandler<NewLogEntriesEventArgs>(OnNewLogEvents)); }
public void Init(FormGrangerMain mainForm, GrangerContext context) { MainForm = mainForm; Context = context; objectListView1.BooleanCheckStateGetter = new BrightIdeasSoftware.BooleanCheckStateGetterDelegate(x => { HerdEntity entity = (HerdEntity)x; return entity.Selected; }); objectListView1.BooleanCheckStatePutter = new BrightIdeasSoftware.BooleanCheckStatePutterDelegate((x, y) => { HerdEntity entity = (HerdEntity)x; Context.UpdateHerdSelectedState(entity.HerdID, y); return entity.Selected; }); Context.OnHerdsModified += RefreshHerdList; RefreshHerdList(this, new EventArgs()); }
public TraitViewManager(FormGrangerMain mainForm, GrangerContext context, ObjectListView listview) { MainForm = mainForm; Context = context; OLV = listview; OLV.FormatRow += OLV_FormatRow; AllTraits = HorseTrait.GetAllTraitEnums().Select(x => new HorseTrait(x)).ToArray(); BuildClearTraitView(); listview.SetObjects(Items); Decide(); MainForm.Granger_SelectedSingleHorseChanged += MainForm_Granger_SelectedHorsesChanged; MainForm.Granger_ValuatorChanged += MainForm_Granger_ValuatorChanged; MainForm.Granger_TraitViewDisplayModeChanged += MainForm_Granger_TraitViewDisplayModeChanged; Context.OnHerdsModified += Context_OnHerdsModified; Context.OnHorsesModified += Context_OnHorsesModified; Context.OnTraitValuesModified += Context_OnTraitValuesModified; }
public TraitValueMap(GrangerContext context, string traitValueMapID) { Context = context; TraitValueMapID = traitValueMapID; ValueMap = HorseTrait.GetAllDefaultValues(); if (traitValueMapID == TraitValuator.DEFAULT_id) { ReadOnly = true; } else { ReadOnly = false; var entities = Context.TraitValues.Where(x => x.ValueMapID == traitValueMapID); foreach (var entity in entities) { ValueMap[entity.Trait.Trait] = entity.Value; } } }
public LogFeedManager(ModuleGranger parentModule, GrangerContext context) { _parentModule = parentModule; _context = context; }
public void ImportHerd(GrangerContext context, string newHerdName, string xmlFilePath) { if (newHerdName == null || newHerdName.Trim() == string.Empty) { throw new GrangerException("new herd name cannot be empty"); } // check if this herd already exists in database if (context.Herds.Any(x => x.HerdID == newHerdName)) { throw new GrangerException(string.Format("there is already a herd with named {0} in database", newHerdName)); } XDocument doc = XDocument.Load(xmlFilePath); var horseEntities = new List<HorseEntity>(); var elements = doc.Root.Elements("Horse"); foreach (var x in elements) { var entity = new HorseEntity(); entity.Herd = newHerdName; entity.Name = x.Element("Name").Value; // verify this name is not present in current list if (horseEntities.Any(y => y.Name.Equals(entity.Name, StringComparison.InvariantCultureIgnoreCase))) { throw new GrangerException(string.Format("Horse named {0} was already added from this XML file. Review the file for any errors.", entity.Name)); } entity.FatherName = x.Element("Father").Value; entity.MotherName = x.Element("Mother").Value; entity.Traits = GetTraitsFromXML(x.Element("Traits")); var notInMood = x.Element("NotInMoodUntil").Value; if (string.IsNullOrEmpty(notInMood)) { entity.NotInMood = null; } else { entity.NotInMood = DateTime.Parse(notInMood, CultureInfo.InvariantCulture); } var pregnantUntil = x.Element("PregnantUntil").Value; if (string.IsNullOrEmpty(pregnantUntil)) { entity.PregnantUntil = null; } else { entity.PregnantUntil = DateTime.Parse(pregnantUntil, CultureInfo.InvariantCulture); } var groomedOn = x.Element("GroomedOn").Value; if (string.IsNullOrEmpty(groomedOn)) entity.GroomedOn = null; else entity.GroomedOn = DateTime.Parse(groomedOn, CultureInfo.InvariantCulture); var gender = x.Element("Gender").Value; if (string.IsNullOrEmpty(gender)) entity.IsMale = null; else entity.IsMale = gender.Equals("male", StringComparison.InvariantCultureIgnoreCase); entity.TakenCareOfBy = x.Element("CaredBy").Value; var xInspect = x.Element("InspectSkill"); if (string.IsNullOrEmpty(xInspect.Value)) entity.TraitsInspectedAtSkill = null; else entity.TraitsInspectedAtSkill = float.Parse(xInspect.Value, CultureInfo.InvariantCulture); var xInspectAttr = xInspect.Attribute("IsEpic"); if (string.IsNullOrEmpty(xInspectAttr.Value)) entity.EpicCurve = null; else entity.EpicCurve = bool.Parse(xInspectAttr.Value); entity.Age = HorseAge.CreateAgeFromEnumString(x.Element("Age").Value); entity.Color = HorseColor.CreateColorFromEnumString(x.Element("Color").Value); entity.Comments = x.Element("Comments").Value; entity.SpecialTagsRaw = x.Element("Tags").Value; entity.BrandedFor = x.Element("BrandedFor").Value; horseEntities.Add(entity); } context.InsertHerd(newHerdName); foreach (var horseEntity in horseEntities) { horseEntity.ID = HorseEntity.GenerateNewHorseID(context); context.InsertHorse(horseEntity); } }
public XDocument CreateXML(GrangerContext context, string herdName) { if (herdName == null) throw new GrangerException("No herd specified"); var horses = context.Horses.Where(x => x.Herd == herdName).ToArray(); if (horses.Length == 0) { throw new GrangerException(string.Format("No horses found in {0} herd or herd did not exist", herdName)); } XElement root = new XElement("Herd", new XAttribute("OriginalHerdName", herdName)); foreach (HorseEntity horseEntity in horses) { var horse = new XElement("Horse", new XElement("Name", horseEntity.Name), new XElement("Father", horseEntity.FatherName), new XElement("Mother", horseEntity.MotherName), new XElement("Traits", GetTraitListXML(horseEntity)), new XElement("NotInMoodUntil", horseEntity.NotInMood.HasValue ? horseEntity.NotInMood.Value.ToString(CultureInfo.InvariantCulture) : string.Empty), new XElement("PregnantUntil", horseEntity.PregnantUntil.HasValue ? horseEntity.PregnantUntil.Value.ToString( CultureInfo.InvariantCulture) : string.Empty), new XElement("GroomedOn", horseEntity.GroomedOn.HasValue ? horseEntity.GroomedOn.Value.ToString(CultureInfo.InvariantCulture) : string.Empty), new XElement("Gender", GetGender(horseEntity)), new XElement("CaredBy", horseEntity.TakenCareOfBy), new XElement("InspectSkill", horseEntity.TraitsInspectedAtSkill, new XAttribute("IsEpic", horseEntity.EpicCurve.HasValue ? horseEntity.EpicCurve.ToString() : bool.FalseString)), new XElement("Age", horseEntity.Age), new XElement("Color", horseEntity.Color), new XElement("Comments", horseEntity.Comments), new XElement("Tags", horseEntity.SpecialTagsRaw), new XElement("BrandedFor", horseEntity.BrandedFor)); root.Add(horse); } return new XDocument( new XDeclaration("1.0", "utf-8", "yes"), root); }
//other data? public Horse(FormGrangerMain mainForm, HorseEntity entity, GrangerContext context) { MainForm = mainForm; Entity = entity; Context = context; }
public FormGrangerImportExport(GrangerContext context) { _context = context; InitializeComponent(); comboBoxExportedHerd.Items.AddRange(context.Herds.Select(x => x.ToString()).ToArray()); }
public FormEditValuePresets(GrangerContext Context) { this.Context = Context; InitializeComponent(); RebuildAllPresetsList(); }
public void Init(FormGrangerMain mainForm, GrangerContext context) { MainForm = mainForm; _debug_MainFormAssigned = true; if (mainForm.Settings.Value.HorseListState != null) { this.objectListView1.RestoreState(mainForm.Settings.Value.HorseListState); } Context = context; olvColumnPairedWith.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; Horse mate = horse.GetMate(); if (mate != null) { string[] output = new string[2] { horse.ToString(), mate.ToString() }; return string.Join(" + ", output.OrderBy(y => y)); } else return "Free"; }); //olvColumnValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => // { // Horse horse = (Horse)x; // return horse.ValueAspect; // }); olvColumnValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; if (horse.Value >= 0) return "Positive"; else return "Negative"; }); olvColumnValue.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { return x.ToString(); }); //olvColumnBreedValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => // { // Horse horse = (Horse)x; // var result = horse.BreedValueAspect; // return result != null ? result.ToString() : "Not comparing"; // }); olvColumnBreedValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; double? val = horse.BreedValueAspect; if (val == null) return "Being Compared / Not comparing"; else return "Candidates"; }); olvColumnBreedValue.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { if (x is double) { double val = (double)x; if (val == double.NegativeInfinity) return "-inf"; else return val.ToString("F0"); } else if (x == null) return string.Empty; else return x.ToString(); }); olvColumnTraits.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; var traits = horse.Traits; HorseTrait[] positives = HorseTrait.GetGoodTraits(traits, MainForm.CurrentValuator); HorseTrait[] negatives = HorseTrait.GetBadTraits(traits, MainForm.CurrentValuator); return string.Format("Good: {0}, Neutral: {1}, Bad: {2}", positives.Length, traits.Length - positives.Length - negatives.Length, negatives.Length); }); olvColumnTraitsInspectedAt.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; var traitinfo = horse.TraitsInspectedAtSkillAspect; if (traitinfo.Skill > HorseTrait.GetFullTraitVisibilityCap(traitinfo.EpicCurve)) return "Fully known"; else return "Known partially"; }); olvColumnAge.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { HorseAge age = ((Horse)x).Age; return (int)age.EnumVal; }); olvColumnAge.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x => { int result = (int)x; return (new HorseAge(result.ToString()).ToString()); }); ////////////// // GroupKeyGetter needs to be sortable to position them correctly, // GroupKeyToTitleConverter converts that key into something more meaningful to display // AspectToStringConverter converts aspect into display string in special way olvColumnNotInMoodFor.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; //DateTime notInMoodUntil = horse.NotInMoodUntil; TimeSpan tms = horse.NotInMoodForAspect;// notInMoodUntil - DateTime.Now; if (tms.TotalDays >= 0) { return 0; // "Not in mood"; } else { return 1; // "In mood"; } }); olvColumnNotInMoodFor.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { if (x is TimeSpan) { TimeSpan ts = (TimeSpan)x; if (ts.TotalDays >= 0) return TimeHelper.FormatTimeSpanForDisplay(ts); else return string.Empty; } else return string.Empty; }); olvColumnNotInMoodFor.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x => { int result = (int)x; switch (result) { case 0: return "Not in mood"; case 1: return "In mood"; default: return ""; } }); olvColumnGroomedAgo.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; //DateTime groomedon = horse.GroomedOn; TimeSpan tms = horse.GroomedAgoAspect; // DateTime.Now - groomedon; if (tms.TotalHours <= 1) { return "Less than 1 hour ago"; } else { return "More than 1 hour ago"; } }); olvColumnGroomedAgo.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { if (x is TimeSpan) { TimeSpan ts = (TimeSpan)x; if (ts < MainForm.Settings.Value.ShowGroomingTime) return TimeHelper.FormatTimeSpanForDisplay(ts); else return string.Empty; } else return string.Empty; }); olvColumnGroomedAgo.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x => { return x.ToString(); }); olvColumnPregnantFor.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; DateTime pregnantUntil = horse.PregnantUntil; TimeSpan tms = pregnantUntil - DateTime.Now; if (tms.Ticks <= 0) { if (tms.TotalDays >= -1) return 2; // "Gave birth within last 24h"; else if (tms.TotalDays >= -7) return 3; // "Gave birth in last 7 days"; else return 4; // "Not pregnant"; } else if (tms.TotalDays <= 1) { return 0; // "Will give birth within 24h"; } else { return 1; // "Will give birth in more than 24h"; } }); olvColumnPregnantFor.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { if (x is TimeSpan) { TimeSpan ts = (TimeSpan)x; if (ts.Ticks >= 0) return TimeHelper.FormatTimeSpanForDisplay(ts); else return string.Empty; } else return string.Empty; }); olvColumnPregnantFor.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x => { int group = (int)x; switch (group) { case 0: return "Will give birth within 24h"; case 1: return "Will give birth in more than 24h"; case 2: return "Gave birth within last 24h"; case 3: return "Gave birth within last 7 days"; case 4: return "Not pregnant"; default: return ""; } }); olvColumnBirthDate.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; return horse.BirthDate.Date; }); olvColumnBirthDate.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { if (x is DateTime) { DateTime dt = (DateTime)x; if (dt < _treshholdDtValueForBirthDate) { return string.Empty; } else { return dt.ToString(CultureInfo.CurrentCulture); } } else return string.Empty; }); olvColumnBirthDate.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x => { DateTime dt = (DateTime) x; if (dt < _treshholdDtValueForBirthDate) { return "No birth date available"; } else { return dt.ToShortDateString(); } }); olvColumnExactAge.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x => { Horse horse = (Horse)x; var val = (int)horse.ExactAgeAspect.TotalDays; if (val > _treshholdDaysValueForExactAge) return int.MaxValue; else return val; }); olvColumnExactAge.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x => { if (x is TimeSpan) { TimeSpan ts = (TimeSpan)x; if (ts > _treshholdTsValueForExactAge) { return string.Empty; } else { return TimeHelper.FormatTimeSpanForDisplay(ts); } } else return string.Empty; }); olvColumnExactAge.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x => { int gkey = (int)x; if (gkey > _treshholdDaysValueForExactAge) { return "No birth date available"; } else { return string.Format("{0} real days", gkey); } }); Context.OnHerdsModified += Context_OnHerdsModified; Context.OnHorsesModified += Context_OnHorsesModified; MainForm.Granger_UserViewChanged += MainForm_UserViewChanged; MainForm.Granger_AdvisorChanged += MainForm_Granger_AdvisorChanged; MainForm.Granger_ValuatorChanged += MainForm_Granger_ValuatorChanged; UpdateCurrentHorsesData(); UpdateDataForView(); timer1.Enabled = true; }