Пример #1
0
 protected Repository(
     IDatabaseReader <TEntity> databaseReader,
     IDatabaseWriter <TEntity> databaseWriter)
 {
     DatabaseReader = databaseReader;
     DatabaseWriter = databaseWriter;
 }
        protected override ChatRoomInformation ParseItemFromDatabase(IDatabaseReader databaseReader)
        {
            string roomName = databaseReader.GetString((int)ValueIndex.RoomName);

            byte[] participantsRaw = databaseReader.GetBlob((int)ValueIndex.Participants);

            string[] participants;
            try
            {
                participants = BPListParser.ParseBPListStrings(participantsRaw);
            }
            catch (FormatException ex)
            {
                List <string> bytesAsStrings = new List <string>(participantsRaw.Length);
                foreach (byte participantsRawByte in participantsRaw)
                {
                    bytesAsStrings.Add(string.Format("0x{0:X2}", participantsRawByte));
                }
                string bytesString = "{" + string.Join(", ", bytesAsStrings) + "}";

                throw new FormatException("Could not parse bpList: " + bytesString, ex);
            }

            return(new ChatRoomInformation(roomName, participants));
        }
Пример #3
0
 public EmployeeRepository(ILogger <EmployeeRepository> logger, IDatabaseReader databaseReader)
 {
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     _databaseReader = databaseReader ?? throw new ArgumentNullException(nameof(databaseReader));
     _entityMapper   = new FluentEntityMapper <Employee>(
         new EmployeeMappingConfiguration());
 }
Пример #4
0
        protected override ChatRoomInformation ParseItemFromDatabase(IDatabaseReader databaseReader)
        {
            string roomName     = databaseReader.GetString((int)ValueIndexiOS6.RoomName);
            string participants = databaseReader.GetString((int)ValueIndexiOS6.HandleId);

            return(new ChatRoomInformation(roomName, new string[] { participants }));
        }
Пример #5
0
        protected override TextMessage ParseItemFromDatabase(IDatabaseReader databaseReader)
        {
            long messageId = databaseReader.GetInt64((int)ValueIndex.MessageId);

            if (messageId < 0)
            {
                throw new ArgumentOutOfRangeException("Message ID cannot be negative.");
            }

            string address         = databaseReader.GetString((int)ValueIndex.Address);
            string country         = databaseReader.GetString((int)ValueIndex.Country);
            long   timestampUnix   = databaseReader.GetInt64((int)ValueIndex.Timestamp);
            string messageContents = databaseReader.GetString((int)ValueIndex.MessageContents);
            long   flagsRaw        = databaseReader.GetInt64((int)ValueIndex.Flags);

            TextMessageFlags flags;

            //
            // Take the int part of the long (intentionally truncate the raw flags value)
            //

            int flagsInt = (int)(flagsRaw & ((long)int.MaxValue));

            flags = (TextMessageFlags)flagsInt;

            return(new TextMessage(messageId,
                                   (flags & TextMessageFlags.Outgoing) != 0,
                                   UnixTimeToLocalTime(timestampUnix),
                                   messageContents,
                                   address,
                                   country));
        }
Пример #6
0
 public RouteFinder(IRouteExplorer routeExplorer, IShortestRouteFinder shortestRouteFinder, IDatabaseReader databaseReader, IRouteValidator routeValidator)
 {
     this.routeExplorer       = routeExplorer;
     this.shortestRouteFinder = shortestRouteFinder;
     this.databaseReader      = databaseReader;
     this.routeValidator      = routeValidator;
 }
Пример #7
0
        protected override TextMessage ParseItemFromDatabase(IDatabaseReader databaseReader)
        {
            long messageId = databaseReader.GetInt64((int)ValueIndex.MessageId);
            if (messageId < 0)
            {
                throw new ArgumentOutOfRangeException("Message ID cannot be negative.");
            }

            string address = databaseReader.GetString((int)ValueIndex.Address);
            string country = databaseReader.GetString((int)ValueIndex.Country);
            long timestampUnix = databaseReader.GetInt64((int)ValueIndex.Timestamp);
            string messageContents = databaseReader.GetString((int)ValueIndex.MessageContents);
            long flagsRaw = databaseReader.GetInt64((int)ValueIndex.Flags);

            TextMessageFlags flags;

            //
            // Take the int part of the long (intentionally truncate the raw flags value)
            //

            int flagsInt = (int)(flagsRaw & ((long)int.MaxValue));
            flags = (TextMessageFlags)flagsInt;

            return new TextMessage(messageId,
                                   (flags & TextMessageFlags.Outgoing) != 0,
                                   UnixTimeToLocalTime(timestampUnix),
                                   messageContents,
                                   address,
                                   country);
        }
