예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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!
            }
        }
예제 #4
0
        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!
            }
        }