Пример #1
0
        //**************************************************************************
        // Constructor:	FieldSingleton
        //
        // Description:	Private constructor to set up access to API
        //
        // Parameters:	None
        //
        // Returns:		None
        //**************************************************************************
        private FieldSingleton()
        {
            this.fieldDataService = new FieldApiDataService(new Uri("https://evenstreaminfunctionapp.azurewebsites.net"));
            this.fieldEntries     = new ObservableCollection <FieldTable> ();

            this.LoadMediator();
        }
 public FieldDefenitionController(IUnitOfWork unitOfWork, IFieldDataService fieldDataService, IFieldDefenitionGroupDataService fieldDefenitionGroupDataService, IFieldDefentionFacade fieldDefentionFacade)
 {
     _fieldDefentionFacade            = fieldDefentionFacade;
     _fieldDataService                = fieldDataService;
     _unitOfWork                      = unitOfWork;
     _fieldDefenitionGroupDataService = fieldDefenitionGroupDataService;
 }
Пример #3
0
        public DownloadVM(
            IDiversityServiceClient Service,
            IConnectivityService Connectivity,
            IFieldDataService Storage,
            IKeyMappingService Mappings,
            EventHierarchyLoader HierarchyLoader,
            [Dispatcher] IScheduler Dispatcher
            ) {
            this.Service = Service;
            this.Connectivity = Connectivity;
            this.Storage = Storage;
            this.Mappings = Mappings;
            this.HierarchyLoader = HierarchyLoader;

            QueryResult = new ReactiveCollection<Event>();

            _IsOnlineAvailable = Connectivity.Status().Select(s => s == ConnectionStatus.Wifi).Do(_ => { this.GetType(); }, ex => { }, () => { })
                .ToProperty(this, x => x.IsOnlineAvailable);

            SearchEvents = new ReactiveAsyncCommand(this.WhenAny(x => x.IsOnlineAvailable, x => x.Value));
            SearchEvents.ShowInFlightNotification(Notifications, DiversityResources.Download_SearchingEvents);
            SearchEvents.ThrownExceptions
                    .ShowServiceErrorNotifications(Notifications)
                    .ShowErrorNotifications(Notifications)
                    .Subscribe();
            SearchEvents
                .RegisterAsyncObservable(query =>
                    Service.GetEventsByLocality(query as string ?? string.Empty)
                    .TakeUntil(this.OnDeactivation())
                )
                .Do(_ => QueryResult.Clear())
                .Subscribe(QueryResult.AddRange);

            CancelDownload = new ReactiveCommand();

            DownloadElement = new ReactiveAsyncCommand(this.WhenAny(x => x.IsOnlineAvailable, x => x.Value));
            DownloadElement.ThrownExceptions
                .ShowServiceErrorNotifications(Notifications)
                .ShowErrorNotifications(Notifications)
                .Subscribe();
            DownloadElement
                .RegisterAsyncObservable(ev => IfNotDownloadedYet(ev as Event)
                    .Select(HierarchyLoader.downloadAndStoreDependencies)
                    .SelectMany(dl => dl.TakeUntil(CancelDownload))
                    .Scan(0, (acc, _) => ++acc)
                    .Do(_ElementsDownloadedSubject.OnNext)
                    );

            _IsDownloading = DownloadElement.ItemsInflight
                .Select(x => x > 0)
                .ToProperty(this, x => x.IsDownloading);

            this.OnDeactivation()
                .Subscribe(_ => Messenger.SendMessage(EventMessage.Default, MessageContracts.INIT));

            _ElementsDownloadedSubject = new Subject<int>();
            _ElementsDownloaded = _ElementsDownloadedSubject.ToProperty(this, x => x.ElementsDownloaded, 0, Dispatcher);
        }
 public EventHierarchyLoader(
     IDiversityServiceClient Service,
     IFieldDataService Storage,
     IKeyMappingService Mappings,
     [ThreadPool] IScheduler ThreadPool
     ) {
     this.Service = Service;
     this.Storage = Storage;
     this.Mappings = Mappings;
     this.ThreadPool = ThreadPool;
 }
