示例#1
0
        // Parameter is used only on release.
        // ReSharper disable once UnusedParameter.Global
        public void Update(float frameTime, IRuntimeLog runtimeLog)
        {
            if (IsActive)
            {
                _timeCounter -= (int)(frameTime * 1000);

                if (_timeCounter <= 0)
                {
#if EXCEPTION_TOLERANCE
                    try
#endif
                    {
                        OnFired();
                    }
#if EXCEPTION_TOLERANCE
                    catch (Exception e)
                    {
                        runtimeLog.LogException(e, "Timer Callback");
                    }
#endif

                    if (IsRepeating)
                    {
                        _timeCounter = Time;
                    }
                    else
                    {
                        IsActive = false;
                    }
                }
            }
        }
示例#2
0
 public GameLoop(IGameTiming timing)
 {
     _timing     = timing;
     _runtimeLog = IoCManager.Resolve <IRuntimeLog>();
 }
示例#3
0
 public RobustSynchronizationContext(IRuntimeLog runtimeLog)
 {
     _runtimeLog = runtimeLog;
 }
示例#4
0
            /// <summary>
            /// Convert a Simio Log to a DataTable
            /// </summary>
            /// <param name="model"></param>
            /// <param name="logExpressions">Information about each Custom Column</param>
            /// <param name="logs">A record for each log record of type T</param>
            /// <returns></returns>
            public static DataTable ConvertLogToDataTable <T>(IRuntimeLog <T> runtimeLog) where T : IRuntimeLogRecord
            {
                string    tableName = typeof(T).ToString();
                DataTable dt        = new DataTable(tableName);

                if (!runtimeLog.Any())
                {
                    return(dt);
                }

                try
                {
                    // Create a DataTable Column for each property of the Simio Log
                    List <string> columnNames = new List <string>();
                    foreach (PropertyInfo pi in typeof(T).GetProperties())
                    {
                        dt.Columns.Add(pi.Name);
                    }

                    // If needed, find the method the fetches the value for the custom columns using the DisplayName
                    // We'll use it below as we invoke it for each custom column in each record.
                    MethodInfo GetCustomValueMethod = null;

                    if (runtimeLog.RuntimeLogExpressions != null)
                    {
                        // ... and also create a Column for each Custom Column
                        foreach (ILogExpression logExpression in runtimeLog.RuntimeLogExpressions)
                        {
                            dt.Columns.Add(logExpression.DisplayName);
                        }

                        // If we have any runtimelogExpressions, then create a reference
                        // it the GetCustomColumnValue method, which we'll use when create a datarow.
                        if (runtimeLog.RuntimeLogExpressions.Any())
                        {
                            foreach (MethodInfo mi in typeof(T).GetMethods())
                            {
                                if (mi.Name == "GetCustomColumnValue")
                                {
                                    ParameterInfo[] parameters = mi.GetParameters();
                                    if (parameters.Length == 1)
                                    {
                                        GetCustomValueMethod = mi;
                                        goto DoneLookingForMethod;
                                    }
                                }
                                DoneLookingForMethod :;
                            }
                        } // Do we have any custom columns?
                    }     // Check if we have access to RuntimeLogRecords

                    int recordCount = 0;
                    // Create a DataRow (and add it to the DataTable) from:
                    // 1. The properties in each RuntimeLogRecord
                    // 2. The custome properties (if any) using GetCustomValueMethod
                    foreach (var record in runtimeLog)
                    {
                        recordCount += 1;
                        DataRow dr = dt.NewRow();

                        // Look at each property in the record and get its name and value (as a string)
                        foreach (PropertyInfo pi in typeof(T).GetProperties())
                        {
                            try
                            {
                                object fieldValue = pi.GetValue(record) ?? "";
                                dr[pi.Name] = fieldValue.ToString();
                            }
                            catch (Exception ex)
                            {
                                throw new ApplicationException($"Record={recordCount}. Column={pi.Name} Err={ex}");
                            }
                        } // for each property

                        // Now add the Custom columns
                        // Invoke our previously found method on the current record for each name of custom columns.
                        foreach (ILogExpression logExpression in runtimeLog.RuntimeLogExpressions)
                        {
                            string expressionName = logExpression.DisplayName;

                            try
                            {
                                object value = GetCustomValueMethod?.Invoke(record, new object[] { expressionName });
                                dr[expressionName] = value.ToString();
                            }
                            catch (Exception ex)
                            {
                                throw new ApplicationException($"Record={recordCount}. Custom Column={expressionName} Err={ex}");
                            }
                        }

                        dt.Rows.Add(dr);
                    } // for each record

                    dt.AcceptChanges();
                    return(dt);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException($"Table(Log)={tableName} Error={ex}");
                }
            } // method