상속: INotifyPropertyChanged
예제 #1
0
 public void Add(string name, string type)
 {
     if (name.Trim() != "")
     {
         if (!Dict.ContainsKey(name))
         {
             Station station = new Station(name, Dict.Count + 1);
             station.SetType(type);
             Dict.Add(name, station);
             Save();
         }
     }
 }
        private void initializeStations(Station[] uniqueStations)
        {
            //Load stations
            OpenStations.Clear();

            if (stationMonitoring != null) stationMonitoring.Dispose();

            //Start by adding all stations as open stations to the collection
            foreach (var s in uniqueStations) OpenStations.Add(s);

            //Load up Stations instance with new stations
            var stations = Stations.Instance;
            stations.LoadNew(uniqueStations);

            //Hook up station status change monitoring events for all stations
            var allStations = stations.Dict;
            var subscriptions = allStations.Select(kvp => kvp.Value).Select(s =>
            {
                var stationPropChanged = Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(h => s.PropertyChanged += h, h => s.PropertyChanged -= h);

                return stationPropChanged.Where(ep => ep.EventArgs.PropertyName == "Status")
                    .ObserveOnDispatcher().Subscribe(_ =>
                    {
                        if (s.Status == StationStatus.Open) OpenStations.Add(s);
                        else OpenStations.Remove(s);
                    });
            }).ToArray();

            //Get the names of all currently "in use" stations and mark them as in use, removing them from the observable collection via the event listener that was just hooked up
            var inUseStations = OpenMatches.Select(m => m.Match.StationAssignment).Where(sn => sn != null);
            foreach (var sn in inUseStations)
            {
                stations.AttemptClaimStation(sn);
            }

            stationMonitoring = new CompositeDisposable(subscriptions);
        }
        private void loadStationsFromSettings()
        {
            if (Properties.Settings.Default.stationNames != null && Properties.Settings.Default.stationNames.Count > 0)
            {
                Station[] stations = new Station[Properties.Settings.Default.stationNames.Count];

                for (int x = 0; x < Properties.Settings.Default.stationNames.Count; x++)
                {
                    StationType type = StationType.Standard;
                    string name = Properties.Settings.Default.stationNames[x];
                    string stationText;
                    if (Properties.Settings.Default.stationTypes != null && Properties.Settings.Default.stationTypes.Count > x)
                        stationText = Properties.Settings.Default.stationTypes[x].Trim().ToLower();
                    else
                        stationText = "";

                    if (stationText == "stream") type = StationType.Stream;
                    else if (stationText == "recording") type = StationType.Recording;
                    else if (stationText == "premium") type = StationType.Premium;
                    else if (stationText == "backup") type = StationType.Backup;
                    else if (stationText == "noassign") type = StationType.NoAssign;

                    Station station = new Station(name, x, type);
                    stations[x] = station;
                }

                reinitializeStations(stations);
            }
            else
            {
                Station[] stations = new Station[0];
                reinitializeStations(stations);
            }
        }