private IConfigurationContext MergeConfiguration(IConfigurationContext context) { var defaultSettings = new Configuration.ConfigurationSettings(); var configSection = ConfigurationHelper.GetConfigSection <Configuration.ConfigurationSection>(); // If the value is in the config use that // Otherwise, if the value is already set via fluent config use that // Otherwise use the default value if (configSection != null) { if (!String.IsNullOrWhiteSpace(configSection.Hostname)) { context.SetHostname(configSection.Hostname); } else if (context.GetHostname() == null) { context.SetHostname(defaultSettings.Hostname); } if (!String.IsNullOrWhiteSpace(configSection.MulticastAddress)) { context.SetMulticastAddress(configSection.MulticastAddress); } else if (context.GetMulticastAddress() == null) { context.SetMulticastAddress(defaultSettings.MulticastAddress); } } return(context); }
public PrimaryConsumer(IConfigurationContext configuration) { this.configuration = configuration; this.keyResolver = configuration.SubscriptionKeyResolver; this.messageFilters = new Dictionary<Type, List<IInboundMessageFilter>>(configuration.InboundMessageFilters.ToDictionary(k => k.Key, v => new List<IInboundMessageFilter>(v))); this.subscriptions = new Dictionary<Type, Func<object, IHandlerResult>>(configuration.Subscriptions.ToDictionary(k => k.Key, v => v.First())); }
public static void Web(this IConfigurationContext builder, string name, Action <IWebComponentConfigurator> config) { var spec = builder.CreateComponentConfigSpecification <WebComponentSpecification>(name); config(spec); builder.AddSpecification(spec); }
public async Task LoadAsync(IConfigurationContext context) { foreach (var service in ProxiedServices) { await service.LoadAsync(context); } }
private void ConfigureType(IConfigurationContext context, CachedType cachedType) { if (!MayConfigureType(cachedType)) { if (cachedType.State == ProcessingState.RegistratorRan) { cachedType.State = ProcessingState.Configured; } return; } if (!cachedType.HasProcessableAttributes || SimulateOnlyUnprocessableTypes) { cachedType.State = ProcessingState.Configured; return; } foreach (var attribute in cachedType.ProcessableAttributes !) { ConfigureType(context, cachedType.Type, attribute); } cachedType.State = ProcessingState.Configured; }
public PrimaryConsumer(IConfigurationContext configuration) { this.configuration = configuration; this.keyResolver = configuration.SubscriptionKeyResolver; this.messageFilters = new Dictionary <Type, List <IInboundMessageFilter> >(configuration.InboundMessageFilters.ToDictionary(k => k.Key, v => new List <IInboundMessageFilter>(v))); this.subscriptions = new Dictionary <Type, Func <object, IHandlerResult> >(configuration.Subscriptions.ToDictionary(k => k.Key, v => v.First())); }
public BusClient(ITransport transport, ISubscriptionKeyResolver keyResolver, IConfigurationContext configurationContext) { this.transport = transport; this.keyResolver = keyResolver; this.transport.InitializeForPublishing(); this.configurationContext = configurationContext; }
public async Task LoadAsync(IConfigurationContext context) { IConfigurationContext permissionsContext = context.CreateChildConfigurationContext("Permissions"); IConfigurationContext groupsContext = permissionsContext.CreateChildConfigurationContext("Groups"); GroupsConfig.ConfigurationContext = groupsContext; await GroupsConfig.LoadAsync(new { Groups = new object[] { new GroupPermissionSection { Id = "Default", Name = "Default Group", Priority = 0, Permissions = new[] { "SomePermission", "SomePermission.Other" }, AutoAssign = true } } }); IConfigurationContext playersContext = permissionsContext.CreateChildConfigurationContext("Players"); PlayersConfig.ConfigurationContext = playersContext; await PlayersConfig.LoadAsync(); }
private IConfigurationContext MergeConfiguration(IConfigurationContext context) { var defaultSettings = new Configuration.ConfigurationSettings(); var configSection = ConfigurationHelper.GetConfigSection <Configuration.ConfigurationSection>(); // If the value is in the config use that // Otherwise, if the value is already set via fluent config use that // Otherwise use the default value if (configSection != null) { if (!String.IsNullOrWhiteSpace(configSection.ConnectionStringName)) { context.SetConnectionString(ConfigurationManager.ConnectionStrings[configSection.ConnectionStringName].ConnectionString); } else if (context.GetConnectionString() == null) { context.SetConnectionString(defaultSettings.ConnectionString); } if (!String.IsNullOrWhiteSpace(configSection.Exchange)) { context.SetExchange(configSection.Exchange); } else if (context.GetExchange() == null) { context.SetExchange(defaultSettings.Exchange); } } return(context); }
public BusClient(ITransport transport, ISubscriptionKeyResolver keyResolver, IConfigurationContext configurationContext) { this.transport = transport; this.keyResolver = keyResolver; this.transport.InitializeForPublishing(); this.configurationContext = configurationContext; }
public DelayConsumer(IConfigurationContext configuration) { this.configuration = configuration; // Flipped whenever a new message arrives from the transport to short circuit // the 15 second timeout intervals this.resetEvent = new AutoResetEvent(false); }
public WebhookController(IConfigurationContext configuration, IAuthorizationService authorizationService) { Requires.NotNull(configuration, nameof(configuration)); _configuration = configuration; Requires.NotNull(authorizationService, nameof(authorizationService)); _authorizationService = authorizationService; }
public Log4NetLogger(IConfigurationContext configuration) { #if NET451 || NET472 internalLogger = LogManager.GetLogger(configuration.AssemblyLocator.GetEntryAssembly().GetName().Name); #else internalLogger = LogManager.GetLogger(configuration.AssemblyLocator.GetEntryAssembly().EntryPoint.DeclaringType); #endif }
internal static ushort?GetDelayQueuePrefetchCount(this IConfigurationContext context) { ushort result; return(ushort.TryParse((string)context["rabbitmq.delayQueuePrefetchCount"], out result) ? result : (ushort?)null); }
public override void Configure(IConfigurationContext context, ProcessableAttribute attribute, Type typeWithAttribute) { var boundedContext = ((OutboxAttribute)attribute).BoundedContext; var outboxProcessor = D.P.GetRequiredInstance <IOutboxProcessor>(); GenericsHelper.RegisterOutboxToOutboxProcessor(outboxProcessor, typeWithAttribute, boundedContext, OutboxPublicationType); }
internal MSMQTransport(string baseQueueName, IConfigurationContext configuration) { this.configuration = MergeConfiguration(configuration); this.subscriptions = new ConcurrentDictionary <String, String>(); this.primaryQueueName = baseQueueName; this.delayQueueName = String.Format("{0}_Delay", this.primaryQueueName); this.errorQueueName = String.Format("{0}_Error", this.primaryQueueName); }
public override void Configure(IConfigurationContext context, ProcessableAttribute attribute, Type typeWithAttribute) { var interfaceType = ((ProcessableWithInterfaceAttribute)attribute).GetInterfaceOrDefault(typeWithAttribute); var instance = (ISomeConfigurable)D.P.GetRequiredInstance(interfaceType); instance.Configured = true; }
public override void Configure(IConfigurationContext context, ProcessableAttribute attribute, Type typeWithAttribute) { var key = ((OutboxProcessorAttribute)attribute).ScheduleConfigurationKey; var scheduleConfiguration = D.O.GetRequiredString(key); var outboxProcessor = D.P.GetRequiredInstance <IOutboxProcessor>(); outboxProcessor.Schedule(scheduleConfiguration); }
internal MSMQTransport(string baseQueueName, IConfigurationContext configuration) { this.configuration = MergeConfiguration(configuration); this.subscriptions = new ConcurrentDictionary<String, String>(); this.primaryQueueName = baseQueueName; this.delayQueueName = String.Format("{0}_Delay", this.primaryQueueName); this.errorQueueName = String.Format("{0}_Error", this.primaryQueueName); }
internal static ushort?GetPrefetchCountPerWorker(this IConfigurationContext context) { ushort result; return(ushort.TryParse((string)context["rabbitmq.prefetchCountPerWorker"], out result) ? result : (ushort?)null); }
public override void Configure(IConfigurationContext context, ProcessableAttribute attribute, Type typeWithAttribute) { var attributeTyped = (IntegrationEventHandlerAttribute)attribute; var eventHandlerRegistry = D.P.GetRequiredInstance <IIntegrationEventHandlerRegistry>(); eventHandlerRegistry.Add(attributeTyped.EventStreamIdentifier, typeWithAttribute); }
internal static RunAs GetUserType(this IConfigurationContext context) { if (context["topshelf.usertype"] == null) { return(RunAs.LocalService); } return((RunAs)context["topshelf.usertype"]); }
static void AddDefaultStrategies(IConfigurationContext context) { context.AddStrategy<ComparableComparisonStrategy>(); context.AddStrategy<PrimitiveComparisonStrategy>(); context.AddStrategy<EqualsOverrideComparisonStrategy>(); context.AddStrategy<EnumerableComparisonStrategy>(); context.AddStrategy<ClassComparisonStrategy>(); context.AddStrategy<DefaultComparisonStrategy>(); }
public FeaturesManagerFactory(MiniRecipient recipient, IConfigurationContext configurationContext, ScopeFlightsSettingsProvider scopeFlightsSettingsProvider, Func <VariantConfigurationSnapshot, IFeaturesStateOverride> featureStateOverrideFactory, string rampId, bool isFirstRelease) { this.recipient = recipient; this.configurationContext = configurationContext; this.scopeFlightsSettingsProvider = scopeFlightsSettingsProvider; this.featureStateOverrideFactory = featureStateOverrideFactory; this.rampId = rampId; this.isFirstRelease = isFirstRelease; }
//public long GetJobQueueIdByJobType(IConfigurationContext configurationContext, long fileReceivedId, int jobType) public JobQueueEntry GetJobQueueEntryByJobType(IConfigurationContext configurationContext, long fileReceivedId, int jobType) { var jobQueue = commonTestRepository.GetJobQueueEntry(configurationContext.ClientFileTypeId, fileReceivedId, jobType).FirstOrDefault(); if (jobQueue == null || jobQueue.JobQueueId == 0) { throw new Exception("JobQueueId = 0 or JobQueue not exist!!! Please recheck"); } return(jobQueue); }
public SchoolSearcher(IConfigurationContext _DB, ref int _RequestedCount, ref int _RequestedPage, ref string _RequestedValue) { RequestedCount = _RequestedCount; RequestedPage = _RequestedPage; RequestedValue = _RequestedValue; Schools = _DB.Tenants; Cities = _DB.Cities; Database = _DB; }
/// <summary> /// Merges in configuration from external files from the passed in configuration /// </summary> /// <param name="configuration"></param> /// <returns></returns> private IConfigurationContext MergeConfiguration(IConfigurationContext configuration) { var configSection = ConfigurationHelper.GetConfigSection <Configuration.ConfigurationSection>(); if (configSection != null) { configuration.SetAutomaticConfigurationFlag(configSection.UseAutomaticConfiguration); } return(configuration); }
public static IConfigurationContext UseStrategies(this IConfigurationContext configurationContext, IEnumerable <IComparisonStrategy> strategies) { configurationContext.ClearStrategies(); foreach (var strategy in strategies) { configurationContext.PushStrategy(strategy); } return(configurationContext); }
internal static IConfigurationContext UseAllStrategies(this IConfigurationContext configurationContext) { configurationContext.PushStrategy <DefaultComparisonStrategy>(); configurationContext.PushStrategy <KeyValuePairComparisonStrategy>(); configurationContext.PushStrategy <ClassComparisonStrategy>(); configurationContext.PushStrategy <EnumerableComparisonStrategy>(); configurationContext.PushStrategy <EqualsOverrideComparisonStrategy>(); configurationContext.PushStrategy <PrimitiveComparisonStrategy>(); configurationContext.PushStrategy <ComparableComparisonStrategy>(); return(configurationContext); }
public override void Configure(IConfigurationContext context, ProcessableAttribute attribute, Type typeWithAttribute) { var attributeTyped = (MessageForExchangeCommandQueueTargetAttribute)attribute; var messageBus = D.P.GetRequiredInstance <IMessageBus>(); var messageListenerType = attributeTyped.MessageListenerType; var targetBoundedContext = attributeTyped.TargetBoundedContext; var exchangeName = Exchange.CommandsFor(targetBoundedContext); var queueName = Queue.For(targetBoundedContext); GenericsHelper.RegisterMessageToMessageBus(messageBus, typeWithAttribute, messageListenerType, exchangeName, queueName); }
private void Configure(IConfigurationContext context) { var watch = System.Diagnostics.Stopwatch.StartNew(); ConfigureTypes(context); RunConfigurators(context); long elapsedMilliseconds = watch.ElapsedMilliseconds; Statistics.ClassConfigurationTime += elapsedMilliseconds; Options.Logger?.Log($"Method '{nameof( Configure )}' executed in {elapsedMilliseconds} ms."); }
private void ConfigureType(IConfigurationContext context, Type type, ProcessableAttribute attribute) { var attributeType = attribute.GetType(); var extension = GetExtensionForAttribute(attributeType); if (extension == null) { throw new InvalidOperationException($"Unhandled attribute '{attributeType.Name}'"); } extension.Configure(context, attribute, type); Options.Logger?.Log($"Configured class '{type.Name}' with attribute '{attributeType.Name}'"); }
internal RabbitMQTransport(string baseQueueName, IConfigurationContext configuration) { this.configuration = MergeConfiguration(configuration); // Cache encoding name as looking it from the Encoding class is expensive. this.encodingName = new Lazy<string>(() => configuration.Serializer.Encoding.EncodingName); this.connectionManager = new RabbitConnectionManager(new Uri(configuration.GetConnectionString())); this.primaryQueueName = baseQueueName; this.delayQueueName = String.Format("{0}_Delay", this.primaryQueueName); this.errorQueueName = String.Format("{0}_Error", this.primaryQueueName); this.DeclareExchange(); this.sendChannel = new ThreadLocal<IModel>(() => this.connectionManager.GetChannel(), true); }
public long GetJobQueueId(IConfigurationContext configurationContext, long fileReceivedId) { long jobQueueId = 0; var jobQueue = commonTestRepository.GetJobQueueEntry(configurationContext.ClientFileTypeId, fileReceivedId, configurationContext.JobType); foreach (var field in jobQueue) { jobQueueId = field.JobQueueId; } if (jobQueueId == 0) { throw new Exception("JobQueueId = 0 !!! Please recheck"); } return(jobQueueId); }
private void RunConfigurator(IConfigurationContext context, CachedType cachedType) { if (!MayRunConfigurator(cachedType) || SimulateOnlyUnprocessableTypes) { if (cachedType.State == ProcessingState.Configured) { cachedType.State = ProcessingState.ConfiguratorRan; } return; } cachedType.RegistratorConfigurator !.Configure(context); cachedType.State = ProcessingState.ConfiguratorRan; Options.Logger?.Log($"Ran configurator '{cachedType.Type.Name}'"); }
public TopShelfHost(IConfigurationContext configuration) : base(configuration) { this.ConfigurationContext = MergeConfiguration(configuration); }
public DefaultHost(IConfigurationContext configuration) : base(configuration) { }
private IConfigurationContext MergeConfiguration(IConfigurationContext context) { var defaultSettings = new Configuration.ConfigurationSettings(); var configSection = ConfigurationHelper.GetConfigSection<Configuration.ConfigurationSection>(); // If the value is in the config use that // Otherwise, if the value is already set via fluent config use that // Otherwise use the default value if (configSection != null) { if (!String.IsNullOrWhiteSpace(configSection.Hostname)) { context.SetHostname(configSection.Hostname); } else if (context.GetHostname() == null) { context.SetHostname(defaultSettings.Hostname); } if (!String.IsNullOrWhiteSpace(configSection.MulticastAddress)) { context.SetMulticastAddress(configSection.MulticastAddress); } else if (context.GetMulticastAddress() == null) { context.SetMulticastAddress(defaultSettings.MulticastAddress); } } return context; }
public BusHost(IConfigurationContext configuration) { this.configuration = configuration; }
public static void Set(IConfigurationContext configurationContext) { configuration.Set(configurationContext); }
private IConfigurationContext MergeConfiguration(IConfigurationContext context) { var defaultSettings = new Configuration.ConfigurationSettings(); var configSection = ConfigurationHelper.GetConfigSection<Configuration.ConfigurationSection>(); // If the value is in the config use that // Otherwise, if the value is already set via fluent config use that // Otherwise use the default value if (configSection != null) { if (!String.IsNullOrWhiteSpace(configSection.ConnectionStringName)) { context.SetConnectionString(ConfigurationManager.ConnectionStrings[configSection.ConnectionStringName].ConnectionString); } else if (context.GetConnectionString() == null) { context.SetConnectionString(defaultSettings.ConnectionString); } if (!String.IsNullOrWhiteSpace(configSection.Exchange)) { context.SetExchange(configSection.Exchange); } else if (context.GetExchange() == null) { context.SetExchange(defaultSettings.Exchange); } } return context; }
public ConfigurationContext() { this.configValues = new Dictionary<string, object>(); instance = this; }
public RabbitMQTransport(IConfigurationContext configuration) : this(configuration.QueueNameResolver.GetPrimaryQueueName(), configuration) { }
public NLogLogger(IConfigurationContext configuration) { internalLogger = LogManager.GetLogger(configuration.AssemblyLocator.GetEntryAssembly().GetName().Name); }
public void Configure(IConfigurationContext context) { try { var config = context.Config; var mediaConfig = context.MediaConfig; var loggingConfig = context.LoggingConfig; var cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); _section = (SipUserAgentSettingsSection) cfg.Sections["sipua"]; if (_section != null) { context.RegisterTransport( new Core.Utils.Tuple<TransportType, TransportConfig>( (TransportType) Enum.Parse(typeof (TransportType), _section.Transport.TransportType, true), new TransportConfig(){Port = (uint) _section.Transport.Port, BoundAddress = _section.Transport.BoundAddress, PublicAddress = _section.Transport.PublicAddress })); config.UseSrtp = _section.SecureMedia; config.SecureSignalling = _section.SecureSignaling; if (_section.NetworkSettings != null) { config.NatInSdp = _section.NetworkSettings.NatInSdp; config.ForceLooseRoute = _section.NetworkSettings.ForceLooseRoute; if (_section.NetworkSettings.DnsServers != null) for (int i = 0; i < _section.NetworkSettings.DnsServers.Count; i++) if (!string.IsNullOrEmpty(_section.NetworkSettings.DnsServers[i].Address)) config.DnsServers.Add(_section.NetworkSettings.DnsServers[i].Address); if (_section.NetworkSettings.Proxies != null) for (int i = 0; i < _section.NetworkSettings.Proxies.Count; i++) if (!string.IsNullOrEmpty(_section.NetworkSettings.Proxies[i].Address)) config.OutboundProxies.Add(_section.NetworkSettings.Proxies[i].Address); if (_section.NetworkSettings.StunServers != null) for (int i = 0; i < _section.NetworkSettings.StunServers.Count; i++) if (!string.IsNullOrEmpty(_section.NetworkSettings.StunServers[i].Address)) config.StunServers.Add(_section.NetworkSettings.StunServers[i].Address); if (_section.NetworkSettings.Stun != null) { config.StunHost = _section.NetworkSettings.Stun.Address; } if (_section.NetworkSettings.Turn != null && _section.NetworkSettings.Turn.Enabled) { mediaConfig.EnableTurn = true; mediaConfig.TurnServer = _section.NetworkSettings.Turn.Server; TransportType tpType = TransportType.Udp; switch (_section.NetworkSettings.Turn.TransportType) { case "udp": tpType = TransportType.Udp; break; case "tcp": tpType = TransportType.Tcp; break; case "tls": tpType = TransportType.Tls; break; } mediaConfig.TurnConnectionType = tpType; mediaConfig.TurnAuthentication = new NetworkCredential { UserName = _section.NetworkSettings.Turn.UserName, Password = _section.NetworkSettings.Turn.Password, Domain = _section.NetworkSettings.Turn.Realm }; } if (_section.NetworkSettings.ICE != null) { mediaConfig.EnableICE = _section.NetworkSettings.ICE.Enabled; //mediaConfig.ICENoHostCandidates = _section.NetworkSettings.ICE.NoHostCandidates; mediaConfig.ICENoRtcp = _section.NetworkSettings.ICE.NoRtcp; } } mediaConfig.IsVadEnabled = _section.MediaConfig.IsVadEnabled; config.AutoAnswer = _section.AutoAnswer; config.AutoRecord = _section.AutoRecording; config.AutoConference = _section.AutoConference; config.MaxCalls = (uint) _section.MaxCalls; loggingConfig.LogMessages = _section.LogMessages; loggingConfig.LogLevel = (uint) _section.LogLevel; loggingConfig.TraceAndDebug = _section.TraceAndDebug; mediaConfig.CaptureDeviceId = _section.MediaConfig.CaptureDeviceId; mediaConfig.PlaybackDeviceId = _section.MediaConfig.PlaybackDeviceId; context.RegisterAccounts( _section.Accounts.Cast<AccountElement>() .Select(ae => { var accCfg = new AccountConfig() { Id = ae.AccountId, RegUri = ae.RegistrarUri, IsPublishEnabled = ae.PublishPresence, IsDefault = ae.IsDefault }; accCfg.Credentials.Add(new NetworkCredential(ae.UserName, ae.Password, ae.Realm)); return accCfg; })); } } catch (ConfigurationErrorsException) //error in config using default settings { } }
/// <summary> /// Merges in configuration from external files from the passed in configuration /// </summary> /// <param name="configuration"></param> /// <returns></returns> private IConfigurationContext MergeConfiguration(IConfigurationContext configuration) { var configSection = ConfigurationHelper.GetConfigSection<Configuration.ConfigurationSection>(); if (configSection != null) { configuration.SetAutomaticConfigurationFlag(configSection.UseAutomaticConfiguration); } return configuration; }
public IISHost(IConfigurationContext configuration) : base(configuration) { this.ConfigurationContext = MergeConfiguration(configuration); this.log = this.ConfigurationContext.Logger; }
private IConfigurationContext MergeConfiguration(IConfigurationContext configuration) { var defaultSettings = new Configuration.ConfigurationSettings(); var configSection = ConfigurationHelper.GetConfigSection<Configuration.ConfigurationSection>(); if (configSection != null) { if (!String.IsNullOrWhiteSpace(configSection.RunAs.UserType)) { switch (configSection.RunAs.UserType.ToUpper()) { case "LOCALSERVICE": configuration.SetUserType(Configuration.RunAs.LocalService); break; case "LOCALSYSTEM": configuration.SetUserType(Configuration.RunAs.LocalSystem); break; case "NETWORKSERVICE": configuration.SetUserType(Configuration.RunAs.NetworkService); break; case "USER": configuration.SetUserType(Configuration.RunAs.User); break; } if (!String.IsNullOrWhiteSpace(configSection.RunAs.Username)) { configuration.SetUsername(configSection.RunAs.Username); } if (!String.IsNullOrWhiteSpace(configSection.RunAs.Password)) { configuration.SetPassword(configSection.RunAs.Password); } } if (!String.IsNullOrWhiteSpace(configSection.Service.Description)) { configuration.SetDescription(configSection.Service.Description); } if (!String.IsNullOrWhiteSpace(configSection.Service.DisplayName)) { configuration.SetDisplayName(configSection.Service.DisplayName); } if (!String.IsNullOrWhiteSpace(configSection.Service.Name)) { configuration.SetServiceName(configSection.Service.Name); } } // Set Defaults if (String.IsNullOrWhiteSpace(configuration.GetServiceName())) { configuration.SetServiceName(configuration.AssemblyLocator.GetEntryAssembly().GetName().Name); } if (String.IsNullOrWhiteSpace(configuration.GetDescription())) { configuration.SetDescription("Wave Service Host"); } if (String.IsNullOrWhiteSpace(configuration.GetDisplayName())) { configuration.SetDisplayName(configuration.AssemblyLocator.GetEntryAssembly().GetName().Name); } return configuration; }
/// <summary> /// Initializes a new instance of the <see cref="MapViewModel" /> class. /// </summary> public MapViewModel() { _data = ApplicationContext.Data; _configuration = ApplicationContext.Configuration; _navigation = ApplicationContext.NavigationService; if (IsCompassSupported) { _compass = new Compass {TimeBetweenUpdates = TimeSpan.FromMilliseconds(200)}; _compass.CurrentValueChanged += OnCompassReadingChanged; } // Initialise local properties. VisualState = new ObservableValue<VisualStates>(); Suggestions = new ReadOnlyObservableCollection<SearchSuggestion>(_suggestions); Pushpins = new AdaptedObservableCollection<Place, PlaceViewModel>(p => new PlaceViewModel(p, this), source: _data.Places); Routes = new AdaptedObservableCollection<Route, RouteViewModel>(r => new RouteViewModel(r, this), source: _data.Routes); DepartureLocation = new RouteLocation(); ArrivalLocation = new RouteLocation(); // Initialise commands. CommandGetSuggestions = new DelegateCommand(OnGetSuggestions); CommandSearch = new DelegateCommand(OnSearch); CommandAddPlace = new DelegateCommand<Location>(OnAddPlace); CommandSelectPushpin = new DelegateCommand<PlaceViewModel>(vm => SelectedPushpin = vm); CommandSelectRoute = new DelegateCommand<RouteViewModel>(vm => SelectedRoute = vm); CommandDeletePlace = new DelegateCommand<PlaceViewModel>(OnDeletePlace); CommandUpdatePlace = new DelegateCommand<PlaceViewModel>(OnUpdatePlace); CommandStopTrackingCurrentLocation = new DelegateCommand(OnStopTrackingCurrentLocation); CommandGoToDefaultState = new DelegateCommand(OnGoToDefaultState); CommandAddCurrentPlace = new DelegateCommand(() => OnAddPlace(CurrentLocation.ToLocalLocation()), () => CurrentLocation != null && !CurrentLocation.IsUnknown); CommandZoomIn = new DelegateCommand(() => { if (ZoomLevel.Value < MaxZoomLevel) ZoomLevel.Value = Math.Min(ZoomLevel.Value += ZoomStep, MaxZoomLevel); }); CommandZoomOut = new DelegateCommand(() => { if (ZoomLevel.Value > MinZoomLevel) ZoomLevel.Value = Math.Max(ZoomLevel.Value -= ZoomStep, MinZoomLevel); }); CommandShowStreetLayer = new DelegateCommand(() => _data.MapBaseLayer.Value = Layer.Street); CommandShowSatelliteHybridLayer = new DelegateCommand(() => _data.MapBaseLayer.Value = Layer.SatelliteHybrid); CommandToggleMapOverlay = new DelegateCommand<Layer>(_data.ToggleMapOverlay); CommandToggleToolbar = new DelegateCommand(_configuration.ToggleToolbarState); CommandSetDepartLocationToCurrentLocation = new DelegateCommand(() => DepartureLocation.Address = CurrentLocationString); CommandSetArriveLocationToCurrentLocation = new DelegateCommand(() => ArrivalLocation.Address = CurrentLocationString); CommandRoute = new DelegateCommand(OnRoute); CommandActivate = new DelegateCommand(OnActivate); CommandDeactivate = new DelegateCommand(OnDeactivate); CommandSwapRouteLocations = new DelegateCommand(OnSwapRouteLocations); CommandSelectContactAddress = new DelegateCommand(OnSelectContactAddress); CommandSelectDepartLocationFromContacts = new DelegateCommand(OnSelectDepartLocationFromContacts); CommandSelectArriveLocationFromContacts = new DelegateCommand(OnSelectArriveLocationFromContacts); // Initialise application bar button and menu items sources. InitializeAppBarButtonSources(); InitializeAppBarMenuItemsSource(); // Handle events. Pushpins.CollectionChanged += OnPushpinsCollectionChanged; _data.MapBaseLayer.ValueChanged += (old, @new) => RaisePropertyChanged(IsStreetLayerVisibleProperty, IsSatelliteHybridLayerVisibleProperty); _data.SelectedPlace.ValueChanged += (old, @new) => SelectedPushpin = Pushpins.FirstOrDefault(p => p.Data == @new); _data.MapOverlays.CollectionChanged += (s, e) => RaisePropertyChanged(IsTrafficLayerVisibleProperty, IsTransitLayerVisibleProperty); _data.ClearRoutesBeforeAddingNewRoute.ValueChanged += (old, @new) => RaisePropertyChanged(GetRouteButtonTextProperty); VisualState.ValueChanged += OnVisualStateChanged; IsTrackingCurrentLocation.ValueChanged += OnIsTrackingCurrentLocationValueChanged; // Automatically track current position at first run. if (_data.LastRanVersion == null) IsTrackingCurrentLocation.Value = true; #if DEBUG if (DesignerProperties.IsInDesignTool) return; #endif // Initialise geo-coordinate watcher. _geoWatcher = ApplicationContext.GeoCoordinateWatcher; _geoWatcher.PositionChanged += OnGeoWatcherPositionChanged; // Try centering on current location if available. if (IsTrackingCurrentLocation.Value) { if (!_geoWatcher.Position.Location.IsUnknown) { Center.Value = _geoWatcher.Position.Location; ZoomLevel.Value = 15; } } }