コード例 #1
0
        public static void OnLogReceive(string level, string message)
        {
            #if DEBUG && DEBUG_LOG_INTERCEPTOR
            App.Logger.Debug("l: {0} m: {1}", level, message);
            #endif

            #if DEBUG
            LogReceived?.Invoke(Application.Current, new LogInterceptedEventArgs(message, level));
            #elif RELEASE
            switch (level)
            {
            case "Warn":
                LogReceived?.Invoke(null, new LogInterceptedEventArgs(message, "Предупреждение:"));

                break;

            case "Error":
                LogReceived?.Invoke(null, new LogInterceptedEventArgs(message, "Ошибка:"));

                break;

            case "Fatal":
                LogReceived?.Invoke(null, new LogInterceptedEventArgs(message, "Критическая ошибка:"));

                break;

            default:
                LogReceived?.Invoke(null, new LogInterceptedEventArgs(message, ""));

                break;
            }
            #endif
        }
コード例 #2
0
        public async Task <bool> LaunchGameAsync(LaunchProfile profile, Version version)
        {
            var startInfo = new ProcessStartInfo
            {
                FileName               = profile.IsDebugMode ? _gamePathService.JavaPath : _gamePathService.JavawPath,
                WorkingDirectory       = _gamePathService.WorkingDir,
                Arguments              = BuildArguments(profile, version),
                UseShellExecute        = profile.IsDebugMode,
                RedirectStandardOutput = !profile.IsDebugMode,
                RedirectStandardError  = !profile.IsDebugMode,
            };

            _gameProcess = Process.Start(startInfo);

            _gameProcess.EnableRaisingEvents = true;
            _gameProcess.Exited += (s, e) => Exited?.Invoke(_gameProcess.ExitCode);

            if (!profile.IsDebugMode)
            {
                _gameProcess.ErrorDataReceived += (s, e) => ErrorReceived?.Invoke(e.Data);
                _gameProcess.BeginErrorReadLine();

                _gameProcess.OutputDataReceived += (s, e) => LogReceived?.Invoke(e.Data);
                _gameProcess.BeginOutputReadLine();

                if (!_gameProcess.HasExited)
                {
                    await Task.Run(() => _gameProcess.WaitForInputIdle());
                }
            }

            return(!_gameProcess.HasExited);
        }
コード例 #3
0
 public static void RaiseLogEvent(LogEvent logEvent, IFormatProvider formatProvider)
 {
     LogReceived?.Invoke(null, new LogReceivedEventArgs()
     {
         LogEvent = logEvent, FormatProvider = formatProvider
     });
 }
コード例 #4
0
        public override void OnWireReceived(UnsafeReader reader)
        {
            var version = reader.ReadInt();
            var value   = ReadValueDelegate(SerializationContext, reader);

            var rejected = IsMaster && version < myMasterVersion;

            if (LogReceived.IsTraceEnabled())
            {
                LogReceived.Trace("property `{0}` ({1}):: oldver = {2}, newver = {3}, value = {4}{5}",
                                  Location, RdId, myMasterVersion, version, value.PrintToString(), rejected ? " REJECTED" : "");
            }


            if (rejected)
            {
                return;
            }

            myMasterVersion = version;

            using (UsingDebugInfo())
            {
                myProperty.Value = value;
            }
        }
