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);
        }
示例#3
0
 public void Remove(Field field)
 {
     this.AllFields.Remove(field);
     OnPropertyChanged("AllFields");
 }
示例#4
0
 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();
 }
示例#6
0
 void field_OnValueChanged(Field field, string value)
 {
     if (OnFieldValueChanged != null)
         OnFieldValueChanged(this, field);
 }
示例#7
0
 void GamePanel1_OnFieldValueChanged(object sender, Field field)
 {
     Context.SendNewFieldInfo(field);
 }