Пример #8
0
 public void RunQuery(object query, Action <IDatabaseReader> action, params IDatabaseParameter[] @params)
 {
     RunCommand(query, comm => {
         using IDatabaseReader reader = comm.ExecuteReader();
         action.Invoke(reader);
     }, @params);
 }
 public DatabaseConverterService(IValidator <string> validator, IReader <string> reader,
                                 IWriter <string> writer, IDatabaseReader <Tuple <int, string, int, double> > dbReader)
 {
     this.validator = validator;
     this.reader    = reader;
     this.writer    = writer;
     this.dbReader  = dbReader;
 }
Пример #10
0
 public ADOMessageChannel(IDatabaseReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     ChannelId = reader.ReadString(@"msg_channel_id");
 }
Пример #11
0
 public MainWindow(IContainer container)
 {
     InitializeComponent();
     _container = container;
     _episodeSearcher = _container.GetInstance<IEpisodeSearcher>();
     _dbReader = _container.GetInstance<IDatabaseReader>();
     Loaded += MainWindow_Loaded;
 }
Пример #12
0
 public Startup(IConsoleReader consoleReader,
                IDatabaseReader databaseReader,
                ILegacyBuilderMaterialGenerator legacyBuilderInputGenerator)
 {
     this.consoleReader  = consoleReader;
     this.databaseReader = databaseReader;
     this.legacyBuilderInputGenerator = legacyBuilderInputGenerator;
 }
Пример #13
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         m_reader.Dispose();
         m_reader = null;
     }
 }
Пример #14
0
        public static TextMessage SingleMessageFromDatabase(IDatabaseReader databaseReader)
        {
            TextMessageReader2 messageReader = new TextMessageReader2(null);

            messageReader.ParseDatabase(databaseReader);
            Assert.AreEqual(1, messageReader.ItemCountEstimate);
            return(TextMessageReaderTest.SingleMessageFromReader(messageReader));
        }
Пример #15
0
        protected override List <ChatRoomInformation> ParseItemsFromDatabase(IDatabaseReader databaseReader)
        {
            List <ChatRoomInformation> ungroupedChatInfoItems = base.ParseItemsFromDatabase(databaseReader);

            List <ChatRoomInformation> coalescedChatInfoItems = CoalesceChatRoomInformation(ungroupedChatInfoItems);

            return(coalescedChatInfoItems);
        }
Пример #16
0
 private Category CreateCategoryFromReader(IDatabaseReader reader)
 {
     return(new Category()
     {
         Id = reader.GetValue <int>("id"),
         Name = reader.GetValue <string>("name"),
         Total = reader.GetValue <long>("total")
     });
 }
        public static TextMessage SingleMessageFromDatabase(IDatabaseReader databaseReader)
        {
            TextMessageReaderiOS6_Accessor messageReader = new TextMessageReaderiOS6_Accessor(_MockBackupPath);
            messageReader.ParseDatabase(databaseReader);

            List<TextMessage> messages = new List<TextMessage>(messageReader);

            return messages[0];
        }
Пример #18
0
        /// <summary>
        /// Sets the entity identifier asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Couldn't retrieve entity auto increment property.</exception>
        private async Task SetEntityIdAsync(object entity, IDatabaseReader reader)
        {
            if (!await reader.ReadAsync())
            {
                throw new Exception("Couldn't retrieve entity auto increment property.");
            }

            this.Descriptor.IdentityProperty.PropertyInfo.SetValue(entity, Convert.ToInt32(reader.GetValue(0)));
        }
Пример #19
0
        public static TextMessage SingleMessageFromDatabase(IDatabaseReader databaseReader)
        {
            TextMessageReaderiOS6_Accessor messageReader = new TextMessageReaderiOS6_Accessor(_MockBackupPath);

            messageReader.ParseDatabase(databaseReader);

            List <TextMessage> messages = new List <TextMessage>(messageReader);

            return(messages[0]);
        }
Пример #20
0
        private int GetItemCountEstimate(IDatabaseReader databaseReader)
        {
            int countEstimate;

            databaseReader.ExecuteQuery(DataCountQuery);
            databaseReader.Read();
            countEstimate = databaseReader.GetInt32(0);

            return(countEstimate);
        }