コード例 #5
0
        public void LogMessage(LogLevel logLevel, string message)
        {
            switch (logLevel)
            {
            case LogLevel.Critical:
                _logger.Fatal(message);
                LogReceived?.Invoke(LogEventLevel.Fatal, _logger, message, _application);
                break;

            case LogLevel.Debug:
                _logger.Debug(message);
                LogReceived?.Invoke(LogEventLevel.Debug, _logger, message, _application);
                break;

            case LogLevel.Information:
                _logger.Information(message);
                LogReceived?.Invoke(LogEventLevel.Information, _logger, message, _application);
                break;

            case LogLevel.Warning:
                _logger.Warning(message);
                LogReceived?.Invoke(LogEventLevel.Warning, _logger, message, _application);
                break;

            case LogLevel.Error:
                _logger.Error(message);
                LogReceived?.Invoke(LogEventLevel.Error, _logger, message, _application);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the configured <see cref="ISqlBuilder"/> for the specified <see cref="IDbConnection"/> instance.
        /// </summary>
        /// <param name="connection">The database connection instance.</param>
        /// <returns>The <see cref="ISqlBuilder"/> interface for the specified <see cref="IDbConnection"/> instance.</returns>
        public static ISqlBuilder GetSqlBuilder(IDbConnection connection)
        {
            var connectionTypeName = connection.GetType().Name;
            var builder            = SqlBuilders.TryGetValue(connectionTypeName.ToLower(), out var b) ? b : new SqlServerSqlBuilder();

            LogReceived?.Invoke($"Selected SQL Builder '{builder.GetType().Name}' for connection type '{connectionTypeName}'");
            return(builder);
        }
コード例 #7
0
 /// <summary>
 /// Error handler to rethrow wkhtmltopdf log events.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Instance of <see cref="DataReceivedEventArgs"/>.</param>
 private void ErrorDataHandler(object sender, DataReceivedEventArgs e)
 {
     if (!string.IsNullOrEmpty(e?.Data))
     {
         _lastLogLine = e.Data;
         LogReceived?.Invoke(this, e);
     }
 }
コード例 #8
0
        public override void OnWireReceived(UnsafeReader reader)
        {
            var taskId = RdId.Read(reader);
            var value  = ReadRequestDelegate(SerializationContext, reader);

            if (LogReceived.IsTraceEnabled())
            {
                LogReceived.Trace("endpoint `{0}`::({1}), taskId={2}, request = {3}", Location, RdId, taskId, value.PrintToString());
            }


            RdTask <TRes> rdTask;

            using (UsingDebugInfo()) //now supports only sync handlers
            {
                try
                {
                    rdTask = Handler(myBindLifetime, value);
                }
                catch (OperationCanceledException)
                {
                    rdTask = RdTask <TRes> .Cancelled();
                }
                catch (Exception e)
                {
                    rdTask = RdTask <TRes> .Faulted(e);
                }
            }

            rdTask.Result.Advise(myBindLifetime, result =>
            {
                if (LogSend.IsTraceEnabled())
                {
                    LogSend.Trace("endpoint `{0}`::({1}), taskId={2}, response = {3}", Location, RdId, taskId, result.PrintToString());
                }

                RdTaskResult <TRes> validatedResult;
                try
                {
                    if (result.Status == RdTaskStatus.Success)
                    {
                        AssertNullability(result.Result);
                    }
                    validatedResult = result;
                }
                catch (Exception e)
                {
                    LogSend.Error(e);
                    validatedResult = RdTaskResult <TRes> .Faulted(e);
                }

                Wire.Send(RdId, (writer) =>
                {
                    taskId.Write(writer);
                    RdTaskResult <TRes> .Write(WriteResponseDelegate, SerializationContext, writer, validatedResult);
                });
            });
        }
コード例 #9
0
        internal StdIOTransport(Process process, TransportTaskScheduler scheduler = null)
        {
            _process = process;
            scheduler ??= ScheduleTransportTask;
            process.ErrorDataReceived += (s, e) => LogReceived?.Invoke(this, new LogReceivedEventArgs(e.Data));
            process.BeginErrorReadLine();

            scheduler(GetResponseAsync, _readerCancellationSource.Token);
        }
コード例 #10
0
 void Log(object message)
 {
     Debug.WriteLine($"[{DateTime.Now.ToString(CultureInfo.CurrentCulture)} ]: {message}");
     try
     {
         LogReceived?.Invoke(this, message);
     }
     catch { }
 }
コード例 #11
0
ファイル: Site.cs プロジェクト: Snappey/Scraper
        public void Log(string log, LogType type = LogType.Information)
        {
            logStream.Log(log, this, type);

            LogReceived.Invoke(this, new LogEventArgs
            {
                Log  = $"[{DateTime.Now.ToShortTimeString()}] {URL.Host}: {log}",
                Type = type,
            });
        }
コード例 #12
0
ファイル: RdSignal.cs プロジェクト: epeshk/rd
        public override void OnWireReceived(UnsafeReader reader)
        {
            var value = myReadValue(SerializationContext, reader);

            if (LogReceived.IsTraceEnabled())
            {
                LogReceived.Trace("signal `{0}` ({1}):: value = {2}", Location, RdId, value.PrintToString());
            }
            using (UsingDebugInfo())
                mySignal.Fire(value);
        }
コード例 #13
0
            /// <summary>
            /// Gets the key properties for the specified type, using the configured <see cref="IKeyPropertyResolver"/>.
            /// </summary>
            /// <param name="type">The <see cref="Type"/> to get the key properties for.</param>
            /// <returns>The key properties for <paramref name="type"/>.</returns>
            public static KeyPropertyInfo[] KeyProperties(Type type)
            {
                if (!_typeKeyPropertiesCache.TryGetValue(type, out var keyProperties))
                {
                    keyProperties = KeyPropertyResolver.ResolveKeyProperties(type);
                    _typeKeyPropertiesCache.TryAdd(type, keyProperties);
                }

                LogReceived?.Invoke($"Resolved property '{string.Join(", ", keyProperties.Select(p => p.Property.Name))}' as key property for '{type}'");
                return(keyProperties);
            }
コード例 #14
0
            /// <summary>
            /// Gets the name of the column in the database for the specified type,
            /// using the configured <see cref="IColumnNameResolver"/>.
            /// </summary>
            /// <param name="propertyInfo">The <see cref="PropertyInfo"/> to get the column name for.</param>
            /// <param name="sqlBuilder">The SQL builder instance.</param>
            /// <returns>The column name in the database for <paramref name="propertyInfo"/>.</returns>
            public static string Column(PropertyInfo propertyInfo, ISqlBuilder sqlBuilder)
            {
                var key = $"{sqlBuilder.GetType()}.{propertyInfo.DeclaringType}.{propertyInfo.Name}";

                if (!_columnNameCache.TryGetValue(key, out var columnName))
                {
                    columnName = sqlBuilder.QuoteIdentifier(_columnNameResolver.ResolveColumnName(propertyInfo));
                    _columnNameCache.TryAdd(key, columnName);
                }

                LogReceived?.Invoke($"Resolved column name '{columnName}' for '{propertyInfo}'");
                return(columnName);
            }
コード例 #15
0
            /// <summary>
            /// Gets the name of the table in the database for the specified type,
            /// using the configured <see cref="ITableNameResolver"/>.
            /// </summary>
            /// <param name="type">The <see cref="Type"/> to get the table name for.</param>
            /// <param name="sqlBuilder">The SQL builder instance.</param>
            /// <returns>The table name in the database for <paramref name="type"/>.</returns>
            public static string Table(Type type, ISqlBuilder sqlBuilder)
            {
                var key = $"{sqlBuilder.GetType()}.{type}";

                if (!_typeTableNameCache.TryGetValue(key, out var name))
                {
                    name = sqlBuilder.QuoteIdentifier(_tableNameResolver.ResolveTableName(type));
                    _typeTableNameCache.TryAdd(key, name);
                }

                LogReceived?.Invoke($"Resolved table name '{name}' for '{type}'");
                return(name);
            }
コード例 #16
0
            /// <summary>
            /// Gets the the data column for the specified type,
            /// using the configured <see cref="IDataColumnResolver"/>.
            /// </summary>
            /// <param name="propertyInfo">The <see cref="NonaProperty"/> to get the data column for.</param>
            /// <returns>The data column for <paramref name="propertyInfo"/>.</returns>
            public static Tuple <string, Type> DataColumn(NonaProperty propertyInfo)
            {
                var key = propertyInfo.PropertyKey;

                if (!DataColumnCache.TryGetValue(key, out var column))
                {
                    column = _dataColumnResolver.ResolveDataColumn(propertyInfo);
                    DataColumnCache.TryAdd(key, column);
                }

                LogReceived?.Invoke($"Resolved column name '{column.Item1}' for '{propertyInfo.PropertyInfo}'");
                return(column);
            }
コード例 #17
0
            /// <summary>
            /// Gets the key property for the specified type, using the configured <see cref="IKeyPropertyResolver"/>.
            /// </summary>
            /// <param name="type">The <see cref="Type"/> to get the key property for.</param>
            /// <param name="isIdentity">A value indicating whether the key is an identity.</param>
            /// <returns>The key property for <paramref name="type"/>.</returns>
            public static PropertyInfo KeyProperty(Type type, out bool isIdentity)
            {
                if (!_typeKeyPropertyCache.TryGetValue(type, out var keyProperty))
                {
                    var propertyInfo = _keyPropertyResolver.ResolveKeyProperty(type, out isIdentity);
                    keyProperty = new KeyPropertyInfo(propertyInfo, isIdentity);
                    _typeKeyPropertyCache.TryAdd(type, keyProperty);
                }

                isIdentity = keyProperty.IsIdentity;

                LogReceived?.Invoke($"Resolved property '{keyProperty.PropertyInfo}' (Identity: {isIdentity}) as key property for '{type.Name}'");
                return(keyProperty.PropertyInfo);
            }
コード例 #18
0
            /// <summary>
            /// Gets the key properties for the specified type, using the configured <see cref="IKeyPropertyResolver"/>.
            /// </summary>
            /// <param name="type">The <see cref="Type"/> to get the key properties for.</param>
            /// <param name="isIdentity">A value indicating whether the keys represent an identity.</param>
            /// <returns>The key properties for <paramref name="type"/>.</returns>
            public static PropertyInfo[] KeyProperties(Type type, out bool isIdentity)
            {
                if (!_typeKeyPropertiesCache.TryGetValue(type, out var keyPropertyInfo))
                {
                    var propertyInfos = _keyPropertyResolver.ResolveKeyProperties(type, out isIdentity);
                    keyPropertyInfo = new KeyPropertyInfo(propertyInfos, isIdentity);
                    _typeKeyPropertiesCache.TryAdd(type, keyPropertyInfo);
                }

                isIdentity = keyPropertyInfo.IsIdentity;

                LogReceived?.Invoke($"Resolved property '{string.Join<PropertyInfo>(", ", keyPropertyInfo.PropertyInfos)}' (Identity: {isIdentity}) as key property for '{type}'");
                return(keyPropertyInfo.PropertyInfos);
            }
コード例 #19
0
            /// <summary>
            /// Gets the key property for the specified type, using the configured <see cref="IKeyPropertyResolver"/>.
            /// </summary>
            /// <param name="type">The <see cref="Type"/> to get the key property for.</param>
            /// <param name="isIdentity">A value indicating whether the key is an identity.</param>
            /// <returns>The key property for <paramref name="type"/>.</returns>
            public static NonaProperty KeyProperty(Type type, out bool isIdentity)
            {
                if (!TypeKeyPropertyCache.TryGetValue(type.TypeHandle, out var keyProperty))
                {
                    var NonaProperty = _keyPropertyResolver.Resolve(type, out isIdentity);
                    keyProperty = new KeyPropertyInfo(NonaProperty, isIdentity);
                    TypeKeyPropertyCache.TryAdd(type.TypeHandle, keyProperty);
                }

                isIdentity = keyProperty.IsIdentity;

                LogReceived?.Invoke($"Resolved property '{keyProperty.NonaProperty}' (Identity: {isIdentity}) as key property for '{type.Name}'");
                return(keyProperty.NonaProperty);
            }
コード例 #20
0
            /// <summary>
            /// Gets the name of the table in the database for the specified type,
            /// using the configured <see cref="ITableNameResolver"/>.
            /// </summary>
            /// <param name="type">The <see cref="Type"/> to get the table name for.</param>
            /// <returns>The table name in the database for <paramref name="type"/>.</returns>
            public static string Table(Type type)
            {
                if (!_typeTableNameCache.TryGetValue(type, out var name))
                {
                    name = _tableNameResolver.ResolveTableName(type);
                    if (EscapeCharacterStart != char.MinValue || EscapeCharacterEnd != char.MinValue)
                    {
                        name = EscapeCharacterStart + name + EscapeCharacterEnd;
                    }
                    _typeTableNameCache.TryAdd(type, name);
                }

                LogReceived?.Invoke($"Resolved table name '{name}' for '{type.Name}'");
                return(name);
            }
コード例 #21
0
 /// <summary>
 /// Indicates a new log entry has been received and that the log provider should handle it.
 /// </summary>
 /// <param name="logEntry">
 /// The log entry to handle.
 /// </param>
 public void AddLogEntry(LogEntry logEntry)
 {
     if (!_supportedLogLevels.Contains(logEntry.Level))
     {
         return;
     }
     try
     {
         LogReceived?.Invoke(null, new LogEventArgs(logEntry));
     }
     catch
     {
         // Don't let logging bring us down so swallow the error
     }
 }
コード例 #22
0
        private async void Connect()
        {
            try
            {
                if (messageWebSocket == null)
                {
                    messageWebSocket = new MessageWebSocket();
                    messageWebSocket.Control.MessageType = SocketMessageType.Utf8;
                    messageWebSocket.MessageReceived    += (sender, args) =>
                    {
                        using (DataReader reader = args.GetDataReader())
                        {
                            reader.UnicodeEncoding = UnicodeEncoding.Utf8;

                            try
                            {
                                string read     = reader.ReadString(reader.UnconsumedBufferLength);
                                var    response = PlayerResponse.ToObject(read);
                                StatusReceived?.Invoke(response);
                            }
                            catch (Exception ex)
                            {
                                LogReceived?.Invoke(ex.Message);
                            }
                        }
                    };
                    messageWebSocket.Closed += (sender, args) =>
                    {
                        _websocketConnected = false;
                        ConnectionChanged?.Invoke(_websocketConnected);
                    };
                }

                await messageWebSocket.ConnectAsync(new Uri(WebsocketUrl));

                messageWriter = new DataWriter(messageWebSocket.OutputStream);

                _websocketConnected = true;
                ConnectionChanged?.Invoke(_websocketConnected);
                AddRegister(_registered);
            }
            catch (Exception)
            {
                _websocketConnected = false;
                ConnectionChanged?.Invoke(_websocketConnected);
                await Task.CompletedTask;
            }
        }
コード例 #23
0
            /// <summary>
            /// Gets the name of the column in the database for the specified type,
            /// using the configured <see cref="IColumnNameResolver"/>.
            /// </summary>
            /// <param name="propertyInfo">The <see cref="NonaProperty"/> to get the column name for.</param>
            /// <returns>The column name in the database for <paramref name="propertyInfo"/>.</returns>
            public static string Column(NonaProperty propertyInfo)
            {
                var key = propertyInfo.PropertyKey;

                if (!ColumnNameCache.TryGetValue(key, out var columnName))
                {
                    columnName = _columnNameResolver.Resolve(propertyInfo);
                    if (EscapeCharacterStart != char.MinValue || EscapeCharacterEnd != char.MinValue)
                    {
                        columnName = EscapeCharacterStart + columnName + EscapeCharacterEnd;
                    }
                    ColumnNameCache.TryAdd(key, columnName);
                }

                LogReceived?.Invoke($"Resolved column name '{columnName}' for '{propertyInfo.PropertyInfo}'");
                return(columnName);
            }
コード例 #24
0
            /// <summary>
            /// Gets the name of the column in the database for the specified type,
            /// using the configured <see cref="IColumnNameResolver"/>.
            /// </summary>
            /// <param name="propertyInfo">The <see cref="PropertyInfo"/> to get the column name for.</param>
            /// <returns>The column name in the database for <paramref name="propertyInfo"/>.</returns>
            public static string Column(PropertyInfo propertyInfo)
            {
                var key = $"{propertyInfo.DeclaringType}.{propertyInfo.Name}";

                if (!_columnNameCache.TryGetValue(key, out var columnName))
                {
                    columnName = _columnNameResolver.ResolveColumnName(propertyInfo);
                    if (EscapeCharacterStart != char.MinValue || EscapeCharacterEnd != char.MinValue)
                    {
                        columnName = EscapeCharacterStart + columnName + EscapeCharacterEnd;
                    }
                    _columnNameCache.TryAdd(key, columnName);
                }

                LogReceived?.Invoke($"Resolved column name '{columnName}' for '{propertyInfo.Name}'");
                return(columnName);
            }
コード例 #25
0
        private void ProcessBuffer(CancellationToken token)
        {
            LogEntry entry;

            while (!token.IsCancellationRequested)
            {
                try
                {
                    entry = lcs.ReadLogEntry();
                }
                catch (IOException)
                {
                    return;
                }
                LogReceived?.Invoke(this, entry);
            }
        }
コード例 #26
0
ファイル: ScenarioTestTypes.cs プロジェクト: aelij/wcf
    protected virtual void Dispose(bool disposing)
    {
        if (_disposed)
        {
            return;
        }

        if (disposing)
        {
            LogReceived.Dispose();
            ReceiveDataInvoked.Dispose();
            ReceiveDataCompleted.Dispose();
            ReceiveStreamInvoked.Dispose();
            ReceiveStreamCompleted.Dispose();
        }

        _disposed = true;
    }
コード例 #27
0
        private void Send()
        {
#if NETFX_CORE
            try
            {
                if (!_websocketConnected)
                {
                    return;
                }

                var req = GetActiveRequest();

                var jsonStr = req.ToJsonObject().Stringify();
                LogReceived?.Invoke("Send() " + jsonStr);
                messageWriter.WriteString(jsonStr);
                messageWriter.StoreAsync();
                _activeRequest = null;
            }
            catch (Exception e)
            {
                LogReceived?.Invoke("Send() " + e.Message);
            }
#else
            try
            {
                if (!_websocketConnected)
                {
                    Console.Write("not connected.\n");
                    return;
                }

                var msg = JSON.ToJSON(GetActiveRequest(), DEFAULT_PARAM);
                Debug.WriteLine("Send() String " + msg);
                _webSocket.SendAsync(msg, b =>
                {
                    _activeRequest = null;
                });
            }
            catch (Exception e)
            {
                Console.Write($"{e.Message} {e}\n");
            }
#endif
        }
コード例 #28
0
            /// <summary>
            /// Gets the foreign key property for the specified source type and including type
            /// using the configured <see cref="IForeignKeyPropertyResolver"/>.
            /// </summary>
            /// <param name="sourceType">The source type which should contain the foreign key property.</param>
            /// <param name="includingType">The type of the foreign key relation.</param>
            /// <param name="foreignKeyRelation">The foreign key relationship type.</param>
            /// <returns>The foreign key property for <paramref name="sourceType"/> and <paramref name="includingType"/>.</returns>
            public static PropertyInfo ForeignKeyProperty(Type sourceType, Type includingType, out ForeignKeyRelation foreignKeyRelation)
            {
                var key = $"{sourceType};{includingType}";

                if (!_typeForeignKeyPropertyCache.TryGetValue(key, out var foreignKeyInfo))
                {
                    // Resolve the property and relation.
                    var foreignKeyProperty = _foreignKeyPropertyResolver.ResolveForeignKeyProperty(sourceType, includingType, out foreignKeyRelation);

                    // Cache the info.
                    foreignKeyInfo = new ForeignKeyInfo(foreignKeyProperty, foreignKeyRelation);
                    _typeForeignKeyPropertyCache.TryAdd(key, foreignKeyInfo);
                }

                foreignKeyRelation = foreignKeyInfo.Relation;

                LogReceived?.Invoke($"Resolved property '{foreignKeyInfo.PropertyInfo}' ({foreignKeyInfo.Relation}) as foreign key between '{sourceType}' and '{includingType}'");
                return(foreignKeyInfo.PropertyInfo);
            }
コード例 #29
0
        public void Dispose()
        {
#if NETFX_CORE
            if (messageWriter != null)
            {
                // In order to reuse the socket with another DataWriter, the socket's output stream needs to be detached.
                // Otherwise, the DataWriter's destructor will automatically close the stream and all subsequent I/O operations
                // invoked on the socket's output stream will fail with ObjectDisposedException.
                //
                // This is only added for completeness, as this sample closes the socket in the very next code block.
                messageWriter.DetachStream();
                messageWriter.Dispose();
                messageWriter = null;
            }

            if (messageWebSocket != null)
            {
                try
                {
                    messageWebSocket.Close(1000, "Closed due to user request.");
                }
                catch (Exception ex)
                {
                    LogReceived?.Invoke(ex.Message);
                }
            }
#else
            try
            {
                _webSocket.CloseAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
#endif
        }
コード例 #30
0
ファイル: ScenarioTestTypes.cs プロジェクト: aelij/wcf
 public void ReceiveLog(List <string> log)
 {
     ServerLog = log;
     LogReceived.Set();
 }