public SyncValidItems(Field field) { InitializeComponent(); this.DataContext = Context; Syncer = new ValidItemsSyncer(); Syncer.OnProgress += Syncer_OnProgress; Syncer.OnFinish += Syncer_OnFinish; this.field = field; }
/// <summary> /// Read all items in for given items in file per each line and sync with /// database. /// </summary> /// <param name="field">field to sync it's valid items with database</param> void _SyncItems(Field field) { using (StreamReader sr = new StreamReader(field.ValidItemsFilePath)) { long n = 0; DbMan.ValidItems vi = new DbMan.ValidItems(); if (field.ID < 1) field.ID = new FieldsManager().GetFieldID(field); List<string> words = null; try { words = new Crawler.Crawler().GetAllWords(field.URL); } catch { } if (words != null) { foreach (var word in words) { vi.AddNewValidItem(field.ID, word); if (OnProgress != null) OnProgress(field.Title, ++n); } } vi.DeleteValidItems(field.ID); while (!sr.EndOfStream) { string line = sr.ReadLine(); vi.AddNewValidItem(field.ID, line); // notify to UI if (OnProgress != null) OnProgress(field.Title, ++n); } } if (OnFinish != null) OnFinish(this); }
public void Remove(Field field) { this.AllFields.Remove(field); OnPropertyChanged("AllFields"); }
public void Add(Field field) { this.AllFields.Add(field); OnPropertyChanged("AllFields"); }
/// <summary> /// start syncing all valid items with database in thread /// </summary> /// <param name="field">field to sync items with database</param> public void StartSync(Field field) { new Thread(new ThreadStart(() => _SyncItems(field))).Start(); }
void field_OnValueChanged(Field field, string value) { if (OnFieldValueChanged != null) OnFieldValueChanged(this, field); }
void GamePanel1_OnFieldValueChanged(object sender, Field field) { Context.SendNewFieldInfo(field); }