Пример #21
0
        public UserRepo(ILogger <UserRepo> logger, IDatabaseReader databaseReader, ICache cache, IMemoryLockManager memoryLockManager)
            : base(logger, databaseReader, cache, memoryLockManager)
        {
            _databaseReader = databaseReader;

            EntityUpdating += (sender, args) =>
            {
                sender.SecurityStamp = SecurityUtil.CreateUniqueToken();
                return(Task.CompletedTask);
            };
        }
Пример #22
0
 private Product CreateProductFromReader(IDatabaseReader reader)
 {
     return(new Product()
     {
         Id = reader.GetValue <int>("id"),
         Article = reader.GetValue <string>("article"),
         Name = reader.GetValue <string>("name"),
         Count = reader.GetValue <decimal>("count"),
         Price = reader.GetValue <decimal>("price")
     });
 }
Пример #23
0
        protected DatabaseRepository(ILogger logger, IDatabaseReader databaseReader, ICache cache, IMemoryLockManager memoryLockManager)
        {
            Logger            = logger;
            Cache             = cache;
            MemoryLockManager = memoryLockManager;

            //Dirty trick
            Database = (IDatabase)databaseReader;

            Logger.LogInformation($"{GetType().Name} 初始化完成");
        }
Пример #24
0
 public NewFileHandler(IBus bus, IDatabaseReader databaseReader)
 {
     _bus = bus;
     _databaseReader = databaseReader;
     _fsWatcher = new FileSystemWatcher (ConfigurationManager.AppSettings["pathToWatch"])
     {
         EnableRaisingEvents = true,
         Filter = ConfigurationManager.AppSettings["fileFilter"],
         IncludeSubdirectories = false
     };
 }
        /// <summary>
        /// Gets a list of objects mapped from a database reader.
        /// </summary>
        /// <param name="reader">A database reader cursor.</param>
        /// <returns>A list of mapped objects.</returns>
        public async Task <List <object> > MapAsync(IDatabaseReader reader)
        {
            var list = new List <object>();

            while (await reader.ReadAsync())
            {
                list.Add(await this.MapRowAsync(reader));
            }

            return(list);
        }
Пример #26
0
        public CmsStaticRuntimePackage(
            IPackageDependenciesFactory dependencies,
            IConfigurationStore configurationStore,
            IDatabaseReader databaseReader)
        {
            _dependencies = dependencies;
            _database     = databaseReader;
            _config       = configurationStore.Register(CmsConfiguration.Path, ConfigurationChanged, new CmsConfiguration());

            Name          = "cms";
            NamespaceName = "cms";
        }
Пример #27
0
 public ADOMessageUser(IDatabaseReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     UserId      = reader.ReadI64(@"msg_sender_id");
     UserName    = reader.ReadString(@"msg_sender_name");
     Colour      = new Colour(reader.ReadI32(@"msg_sender_colour"));
     Rank        = reader.ReadI32(@"msg_sender_rank");
     NickName    = reader.IsNull(@"msg_sender_nick") ? null : reader.ReadString(@"msg_sender_nick");
     Permissions = (UserPermissions)reader.ReadI32(@"msg_sender_perms");
 }
Пример #28
0
        /// <summary>
        /// Maps one single row from the <see cref="IDatabaseReader"/>.
        /// </summary>
        /// <param name="reader">A database reader cursor.</param>
        /// <returns>A new instance of the known object type already mapped.</returns>
        /// <remarks>This method do not advance the reading cursor.</remarks>
        protected virtual object MapRow(IDatabaseReader reader)
        {
            // TODO: maybe we could add an option to allow map by index instead of name. Should be even faster.
            var entity = Activator.CreateInstance(this.Descriptor.Type);

            foreach (var property in this.Descriptor.AllProperties)
            {
                var value = reader.GetValue(property.ColumnName);
                property.PropertyInfo.SetValue(entity, this.ValueConverter.ConvertTo(value, property.NotNullablePropertyType));
            }

            return(entity);
        }