Пример #5
0
        public ViewMapVM(
            IMapStorageService MapStorage,
            ILocationService Location,
            IFieldDataService Storage
            ) {
            Contract.Requires(MapStorage != null);
            Contract.Requires(Location != null);
            Contract.Requires(Storage != null);
            this.MapStorage = MapStorage;
            this.Location = Location;
            this.Storage = Storage;

            ImageScale = 1.0;
            ImageOffset = new Point();

            SelectMap = new ReactiveCommand();
            SelectMap
                .Select(_ => Page.MapManagement)
                .ToMessage(Messenger);

            this.FirstActivation()
                .Select(_ => Page.MapManagement)
                .ToMessage(Messenger);


            _CurrentMap = this.ObservableToProperty(Messenger.Listen<IElementVM<Map>>(MessageContracts.VIEW), x => x.CurrentMap);
            _CurrentMap
                .Where(vm => vm != null)
                .Select(vm => Observable.Start(() => MapStorage.loadMap(vm.Model)))
                .Switch()
                .ObserveOnDispatcher()
                .Select(stream => {
                    var img = new BitmapImage();
                    img.SetSource(stream);
                    stream.Close();
                    return img;
                })
                .Subscribe(x => MapImage = x);

            var current_series = Messenger.Listen<ILocationOwner>(MessageContracts.VIEW);

            var current_localizable = Messenger.Listen<ILocalizable>(MessageContracts.VIEW);

            var current_series_if_not_localizable = current_series.Merge(current_localizable.Select(_ => null as ILocationOwner));

            var current_localizable_if_not_series = current_localizable.Merge(current_series.Select(_ => null as ILocalizable));

            var series_and_map =
            current_series_if_not_localizable
                .CombineLatest(_CurrentMap.Where(x => x != null), (es, map) =>
                    new { Map = map.Model, Series = es })
                .Publish();


            var add_locs =
            series_and_map
                .Select(pair => {
                    if (pair.Series != null) {
                        var stream = Storage.getGeoPointsForSeries(pair.Series.EntityID).ToObservable(ThreadPoolScheduler.Instance) //Fetch geopoints asynchronously on Threadpool thread
                                .Merge(Messenger.Listen<GeoPointForSeries>(MessageContracts.SAVE).Where(gp => gp.SeriesID == pair.Series.EntityID)) //Listen to new Geopoints that are added to the current tour
                                .Select(gp => pair.Map.PercentilePositionOnMap(gp))
                                .TakeUntil(series_and_map)
                                .Replay();
                        stream.Connect();
                        return stream as IObservable<Point?>;
                    }
                    else
                        return Observable.Empty<Point?>();
                }).Replay(1);

            _AdditionalLocalizations = add_locs;
            add_locs.Connect();

            series_and_map.Connect();

            Observable.CombineLatest(
                current_localizable_if_not_series,
                _CurrentMap,
                (loc, map) => {
                    if (map == null)
                        return null;
                    return map.Model.PercentilePositionOnMap(loc);
                })
                .Subscribe(c => PrimaryLocalization = c);



            ToggleEditable = new ReactiveCommand(current_localizable_if_not_series.Select(l => l != null));

            _IsEditable = this.ObservableToProperty(
                                current_localizable_if_not_series.Select(_ => false)
                                .Merge(ToggleEditable.Select(_ => true)),
                                x => x.IsEditable);

            SetLocation = new ReactiveCommand(_IsEditable);
            SetLocation
                .Select(loc => loc as Point?)
                .Where(loc => loc != null)
                .Subscribe(loc => PrimaryLocalization = loc);

            var valid_localization = this.ObservableForProperty(x => x.PrimaryLocalization).Value()
                .Select(loc => loc.HasValue);



            Save = new ReactiveCommand(_IsEditable.BooleanAnd(valid_localization));
            current_localizable_if_not_series
                .Where(loc => loc != null)
                .Select(loc =>
                    Save
                    .Select(_ => loc)
                    )
                .Switch()
                .Do(c => c.SetCoordinates(CurrentMap.Model.GPSFromPercentilePosition(PrimaryLocalization.Value)))
                .Do(_ => Messenger.SendMessage(Page.Previous))
                .ToMessage(Messenger, MessageContracts.SAVE);

            this.OnActivation()
                .Where(_ => CurrentMap != null)
                .SelectMany(_ => Location.Location().StartWith(null as Coordinate).TakeUntil(this.OnDeactivation()))
                .Select(c => CurrentMap.Model.PercentilePositionOnMap(c))
                .Subscribe(c => CurrentLocation = c);

        }
