Esempio n. 1
0
        public static T InsertAndCheckRowKey <T>(this INoSQLTableStorage <T> table, T entity, Func <string> generateRowKey) where T : ITableEntity, new()
        {
            var no = 0;

            while (true)
            {
                entity.RowKey = generateRowKey();

                try
                {
                    table.Insert(entity);
                    return(entity);
                }
                catch (StorageException e)
                {
                    if (e.RequestInformation.HttpStatusCode != Conflict)
                    {
                        throw;
                    }
                }

                if (no == 999)
                {
                    throw new Exception("Can not insert record InsertAndCheckRowKey: " + PrintItem(entity));
                }
                no++;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Перебирает по одному ключу, пока не получится вставить запись в таблицу
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table"></param>
        /// <param name="entity"></param>
        /// <param name="dateTime"></param>
        /// <param name="rowKeyDateTimeFormat">Формат ключа</param>
        /// <returns></returns>
        public static T InsertAndGenerateRowKeyAsDateTime <T>(this INoSQLTableStorage <T> table, T entity, DateTime dateTime, RowKeyDateTimeFormat rowKeyDateTimeFormat = RowKeyDateTimeFormat.Iso) where T : ITableEntity, new()
        {
            var dt = dateTime.ToString(rowKeyDateTimeFormat.ToDateTimeMask());
            var no = 0;

            while (true)
            {
                entity.RowKey = dt + no.ToDateTimeSuffix(rowKeyDateTimeFormat);

                try
                {
                    table.Insert(entity, Conflict);
                    return(entity);
                }
                catch (StorageException e)
                {
                    if (e.RequestInformation.HttpStatusCode != Conflict)
                    {
                        throw;
                    }
                }

                if (no == 999)
                {
                    throw new Exception("Can not insert record: " + PrintItem(entity));
                }
                no++;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Перебирает по одному ключу, пока не получится вставить запись в таблицу
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="table"></param>
        /// <param name="entity"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static T InsertAndGenerateRowKeyAsTime <T>(this INoSQLTableStorage <T> table, T entity, DateTime dateTime) where T : ITableEntity, new()
        {
            var dt = dateTime.ToString("HH:mm:ss");
            var no = 0;

            while (true)
            {
                entity.RowKey = dt + '.' + no.ToString("000");

                try
                {
                    table.Insert(entity);
                    return(entity);
                }
                catch (StorageException e)
                {
                    if (e.RequestInformation.HttpStatusCode != Conflict)
                    {
                        throw;
                    }
                }

                if (no == 999)
                {
                    throw new Exception("Can not insert record InsertAndGenerateRowKeyAsTime: " + PrintItem(entity));
                }
                no++;
            }
        }