/// <summary>
 /// Initialize Unit Kills History Model with DataReader
 /// </summary>
 /// <param name="reader">The DataReader</param>
 public SQLiteUnitKillsHistoryModel(IDataReader reader)
 {
     try
     {
         if (reader == null)
         {
             throw new ArgumentNullException("reader");
         }
         RealizeColumnMappings(reader);
         ID            = reader.GetInt64(_indexID);
         PlayerName    = reader.GetString(_indexPlayerName);
         EffectiveDate = DateUtility.EpochToDate(reader.GetDouble(_indexEffectiveDate));
         Score         = reader.GetInt64(_indexScore);
         Rank          = reader.GetInt32(_indexRank);
     }
     catch (Exception caught)
     {
         logger.Error("Unexpected Error Initializing SQLite Unit Kills History model", caught);
         throw;
     }
 }
示例#2
0
        /// <summary>
        /// Build External Macro Model
        /// </summary>
        /// <param name="qualifiedName">Qualified Macro Name</param>
        /// <param name="noxMacroDefinition">The Nox Macro Definition</param>
        /// <returns>The External Macro Model</returns>
        private IExternalMacroModel BuildExternalMacroModel(string qualifiedName, Models.Json.NoxMacroHeaderModel noxMacroDefinition)
        {
            try
            {
                var externalModel = new Models.NoxExternalMacroModelImpl();
                externalModel.QualifiedName = qualifiedName;
                externalModel.FriendlyName  = noxMacroDefinition.name;

                int parsePriorityOut;
                externalModel.ListOrder = int.TryParse(noxMacroDefinition.priority, out parsePriorityOut) ? parsePriorityOut : 0;

                /*
                 * The Create Date in Nox is stored as an epoch time stamp.
                 * If this value isn't sored correctly (it cannot parse to a double) just stick now in.
                 * Note that Epoch stores in UTC, not sure if its really relevant in Nox, but I'm choosing
                 * to store a fallback of now, in UTC in case it does compensate for that.
                 */
                double parseTimeOut;
                externalModel.CreateDate = double.TryParse(noxMacroDefinition.time, out parseTimeOut) ? DateUtility.EpochToDate(parseTimeOut) : DateTime.UtcNow;


                //The path to the macro source file, is simply the Nox Macro Directory, and the filename is the qualified name
                externalModel.SourceFileName = Path.Combine(Environment.GetNoxMacroDirectory(), qualifiedName);

                /*
                 * For a source of the macro, which will be cached in the database, we simply read the contents of the macro file
                 * If unable to read this file for any reason, log that, and then just set the macro source to null.
                 * It's techncially fine for this software to not have a macro source file, as this tool rebuilds the source after
                 * user modifications.  So this would just net in a new or empty macro
                 */
                try
                {
                    externalModel.MacroSource = File.ReadAllText(externalModel.SourceFileName);
                }
                catch (Exception caught)
                {
                    logger.Warn("Unable to read macro source file", caught);
                    externalModel.MacroSource = null;
                }

                /*
                 * TODO: Review this; it just kind of dawned on me that the values for play settings will be different if more than
                 * one emulator is used.  So it would definately make more sense to break the play settings down, from within the application management
                 * definately something to look into.
                 *
                 * This, which I view as a pretty high proprity thing to do; is not yet critical, as I don't think many have multiple emulators
                 * that they frequently use.  I'd just not like to corrupt a macro records file with foreign values,
                 * and potentially risk unexpected behavior. (potentially crashing?)
                 */

                /*
                 * The play settings are a separate object, and it's therefor technically
                 * possible that it's not present.  If the play settings are not present, just
                 * stick some good default for the affected values.
                 */
                var playSettings = noxMacroDefinition.playSet;
                if (playSettings == null)
                {
                    externalModel.Accelerator = "1";
                    externalModel.Interval    = "0";
                    externalModel.Mode        = "0";
                    externalModel.PlaySeconds = "0#0#0";
                    externalModel.RepeatTimes = "1";
                }
                else
                {
                    externalModel.Accelerator = playSettings.accelerator;
                    externalModel.Interval    = playSettings.interval;
                    externalModel.Mode        = playSettings.mode;
                    externalModel.PlaySeconds = playSettings.playSeconds;
                    externalModel.RepeatTimes = playSettings.repeatTimes;
                }

                //TODO: VALIDATE SOURCE, ENSURE ASSEMBLER IS SUPPORTED!

                return(externalModel);
            }
            catch (Exception caught)
            {
                logger.Error("Unexpected Error Building External Macro Model", caught);
                throw;
            }
        }