Exemplo n.º 1
0
#pragma warning restore IDE0032 // Use auto property

    private Player(
        PlayerState state,
        ILocationStore locationStore,
        IRoadStore roadStore,
        Action <string> updateMessagingGroup)
    {
        _locationStore        = locationStore;
        _roadStore            = roadStore;
        _updateMessagingGroup = updateMessagingGroup;

        _playerId   = state.PlayerId;
        _locationId = state.LocationId;

        if (state.RoadMovementState != null)
        {
            var road = roadStore.Find(state.RoadMovementState.RoadId);
            if (road == null)
            {
                throw new InvalidOperationException($"Road {state.RoadMovementState.RoadId} is not found in the store.");
            }

            _roadMovementComponent = new RoadMovementComponent(road, state.RoadMovementState.Progress, state.RoadMovementState.MovementDirection);
        }

        UpdateMessagingGroup();
    }
Exemplo n.º 2
0
        public DistributedCentralStorage(
            DistributedCentralStoreConfiguration configuration,
            ILocationStore locationStore,
            IDistributedContentCopier copier,
            CentralStorage fallbackStorage)
        {
            _configuration = configuration;
            _copier = copier;
            _fallbackStorage = fallbackStorage;
            _locationStore = locationStore;

            var maxRetentionMb = configuration.MaxRetentionGb * 1024;
            var softRetentionMb = (int)(maxRetentionMb * 0.8);

            var cacheFolder = configuration.CacheRoot / CacheSubFolderName;

            _copierWorkingDirectory = new DisposableDirectory(copier.FileSystem, cacheFolder / "Temp");

            // Create a private CAS for storing checkpoint data
            // Avoid introducing churn into primary CAS
            _privateCas = new FileSystemContentStoreInternal(
                copier.FileSystem,
                SystemClock.Instance,
                cacheFolder,
                new ConfigurationModel(
                    new ContentStoreConfiguration(new MaxSizeQuota(hardExpression: maxRetentionMb + "MB", softExpression: softRetentionMb + "MB")),
                    ConfigurationSelection.RequireAndUseInProcessConfiguration),
                settings: new ContentStoreSettings()
                {
                    TraceFileSystemContentStoreDiagnosticMessages = _configuration.TraceFileSystemContentStoreDiagnosticMessages,
                    SelfCheckSettings = _configuration.SelfCheckSettings,
                });
        }
Exemplo n.º 3
0
 public FocusGeofenceService(IDigitLogger logger,
                             ILocationStore locationStore, IFocusStore focusStore)
 {
     _logger        = logger;
     _locationStore = locationStore;
     _focusStore    = focusStore;
 }
Exemplo n.º 4
0
 public PlayerPersistenceFactory(
     ILocationStore locationStore,
     IRoadStore roadStore,
     IConnectedClientStore connectedClientStore)
 {
     _locationStore        = locationStore;
     _roadStore            = roadStore;
     _connectedClientStore = connectedClientStore;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResponseLog" /> class.
        /// </summary>
        /// <param name="options">The configured <see cref="SqlServerLoggingOptions" />.</param>
        /// <param name="locations">The configured <see cref="LocationStore" />.</param>
        /// <param name="environment">The environment context.</param>
        public ResponseLog(SqlServerLoggingOptions options, ILocationStore locations, ApplicationInformation environment) : base(options.BatchSize, options.Period)
        {
            Argument.NotNull(options, nameof(options));
            Argument.NotNull(locations, nameof(locations));
            Argument.NotNull(environment, nameof(environment));

            _options     = options;
            _locations   = locations;
            _environment = environment;

            _eventsTable = this.CreateTable();
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Construct a sink posting to the specified database.
        /// </summary>
        /// <param name="connectionString">Connection string to access the database.</param>
        /// <param name="tableName">Name of the table to store the data in.</param>
        /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
        /// <param name="columnOptions">Options that pertain to columns</param>
        public MSSqlServerSink(
            string connectionString,
            string tableName,
            int batchPostingLimit,
            TimeSpan period,
            IFormatProvider formatProvider,
            bool autoCreateSqlTable     = false,
            ColumnOptions columnOptions = null,
            ILocationStore locations    = null
            )
            : base(batchPostingLimit, period)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException("connectionString");
            }

            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentNullException("tableName");
            }

            _connectionString = connectionString;
            _tableName        = tableName;
            _formatProvider   = formatProvider;
            _locations        = locations;
            _columnOptions    = columnOptions ?? new ColumnOptions();
            if (_columnOptions.AdditionalDataColumns != null)
            {
                _additionalDataColumnNames = new HashSet <string>(_columnOptions.AdditionalDataColumns.Select(c => c.ColumnName), StringComparer.OrdinalIgnoreCase);
            }

            if (_columnOptions.Store.Contains(StandardColumn.LogEvent))
            {
                _jsonFormatter = new JsonFormatter(formatProvider: formatProvider);
            }

            // Prepare the data table
            _eventsTable = this.CreateDataTable();

            if (autoCreateSqlTable)
            {
                try
                {
                    var tableCreator = new SqlTableCreator(connectionString);
                    tableCreator.CreateTable(_eventsTable);
                }
                catch (Exception ex)
                {
                    SelfLog.WriteLine("Exception {0} caught while creating table {1} to the database specified in the Connection string.", ex, tableName);
                }
            }
        }