Пример #29
0
        public static Trie <T> LoadFromDb(IDatabaseReader reader)
        {
            var data = reader.LoadData <T>();

            var trie = new Trie <T>();

            foreach (var keyValuePair in data)
            {
                trie.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(trie);
        }
Пример #30
0
        public void Start()
        {
            m_databaseFileWriter = m_writerFactory(FileName);
            m_databaseFileReader = m_readerFactory(FileName);

            m_cacheProvider = m_cacheProviderFactory(FileName);

            ulong timestamp;

            m_documentStore = new DocumentStore(m_databaseFileReader.GetDocuments(out timestamp));

            DBTimeStamp = timestamp;
        }
Пример #31
0
        /// <summary>
        /// Processes the data reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private async Task ProcessDataReaderAsync(IDatabaseReader reader)
        {
            // iterate over all the batch steps.
            foreach (var result in this.Steps)
            {
                // call the callback and consume the resultset.
                await result.BatchResultCallbackAsync.Invoke(reader);

                if (!await reader.NextResultAsync())
                {
                    break;
                }
            }
        }
        protected override TripParticipant CreateValueFromReader(IDatabaseReader reader)
        {
            var tripParticipant = new TripParticipant
                                  (
                reader.GetInt("TRPIDT"),
                reader.GetString("USRPSD"),
                ConverterHelper.YesNoStringToBool(reader.GetString("INDUSRPTP")),
                reader.GetDouble("TRPNOT"),
                reader.GetNullableDate("VALDAT")
                                  );

            tripParticipant.ModificationDate = reader.GetDate("DATEFT");
            return(tripParticipant);
        }
        #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

        /// <summary>
        /// Maps one row to an object.
        /// </summary>
        /// <param name="reader">An open database reader cursor.</param>
        /// <returns>A new instance.</returns>
        protected override object MapRow(IDatabaseReader reader)
        {
            var entity = new TrackingData(this.ServiceProvider);

            entity.FirstName       = reader.IsDBNull(0) ? default(string) : reader.GetString(0);
            entity.Heat            = reader.GetDouble(1);
            entity.LastName        = reader.IsDBNull(2) ? default(string) : reader.GetString(2);
            entity.Location        = reader.IsDBNull(3) ? default(string) : reader.GetString(3);
            entity.Speed           = reader.GetDouble(4);
            entity.TelepathyPowers = reader.GetInt32(5);
            entity.Timestamp       = reader.GetFieldValue <DateTimeOffset>(6);

            return(entity);
        }
Пример #34
0
        /// <summary>
        /// Processes the data reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void ProcessDataReader(IDatabaseReader reader)
        {
            // iterate over all the batch steps.
            foreach (var result in this.Steps)
            {
                // call the callback and consume the resultset.
                result.BatchResultCallback.Invoke(reader);

                if (!reader.NextResult())
                {
                    break;
                }
            }
        }
Пример #35
0
        protected override TextMessage ParseItemFromDatabase(IDatabaseReader databaseReader)
        {
            long isMadridRaw = databaseReader.GetInt64((int)MadridValueIndex.IsMadrid);
            bool isMadrid = (isMadridRaw == 1);
            if (!isMadrid)
            {
                return base.ParseItemFromDatabase(databaseReader);
            }

            long messageId = databaseReader.GetInt64((int)ValueIndex.MessageId);
            long timestampMadrid = databaseReader.GetInt64((int)ValueIndex.Timestamp);
            string messageContents = databaseReader.GetString((int)ValueIndex.MessageContents);
            string madridRoomName = databaseReader.GetString((int)MadridValueIndex.MadridRoomName);
            string madridHandle = databaseReader.GetString((int)MadridValueIndex.Handle);
            long madridFlagsRaw = databaseReader.GetInt64((int)MadridValueIndex.Flags);
            long timestampMadridRead = databaseReader.GetInt64((int)MadridValueIndex.DateRead);
            long timestampMadridDelivered = databaseReader.GetInt64((int)MadridValueIndex.DateDelivered);

            TextMessageMadridFlags madridFlags;
            int madridFlagsInt = (int)(madridFlagsRaw & ((long)int.MaxValue));
            madridFlags = (TextMessageMadridFlags)madridFlagsInt;
            bool isOutgoing = ((madridFlags & TextMessageMadridFlags.UnknownFlag3) != 0) ||
                              ((madridFlags & TextMessageMadridFlags.UnknownFlag6) != 0);

            messageContents = SanitizeMessageContents(messageContents);

            long timestampToConvert = timestampMadrid;
            if (!isOutgoing && (timestampMadridRead != 0))
            {
                timestampToConvert = timestampMadridRead;
            }

            DateTime timestamp = IMessageTimeToLocalTime(timestampToConvert);

            return new TextMessage(messageId,
                                   isOutgoing,
                                   timestamp,
                                   messageContents,
                                   madridHandle,
                                   madridRoomName,
                                   null,
                                   null);
        }
Пример #36
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            mediaDataBase = new MediaDatabase();
            db = new IPod5GDbReader(mediaDataBase);

            //Ask for the iTunesDB the first time the application is loaded.
            if ((ISavr.Properties.Settings.Default.iPodControlDir.Equals("")) || (ISavr.Properties.Settings.Default.DriveLetter.Equals("")))
            {
                MessageBox.Show("Welcome to iSavr!\nAs this is the first time you have loaded the application, you will need to point me to your iTunes Database file!", "Welcome to iSavr!");
                showPreferencesForm();
            }
            try
            {
                reloadDatabase();
            }
            catch (Exception)
            {
                //loop forever until we have a database!
                while (true)
                {
                    DialogResult result = MessageBox.Show("Cannot access iTunes Database - check that your iPod is connected.", "Error Reading Database", MessageBoxButtons.RetryCancel);
                    if (result == DialogResult.Retry)
                    {
                        try
                        {
                            reloadDatabase();
                            break;
                        }
                        catch (Exception)
                        {
                            //go around again!
                        }

                    }
                    else if (result == DialogResult.Cancel)
                    {
                        break;
                    }
                }

            }
        }
