public FlagError(ErrorType errorType, JryFlagType type, string value) : base(errorType) { this.type = type; this.value = value; this.Id = type.ToString(); }
private void ConnectToFlag(JryFlagType type, IEnumerable <string> value) { var t = (int)type; var d = this.flagRefs.GetOrCreateValue(t); int n; foreach (var v in value) { if (string.IsNullOrWhiteSpace(v)) { if (Debugger.IsAttached) { Debugger.Break(); } Debug.Assert(false); } if (d.TryGetValue(v, out n)) { d[v] = n - 1; } else { this.Errors.Add(new FlagError(ErrorType.MissingFlag, type, v)); } } }
public static bool CanReplace(JryFlagType type) { switch (type) { case JryFlagType.VideoYear: case JryFlagType.EntityResolution: case JryFlagType.EntityExtension: case JryFlagType.EntityAudioSource: case JryFlagType.EntityQuality: return(false); case JryFlagType.SeriesTag: case JryFlagType.VideoType: case JryFlagType.VideoTag: return(false); case JryFlagType.EntityFansub: case JryFlagType.EntitySubTitleLanguage: case JryFlagType.EntityTrackLanguage: case JryFlagType.EntityTag: return(true); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public async Task <IEnumerable <JryFlag> > QueryAsync(JryFlagType type) { var filter = Builders <JryFlag> .Filter; return((await(await this.Collection.FindAsync( filter.Eq(t => t.Type, type))) .ToListAsync()) .OrderByDescending(z => z.Count)); }
public FlagError(ErrorType errorType, JryFlagType type, string value, int count, int actualCount) : base(errorType) { this.type = type; this.value = value; this.count = count; this.actualCount = actualCount; this.Id = type.ToString(); }
public async Task <bool> ReplaceAsync(JryFlagType type, string oldName, string newName) { if (oldName == null) { throw new ArgumentNullException(nameof(oldName)); } if (newName == null) { throw new ArgumentNullException(nameof(newName)); } if (!CanReplace(type)) { throw new NotSupportedException(); } if (oldName == newName) { return(true); } // old var oldId = JryFlag.BuildFlagId(type, oldName); var oldFlag = await this.FindAsync(oldId); var count = oldFlag?.Count ?? 0; if (oldFlag != null) { await this.Source.RemoveAsync(oldId); } // new var newId = JryFlag.BuildFlagId(type, newName); var flag = await this.FindAsync(newId); bool ret; if (flag != null) { ret = await this.Source.IncrementAsync(type, newName, count); } else { flag = new JryFlag(); flag.Type = type; flag.Value = newName; flag.Count = count; flag.BuildMetaData(true); ret = await this.InsertAsync(flag); } // exist if (ret) { this.FlagChanged?.Invoke(this, new EventArgs <JryFlagType, string, string>(type, oldName, newName)); } return(ret); }
public async Task <IEnumerable <Model.JryVideo> > QueryAsync(JryFlagType type, string flag) { FilterDefinition <Model.JryVideo> filter; switch (type) { case JryFlagType.VideoYear: case JryFlagType.VideoType: throw new NotSupportedException(); case JryFlagType.EntityResolution: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.Resolution), flag); break; case JryFlagType.EntityFilmSource: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.FilmSource), flag); break; case JryFlagType.EntityExtension: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.Extension), flag); break; case JryFlagType.EntityFansub: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.Fansubs), flag); break; case JryFlagType.EntitySubTitleLanguage: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.SubTitleLanguages), flag); break; case JryFlagType.EntityTrackLanguage: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.TrackLanguages), flag); break; case JryFlagType.EntityAudioSource: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.AudioSource), flag); break; case JryFlagType.EntityTag: filter = Builders <Model.JryVideo> .Filter.Eq(nameof(Model.JryVideo.Entities) + "." + nameof(JryEntity.Tags), flag); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } return(await(await this.Collection.FindAsync(filter)).ToListAsync()); }
public async Task <bool> RefMathAsync(JryFlagType type, string value, int count) { if (count == 0) { return(true); } var flagName = String.Format("<{0}>[{1}]", type, value); this.Log(JasilyLogger.LoggerMode.Debug, String.Format("calc flag {0} => {1}", flagName, count)); var id = JryFlag.BuildCounterId(type, value); var filter = Builders <JryFlag> .Filter; var update = Builders <JryFlag> .Update; var flag = await this.Collection.FindOneAndUpdateAsync( filter.Eq(z => z.Id, id), update.Inc(z => z.Count, count), new FindOneAndUpdateOptions <JryFlag, JryFlag>() { IsUpsert = true }); if (flag == null) { this.Log(JasilyLogger.LoggerMode.Debug, String.Format("new flag {0} was inserted.", flagName)); if (count < 1) { this.Log(JasilyLogger.LoggerMode.Debug, String.Format("flag {0} was less than 0, ignore.", flagName)); return(true); } flag = await this.FindAsync(id); flag.Type = type; flag.Value = value; flag.Count = count; flag.BuildMetaData(true); this.Log(JasilyLogger.LoggerMode.Release, String.Format("flag {0} was update to {1}, ignore.", flagName, flag.Count)); return(await this.UpdateAsync(flag)); } else { this.Log(JasilyLogger.LoggerMode.Debug, String.Format("flag {0} was exists.", flagName)); if (flag.Count + count < 0) { this.Log(JasilyLogger.LoggerMode.Debug, String.Format("flag {0} count less than 0, db error.", flagName)); await this.Collection.FindOneAndDeleteAsync(filter.Lt(z => z.Count, 0)); } else if (flag.Count + count == 0) { this.Log(JasilyLogger.LoggerMode.Debug, String.Format("flag {0} count was 0, removed.", flagName)); await this.Collection.FindOneAndDeleteAsync(filter.Lt(z => z.Count, 0)); } } return(true); }
public async Task <JryFlag> CommitAsync(JryFlagType type) { var manager = JryVideoCore.Current.CurrentDataCenter.FlagManager; var obj = new JryFlag(); // 不管是修改还是创建都是创建一个新的 obj.Type = type; this.WriteToObject(obj); obj.BuildMetaData(); return(await base.CommitAsync(manager, obj)); }
public FlagSelectorWindow(JryFlagType type, IEnumerable<string> readySelected = null) : this() { this.TitleTextBlock.Text = String.Format( Properties.Resources.FlagSelectorWindow_Title_Format, type.GetLocalizeString()); this.DataContext = this.ViewModel = new FlagSelectorViewModel(type, readySelected ?? Enumerable.Empty<string>()); this.EditFlagUserControl.FlagType = type; this.EditFlagUserControl.ViewModel.Creating += this.EditFlagUserControl_ViewModel_Creating; this.EditFlagUserControl.ViewModel.Created += this.ViewModel.EditFlagUserControl_ViewModel_Created; this.ViewModel.LoadAsync(); }
private void SelectFlag(JryFlagType type) { var flags = this.ViewModel[type]; var dlg = new FlagSelectorWindow(type, flags) { Owner = this.TryFindParent<Window>() }; if (dlg.ShowDialog() == true) { flags.Clear(); flags.AddRange(dlg.ViewModel.SelectedItems.Select(z => z.Source.Value)); } }
private void SelectFlag(JryFlagType type) { var flags = this.ViewModel[type]; var dlg = new FlagSelectorWindow(type, flags) { Owner = this.TryFindParent <Window>() }; if (dlg.ShowDialog() == true) { flags.Clear(); flags.AddRange(dlg.ViewModel.SelectedItems.Select(z => z.Source.Value)); } }
private IEnumerable<MapperValue> GetSource(JryFlagType type) { switch (type) { case JryFlagType.EntityFansub: return this.Fansubs; case JryFlagType.EntitySubTitleLanguage: return this.SubTitleLanguages; case JryFlagType.EntityTrackLanguage: return this.TrackLanguages; case JryFlagType.EntityTag: return this.Tags; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public static string GetLocalizeString(this JryFlagType flag) { switch (flag) { case JryFlagType.VideoYear: return(Resources.JryFlagType_VideoYear); case JryFlagType.VideoType: return(Resources.JryFlagType_VideoType); case JryFlagType.EntityResolution: return(Resources.JryFlagType_EntityResolution); case JryFlagType.EntityQuality: return(Resources.JryFlagType_EntityFilmSource); case JryFlagType.EntityExtension: return(Resources.JryFlagType_EntityExtension); case JryFlagType.EntityFansub: return(Resources.JryFlagType_EntityFansub); case JryFlagType.EntitySubTitleLanguage: return(Resources.JryFlagType_EntitySubTitleLanguage); case JryFlagType.EntityTrackLanguage: return(Resources.JryFlagType_EntityTrackLanguage); case JryFlagType.EntityAudioSource: return(Resources.JryFlagType_EntityAudioSource); case JryFlagType.EntityTag: return(Resources.JryFlagType_EntityTag); case JryFlagType.SeriesTag: return(Resources.JryFlagType_SeriesTag); case JryFlagType.VideoTag: return(Resources.JryFlagType_VideoTag); default: throw new ArgumentOutOfRangeException(nameof(flag), flag, null); } }
public FlagSelectorWindow(JryFlagType type, IEnumerable <string> readySelected = null) : this() { this.TitleTextBlock.Text = string.Format( Properties.Resources.FlagSelectorWindow_Title_Format, type.GetLocalizeString()); this.DataContext = this.ViewModel = new FlagSelectorViewModel(type); this.EditFlagUserControl.ViewModel.FlagType = type; this.EditFlagUserControl.ViewModel.CreateMode(); this.EditFlagUserControl.ViewModel.Creating += this.EditFlagUserControl_ViewModel_Creating; this.EditFlagUserControl.ViewModel.Created += this.ViewModel.EditFlagUserControl_ViewModel_Created; if (readySelected != null) { this.ViewModel.SelectedStrings.AddRange(readySelected); } #pragma warning disable 4014 this.ViewModel.LoadAsync(); #pragma warning restore 4014 }
private IEnumerable <MapperValue> GetSource(JryFlagType type) { switch (type) { case JryFlagType.EntityFansub: return(this.Fansubs); case JryFlagType.EntitySubTitleLanguage: return(this.SubTitleLanguages); case JryFlagType.EntityTrackLanguage: return(this.TrackLanguages); case JryFlagType.EntityTag: return(this.Tags); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public FlagSelectorWindow(JryFlagType type, IEnumerable<string> readySelected = null) : this() { this.TitleTextBlock.Text = string.Format( Properties.Resources.FlagSelectorWindow_Title_Format, type.GetLocalizeString()); this.DataContext = this.ViewModel = new FlagSelectorViewModel(type); this.EditFlagUserControl.ViewModel.FlagType = type; this.EditFlagUserControl.ViewModel.CreateMode(); this.EditFlagUserControl.ViewModel.Creating += this.EditFlagUserControl_ViewModel_Creating; this.EditFlagUserControl.ViewModel.Created += this.ViewModel.EditFlagUserControl_ViewModel_Created; if (readySelected != null) { this.ViewModel.SelectedStrings.AddRange(readySelected); } #pragma warning disable 4014 this.ViewModel.LoadAsync(); #pragma warning restore 4014 }
public ObservableCollection <string> this[JryFlagType flagType] { get { switch (flagType) { case JryFlagType.EntityFansub: return(this.Fansubs); case JryFlagType.EntitySubTitleLanguage: return(this.SubTitleLanguages); case JryFlagType.EntityTrackLanguage: return(this.TrackLanguages); case JryFlagType.EntityTag: return(this.Tags); default: throw new ArgumentOutOfRangeException(nameof(flagType), flagType, null); } } }
public FlagSelectorViewModel(JryFlagType type) { this.Type = type; }
public async Task <IEnumerable <JryFlag> > LoadAsync(JryFlagType type) { return(await this.Source.QueryAsync(type)); }
public SelectFlagViewModel(JryFlagType type) { this.Type = type; }
public async Task <string[]> TryFireAsync(JryFlagType type, string name, Func <string, bool> filter = null) => await Task.Run(() => this.TryFire(this.GetSource(type), name, filter));
public async Task <bool> UpdateNameAsync(JryFlagType type, string oldName, string newName) { if (oldName == null) { throw new ArgumentNullException(nameof(oldName)); } if (newName == null) { throw new ArgumentNullException(nameof(newName)); } if (oldName == newName) { return(true); } switch (type) { // can not change case JryFlagType.EntityResolution: case JryFlagType.EntityExtension: case JryFlagType.EntityAudioSource: case JryFlagType.EntityFilmSource: case JryFlagType.VideoYear: return(true); case JryFlagType.VideoType: case JryFlagType.EntityFansub: case JryFlagType.EntitySubTitleLanguage: case JryFlagType.EntityTrackLanguage: case JryFlagType.EntityTag: break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } // old var oldId = JryFlag.BuildCounterId(type, oldName); var oldFlag = await this.FindAsync(oldId); var count = oldFlag?.Count ?? 0; if (oldFlag != null) { await this.Source.RemoveAsync(oldId); } // new var newId = JryFlag.BuildCounterId(type, newName); var flag = await this.FindAsync(newId); bool ret; if (flag != null) { ret = await this.Source.RefMathAsync(type, newName, count); } else { flag = new JryFlag(); flag.Type = type; flag.Value = newName; flag.Count = count; flag.BuildMetaData(true); ret = await this.Source.InsertAsync(flag); } // exist if (ret) { this.FlagChanged.BeginFire(this, new EventArgs <JryFlagType, string, string>(type, oldName, newName)); } return(ret); }
public async Task<string[]> TryFireAsync(JryFlagType type, string name, Func<string, bool> filter = null) => await Task.Run(() => this.TryFire(this.GetSource(type), name, filter));
public FlagCreatedJournal(JryFlagType type, string value) { this.FlagType = type; }
public static string BuildFlagId(JryFlagType type, string value) => $"{(int)type}/{value.ThrowIfNullOrEmpty("value")}";
public bool IsObsolete(JryFlagType flag) => this.FlagType == flag;
private void ConnectToFlag(JryFlagType type, IEnumerable<string> value) { var t = (int)type; var d = this.flagRefs.GetOrCreateValue(t); int n; foreach (var v in value) { if (string.IsNullOrWhiteSpace(v)) { if (Debugger.IsAttached) Debugger.Break(); Debug.Assert(false); } if (d.TryGetValue(v, out n)) { d[v] = n - 1; } else { this.Errors.Add(new FlagError(ErrorType.MissingFlag, type, v)); } } }
public async Task <IEnumerable <JryFlag> > LoadAsync(JryFlagType type) => await this.Source.QueryAsync(type, 0, int.MaxValue);
public static string BuildCounterId(JryFlagType type, string value) { return(String.Format("{0}/{1}", (int)type, value.ThrowIfNullOrEmpty("value"))); }