Exemplo n.º 7
0
 public static Player FromState(
     PlayerState state,
     ILocationStore locationStore,
     IRoadStore roadStore,
     Action <string> updateMessagingGroup)
 {
     return(new Player(
                state,
                locationStore,
                roadStore,
                updateMessagingGroup));
 }
        public DistributedCentralStorage(
            DistributedCentralStoreConfiguration configuration,
            ILocationStore locationStore,
            DistributedContentCopier copier,
            CentralStorage fallbackStorage,
            IClock clock)
            : base(configuration, fallbackStorage, copier.FileSystem)
        {
            _copier           = copier;
            _locationStore    = locationStore;
            _checkpointCopies = new VolatileMap <ShortHash, CopyOperation>(clock);
            _checkpointStore  = configuration.IsCheckpointAware ? _locationStore as ICheckpointStore : null;

            _copierWorkingDirectory = new DisposableDirectory(copier.FileSystem, PrivateCas !.RootPath / "Temp");
        }
Exemplo n.º 9
0
        public UserStore(IConnectionFactory sqlConnectionFactory, ILocationStore locationStore)
        {
            _sqlConnectionFactory = sqlConnectionFactory;
            _locationStore        = locationStore;

            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <User, UserEntity>();
                cfg.CreateMap <UserEntity, User>();
                cfg.CreateMap <Ngo, NgoEntity>();
                cfg.CreateMap <NgoEntity, Ngo>();
            });

            _mapper = configuration.CreateMapper();
        }
        /// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// Create a database and execute the table creation script found here
        /// https://gist.github.com/mivano/10429656
        /// or use the autoCreateSqlTable option.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="tableName">Name of the table to store the events in.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
        /// <param name="columnOptions"></param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration StacksSqlServer(
            this LoggerSinkConfiguration loggerConfiguration,
            string connectionString,
            string tableName,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int batchPostingLimit          = Serilog.Sinks.MSSqlServer.MSSqlServerSink.DefaultBatchPostingLimit,
            TimeSpan?period                = null,
            IFormatProvider formatProvider = null,
            bool autoCreateSqlTable        = false,
            ColumnOptions columnOptions    = null,
            ILocationStore locations       = null
            )
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException("loggerConfiguration");
            }

            var defaultedPeriod = period ?? Serilog.Sinks.MSSqlServer.MSSqlServerSink.DefaultPeriod;

            var serviceConfigSection =
                ConfigurationManager.GetSection("MSSqlServerSettingsSection") as MSSqlServerConfigurationSection;

            // If we have additional columns from config, load them as well
            if (serviceConfigSection != null && serviceConfigSection.Columns.Count > 0)
            {
                if (columnOptions == null)
                {
                    columnOptions = new ColumnOptions();
                }
                GenerateDataColumnsFromConfig(serviceConfigSection, columnOptions);
            }

            connectionString = GetConnectionString(connectionString);

            return(loggerConfiguration.Sink(
                       new MSSqlServerSink(
                           connectionString,
                           tableName,
                           batchPostingLimit,
                           defaultedPeriod,
                           formatProvider,
                           autoCreateSqlTable,
                           columnOptions,
                           locations
                           ),
                       restrictedToMinimumLevel));
        }
Exemplo n.º 11
0
        public ILocationStore GetStore()
        {
            if (string.IsNullOrEmpty(this.settingsStore.UserName))
            {
                return new NullLocationStore();
            }

            if (this.settingsStore.UserName != this.username)
            {
                this.username = this.settingsStore.UserName;
                var storeName = string.Format("{0}.location.store", this.username);
                this.locationStore = this.locationStoreFactory.Invoke(storeName);
            }

            return this.locationStore;
        }
        public static Location FindLocationForClient(this ILocationStore locationStore, ConnectedClient sender)
        {
            var location = locationStore.FindLocationForCharacter(sender.ClientId);

            if (location == null)
            {
                throw new InvalidOperationException("Character never joined the world.");
            }

            if (location.LocationId != sender.Group)
            {
                throw new InvalidOperationException("Synchronization mismatch.");
            }

            return(location);
        }
Exemplo n.º 13
0
        public TransactionStore(IConnectionFactory sqlConnectionFactory, ILocationStore locationStore)
        {
            _sqlConnectionFactory = sqlConnectionFactory;
            _locationStore        = locationStore;

            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Campaign, CampaignEntity>();
                cfg.CreateMap <CampaignEntity, Campaign>();
                cfg.CreateMap <Contribution, ContributionEntity>();
                cfg.CreateMap <ContributionEntity, Contribution>();
                cfg.CreateMap <Process, ProcessEntity>();
                cfg.CreateMap <ProcessEntity, Process>();
                cfg.CreateMap <DeliveryDemand, DeliveryDemandEntity>();
                cfg.CreateMap <DeliveryDemandEntity, DeliveryDemand>();
            });

            _mapper = configuration.CreateMapper();
        }