Пример #37
0
        public void Stop()
        {
            m_databaseFileWriter.Dispose();
            m_databaseFileWriter = null;

            m_databaseFileReader.Dispose();
            m_databaseFileReader = null;

            m_documentStore = null;

            m_pendingTransaction.Clear();
            m_pendingTransaction = null;

            m_currentTransactionId = 0;
            DBTimeStamp = 0;
        }
Пример #38
0
        protected override TextMessage ParseItemFromDatabase(IDatabaseReader databaseReader)
        {
            long messageId = databaseReader.GetInt64((int)ValueIndex.RowId);
            string handleId = databaseReader.GetString((int)ValueIndex.HandleId);
            string chatIndentifier = databaseReader.GetString((int)ValueIndex.ChatIdentifier);
            string messageContents = databaseReader.GetString((int)ValueIndex.Text);
            string country = databaseReader.GetString((int)ValueIndex.Country);
            string service = databaseReader.GetString((int)ValueIndex.Service);
            long date = databaseReader.GetInt64((int)ValueIndex.Date);
            long dateRead = databaseReader.GetInt64((int)ValueIndex.DateRead);
            long dateDelivered = databaseReader.GetInt64((int)ValueIndex.DateDelivered);
            long isFromMe = databaseReader.GetInt64((int)ValueIndex.IsFromMe);
            string attachmentPath = databaseReader.GetString((int)ValueIndex.AttachmentFilename);
            string attachmentMimeType = databaseReader.GetString((int)ValueIndex.AttachmentMimeType);

            bool isOutgoing = (isFromMe != 0);

            messageContents = SanitizeMessageContents(messageContents);

            long timestampToConvert = date;
            if (!isOutgoing && string.Equals(service, iMessageServiceIdentifier) && (dateRead != 0))
            {
                timestampToConvert = dateRead;
            }

            DateTime timestamp = IMessageTimeToLocalTime(timestampToConvert);

            string chatId;
            string address;
            if (chatIndentifier.StartsWith("chat"))
            {
                if (isOutgoing)
                {
                    address = null;
                }
                else
                {
                    address = handleId;
                }
                chatId = chatIndentifier;
            }
            else
            {
                address = handleId;
                chatId = null;
            }

            IMessageAttachment attachment;
            try
            {
                attachment = CreateMessageAttachment(messageId, attachmentPath, attachmentMimeType);
            }
            catch
            {
                attachment = null;
            }

            return new TextMessage(messageId,
                                   isOutgoing,
                                   timestamp,
                                   messageContents,
                                   address,
                                   chatId,
                                   country,
                                   attachment);
        }
Пример #39
0
        public void Start()
        {
            m_databaseFileWriter = m_writerFactory(FileName);
            m_databaseFileReader = m_readerFactory(FileName);

            m_cacheProvider = m_cacheProviderFactory(FileName);

            ulong timestamp;

            m_documentStore = new DocumentStore(m_databaseFileReader.GetDocuments(out timestamp));

            DBTimeStamp = timestamp;
        }