public CharacterExtended(Character character, SINner mySINnerLoading = null, CharacterCache myCharacterCache = null, bool blnDoSave = true) : this(character, myCharacterCache, false) { if (mySINnerLoading == null) { return; } SINner backup = MySINnerFile; MySINnerFile = mySINnerLoading; if (MySINnerFile?.SiNnerMetaData == null) { return; } if (MySINnerFile.SiNnerMetaData.Id == Guid.Empty) { MySINnerFile.SiNnerMetaData.Id = backup.SiNnerMetaData.Id; } if (MySINnerFile.SiNnerMetaData.Tags?.Count < backup?.SiNnerMetaData?.Tags?.Count) { MySINnerFile.SiNnerMetaData.Tags = new List <Tag>(backup.SiNnerMetaData.Tags); } if (!blnDoSave || MySINnerFile.Id == null) { return; } if (MySINnerFile.Id == null) { MySINnerFile.Id = Guid.NewGuid(); } MySINnerIds.AddOrUpdate(MyCharacter.FileName, MySINnerFile.Id.Value, (x, y) => MySINnerFile.Id.Value); SaveSINnerIds(); //Save it! }
public CharacterExtended(Character character, CharacterCache myCharacterCache = null, bool blnDoSave = true) { MyCharacter = character ?? throw new ArgumentNullException(nameof(character)); MyCharacterCache = myCharacterCache ?? new CharacterCache(MyCharacter.FileName); MySINnerFile = new SINner { Language = GlobalSettings.Language, SiNnerMetaData = new SINnerMetaData { Id = Guid.NewGuid(), Tags = new List <Tag>(), Visibility = new SINnerVisibility { IsGroupVisible = true, IsPublic = true } } }; MySINnerFile.SiNnerMetaData.Visibility = Utils.DefaultSINnerVisibility; if (MySINnerFile.SiNnerMetaData.Visibility != null && MySINnerFile.SiNnerMetaData.Visibility.Id == null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } MySINnerFile.LastChange = MyCharacter.FileLastWriteTime; MySINnerFile.Id = MySINnerIds.TryGetValue(MyCharacter.FileName, out Guid singuid) ? singuid : Guid.NewGuid(); if (!blnDoSave) { return; } MySINnerIds.AddOrUpdate(MyCharacter.FileName, MySINnerFile.Id.Value, (x, y) => MySINnerFile.Id.Value); SaveSINnerIds(); //Save it! }
public CharacterExtended(Character character, string fileElement = null) { MyCharacter = character; MySINnerFile = new SINner(); if (string.IsNullOrEmpty(fileElement)) { MySINnerFile.SiNnerMetaData = new SINnerMetaData { Id = Guid.NewGuid(), Tags = new List <Tag>(), Visibility = new SINnerVisibility() }; } else { try { MySINnerFile.SiNnerMetaData = JsonConvert.DeserializeObject <SINnerMetaData>(fileElement); } catch (Exception e) { System.Diagnostics.Trace.TraceWarning(e.ToString()); } } if (MySINnerFile.SiNnerMetaData.Visibility != null) { if (MySINnerFile.SiNnerMetaData.Visibility.Id == null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } return; } if (!string.IsNullOrEmpty(Properties.Settings.Default.SINnerVisibility)) { MySINnerFile.SiNnerMetaData.Visibility = JsonConvert.DeserializeObject <SINnerVisibility>(Properties.Settings.Default.SINnerVisibility); } if (MySINnerFile.SiNnerMetaData.Visibility?.Id == null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } var cache = new frmCharacterRoster.CharacterCache(character.FileName); this.MySINnerFile.LastChange = MyCharacter.FileLastWriteTime; if (MySINnerIds.TryGetValue(MyCharacter.Alias, out var singuid)) { MySINnerFile.Id = singuid; } else { MySINnerFile.Id = Guid.NewGuid(); MySINnerIds.Add(MyCharacter.Alias, MySINnerFile.Id.Value); MySINnerIds = MySINnerIds; //Save it! } this.MySINnerFile.JsonSummary = JsonConvert.SerializeObject(cache); }
public CharacterExtended(Character character, string fileElement = null, CharacterCache myCharacterCache = null) { MyCharacter = character ?? throw new ArgumentNullException(nameof(character)); MyCharacterCache = myCharacterCache ?? new CharacterCache(MyCharacter.FileName); if (!string.IsNullOrEmpty(fileElement)) { try { MySINnerFile = JsonConvert.DeserializeObject <SINner>(fileElement); } catch (Exception e) { Log.Error(e); } } if (MySINnerFile == null) { MySINnerFile = new SINner { Language = GlobalOptions.Language }; //MySINnerFile.MyExtendedAttributes = new SINnerExtended(MySINnerFile); } if (MySINnerFile.SiNnerMetaData == null) { MySINnerFile.SiNnerMetaData = new SINnerMetaData { Id = Guid.NewGuid(), Tags = new List <Tag>(), Visibility = new SINnerVisibility { IsGroupVisible = true, IsPublic = true } }; } if (!string.IsNullOrEmpty(Settings.Default.SINnerVisibility)) { MySINnerFile.SiNnerMetaData.Visibility = JsonConvert.DeserializeObject <SINnerVisibility>(Settings.Default.SINnerVisibility); } if (MySINnerFile.SiNnerMetaData.Visibility?.Id == null) { if (MySINnerFile.SiNnerMetaData.Visibility != null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } } MySINnerFile.LastChange = MyCharacter.FileLastWriteTime; if (MySINnerIds.TryGetValue(MyCharacter.FileName, out var singuid)) { MySINnerFile.Id = singuid; } else { MySINnerFile.Id = Guid.NewGuid(); MySINnerIds.Add(MyCharacter.FileName, MySINnerFile.Id.Value); MySINnerIds = MySINnerIds; //Save it! } }
public CharacterExtended(Character character, string fileElement = null) { MyCharacter = character; if (PluginHandler.MyCharExtendedDic.ContainsKey(character.FileName)) { throw new ArgumentException( "CharacterExtended already exists for this char - dont create a new instantce!", nameof(character)); } PluginHandler.MyCharExtendedDic.Add(character.FileName, this); _MySINnerFile = new SINner { MyExtendedAttributes = new SINnerExtended(), SiNnerMetaData = new SINnerMetaData(), Language = GlobalOptions.Language }; if (string.IsNullOrEmpty(fileElement)) { MySINnerFile.SiNnerMetaData = new SINnerMetaData { Id = Guid.NewGuid(), Tags = new List <Tag>(), Visibility = new SINnerVisibility() }; } else { try { MySINnerFile.SiNnerMetaData = JsonConvert.DeserializeObject <SINnerMetaData>(fileElement); } catch (Exception e) { System.Diagnostics.Trace.TraceWarning(e.ToString()); } } if (MySINnerFile.SiNnerMetaData.Visibility != null) { if (MySINnerFile.SiNnerMetaData.Visibility.Id == null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } } if (!string.IsNullOrEmpty(Properties.Settings.Default.SINnerVisibility)) { MySINnerFile.SiNnerMetaData.Visibility = JsonConvert.DeserializeObject <SINnerVisibility>(Properties.Settings.Default.SINnerVisibility); } if (MySINnerFile.SiNnerMetaData.Visibility?.Id == null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } var cache = new frmCharacterRoster.CharacterCache(character.FileName); this.MySINnerFile.LastChange = MyCharacter.FileLastWriteTime; if (MySINnerIds.TryGetValue(MyCharacter.Alias, out var singuid)) { MySINnerFile.Id = singuid; } else { MySINnerFile.Id = Guid.NewGuid(); MySINnerIds.Add(MyCharacter.Alias, MySINnerFile.Id.Value); MySINnerIds = MySINnerIds; //Save it! } this.MySINnerFile.MyExtendedAttributes.JsonSummary = JsonConvert.SerializeObject(cache); }
public CharacterExtended(Character character, string fileElement = null) { MyCharacter = character; if (!string.IsNullOrEmpty(fileElement)) { try { _MySINnerFile = JsonConvert.DeserializeObject <SINner>(fileElement); } catch (Exception e) { Log.Error(e); } } if (_MySINnerFile == null) { _MySINnerFile = new SINner { Language = GlobalOptions.Language }; //_MySINnerFile.MyExtendedAttributes = new SINnerExtended(_MySINnerFile); } if (MySINnerFile.SiNnerMetaData == null) { _MySINnerFile.SiNnerMetaData = new SINnerMetaData { Id = Guid.NewGuid(), Tags = new List <Tag>(), Visibility = new SINners.Models.SINnerVisibility() { IsGroupVisible = true, IsPublic = true } }; } if (MySINnerFile.SiNnerMetaData.Visibility != null) { if (MySINnerFile.SiNnerMetaData.Visibility.Id == null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } } if (!string.IsNullOrEmpty(Properties.Settings.Default.SINnerVisibility)) { MySINnerFile.SiNnerMetaData.Visibility = JsonConvert.DeserializeObject <SINners.Models.SINnerVisibility>(Properties.Settings.Default.SINnerVisibility); } if (MySINnerFile.SiNnerMetaData.Visibility?.Id == null) { if (MySINnerFile?.SiNnerMetaData?.Visibility != null) { MySINnerFile.SiNnerMetaData.Visibility.Id = Guid.NewGuid(); } } var cache = new frmCharacterRoster.CharacterCache(character.FileName); this.MySINnerFile.LastChange = MyCharacter.FileLastWriteTime; if (MySINnerIds.TryGetValue(MyCharacter.FileName, out var singuid)) { MySINnerFile.Id = singuid; } else { MySINnerFile.Id = Guid.NewGuid(); MySINnerIds.Add(MyCharacter.FileName, MySINnerFile.Id.Value); MySINnerIds = MySINnerIds; //Save it! } }