Exemplo n.º 14
0
            public LocationUpdateReceived()
            {
                var locationStoreMock = new Mock<ILocationStore>(MockBehavior.Strict);
                locationStoreMock.Setup(v => v.GetActiveGeofenceRequests(userId, It.IsAny<DateTimeOffset>())).Returns(Task.FromResult(new GeofenceRequest[0]));
                locationStoreMock.Setup(v => v.AddGeofenceRequests(userId, It.IsAny<GeofenceRequest[]>())).Returns(Task.FromResult(new GeofenceRequest[0]));
                locationStoreMock.Setup(v => v.UpdateLocationAsync(userId, It.IsAny<Location>())).Returns(Task.CompletedTask);
                //locationStoreMock.Setup(v => v.SetGeofenceRequestedAsync(userId, It.IsAny<GeofenceRequest>())).Returns(Task.CompletedTask);
                //locationStoreMock.Setup(v => v.IsGeofenceActiveAsync(userId, It.IsAny<GeofenceRequest>())).Returns(Task.FromResult(false));
                //locationStoreMock.Setup(v => v.ClearGeofenceAsync(userId)).Returns(Task.CompletedTask);
                locationStoreMock.Setup(v => v.GetLastLocationAsync(userId)).Returns(Task.FromResult((Location)null));
                locationStore = locationStoreMock.Object;

                var pushSyncServiceMock = new Mock<IPushSyncService>(MockBehavior.Strict);
                pushSyncServiceMock.Setup(v => v.SetLocationRequestedExternal(It.IsAny<string>(), It.IsAny<DateTimeOffset>()))
                    .Returns(Task.CompletedTask);
                pushSyncServiceMock.Setup(v => v.SetLocationRequestDone(It.IsAny<string>()))
                    .Returns(Task.CompletedTask);
                pushSyncServiceMock.Setup(v => v.SetDone(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns(Task.CompletedTask);
                logger = Mock.Of<IDigitLogger>();
                pushSyncService = pushSyncServiceMock.Object;
            }
Exemplo n.º 15
0
 public ProposeRopeWarContestHandler(ILocationStore locationStore, ICharactersClient charactersClient)
 {
     _locationStore    = locationStore;
     _charactersClient = charactersClient;
 }
Exemplo n.º 16
0
 public MoveToLocationHandler(ILocationStore locationStore)
 {
     _locationStore = locationStore;
 }
Exemplo n.º 17
0
 public VoteToStartRopeWarHandler(ILocationStore locationStore)
 {
     _locationStore = locationStore;
 }
Exemplo n.º 18
0
 public JoinRopeWarContestHandler(ILocationStore locationStore)
 {
     _locationStore = locationStore;
 }
Exemplo n.º 19
0
 public GeoTagController(ILocationStore locationStore, ILogger <GeoTagController> logger)
 {
     _locationStore = locationStore;
     _logger        = logger;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlLogger" /> class.
        /// </summary>
        /// <param name="options">The configured <see cref="SqlServerLoggingOptions" />.</param>
        /// <param name="policies">The configured <see cref="IDestructuringPolicy" /> instances.</param>
        /// <param name="locations">The configured <see cref="LocationStore" />.</param>
        public SqlLogger(SqlServerLoggingOptions options, IEnumerable <IDestructuringPolicy> policies, ILocationStore locations)
        {
            Argument.NotNull(options, nameof(options));

            var columnOptions = new ColumnOptions();

            // Don't include the Properties XML column.
            columnOptions.Store.Remove(StandardColumn.Properties);

            // Do include the log event data as JSON.
            columnOptions.Store.Add(StandardColumn.LogEvent);

            var builder = new LoggerConfiguration()
                          .Destructure.With(policies.ToArray())
                          .Enrich.FromLogContext()
                          .WriteTo.StacksSqlServer(options.ConnectionString, options.TraceTableName, autoCreateSqlTable: true, columnOptions: columnOptions, locations: locations)
                          .MinimumLevel.Is(options.GetLogLevel());

            _logger = builder.CreateLogger();
        }
Exemplo n.º 21
0
 public LocationsController(ILocationStore store, IGeocoder geocoder)
 {
     _store    = store;
     _geocoder = geocoder;
 }
 public LocationUpdateFactory(
     ILocationStore locationStore)
 {
     _locationStore = locationStore;
 }
 public LocationsController(ILocationStore locationStore)
 {
     _locationStore = locationStore;
 }
Exemplo n.º 24
0
 public LocationService(IPushSyncService pushSyncService, ILocationStore locationStore, IDigitLogger logger)
 {
     this.pushSyncService = pushSyncService;
     this.locationStore   = locationStore;
     this.logger          = logger;
 }
 /// <inheritdoc />
 public Task <BoolResult> StartupAsync(OperationContext context, ILocationStore locationStore)
 {
     _locationStore = locationStore;
     return(StartupAsync(context));
 }
Exemplo n.º 26
0
 public ConnectHook(ILocationStore locationStore)
 {
     _locationStore = locationStore;
 }