Пример #6
0
        public HomeVM(
            IFieldDataService Storage,
            ILocationService Location,
            [Dispatcher] IScheduler Dispatcher
            )
        {
            this.Storage = Storage;
            this.Location = Location;

            //EventSeries
            SeriesList = new ReactiveCollection<EventSeriesVM>();

            getSeries.RegisterAsyncFunction(_ =>
                    Enumerable.Repeat(NoEventSeriesMixin.NoEventSeries, 1)
                    .Concat(
                        Storage
                        .getAllEventSeries()
                        )
                    .Select(es => new EventSeriesVM(es))
                )
                .SelectMany(vm => vm)
                .ObserveOn(Dispatcher)
                .Subscribe(SeriesList.Add);

            SeriesList
                    .ListenToChanges<EventSeries, EventSeriesVM>();

            (SelectSeries = new ReactiveCommand<IElementVM<EventSeries>>())
                .ToMessage(Messenger, MessageContracts.VIEW);

            (EditSeries = new ReactiveCommand<IElementVM<EventSeries>>(vm => vm.Model != NoEventSeriesMixin.NoEventSeries))
                .ToMessage(Messenger, MessageContracts.EDIT);

            var openSeries = SeriesList.CollectionCountChanged.Select(_ => Unit.Default)
                .Merge(Messenger.Listen<IElementVM<EventSeries>>(MessageContracts.SAVE).Select(_ => Unit.Default))
                .Select(_ => SeriesList.Where(s => s.Model.SeriesEnd == null))
                .Select(list => list.FirstOrDefault());

            openSeries
                .SelectMany(series => (series != null) ?
                    Location.LocationByDistanceThreshold(20)
                    .Select(c =>
                    {
                        var gp = new Localization() { RelatedID = series.Model.SeriesID };
                        gp.SetCoordinates(c);
                        return gp;
                    })
                    .TakeUntil(openSeries) : Observable.Empty<Localization>())
                .ObserveOn(Dispatcher)
                .ToMessage(Messenger, MessageContracts.SAVE);

            var noOpenSeries =
                openSeries
                .Select(openseries => openseries == null);

            Settings = new ReactiveCommand();
            Settings.Select(_ => Page.Settings)
                .ToMessage(Messenger);

            Add = new ReactiveCommand(noOpenSeries);
            Add.Select(_ => new EventSeriesVM(new EventSeries()) as IElementVM<EventSeries>)
                .ToMessage(Messenger, MessageContracts.EDIT);

            Maps = new ReactiveCommand();
            Maps.Select(_ => null as ILocalizable)
                .ToMessage(Messenger, MessageContracts.VIEW);

            Help = new ReactiveCommand();
            Help.Select(_ => Page.Info)
               .ToMessage(Messenger);

            Messenger.Listen<EventMessage>(MessageContracts.INIT)
                .Do(_ => SeriesList.Clear())
                .Subscribe(_ => getSeries.Execute(null));
        }