Exemplo n.º 1
0
 /// <summary>
 /// Creando un grupo de objetos
 /// </summary>
 /// <param name="creator">Un objeto al que el grupo delegará
 /// la responsabilidad de crear objetos que los administre</param>
 /// <param name="maxInstances">El número máximo de instancias de clases
 /// que el grupo permite que existan al mismo tiempo
 /// </param>
 public ObjectPool(ICreation <T> creator, Int32 maxInstances)
 {
     this.creator       = creator;
     this.instanceCount = 0;
     this.maxInstances  = maxInstances;
     this.pool          = new ArrayList();
     this.semaphore     = new Semaphore(0, this.maxInstances);
 }
Exemplo n.º 2
0
        public static TCreatedBy SetCreatedBy <TCreatedBy, TCreatedTime>
            (this ICreation <TCreatedBy, TCreatedTime> creation, Func <TCreatedBy, TCreatedBy> newCreatedByFactory)
            where TCreatedBy : IEquatable <TCreatedBy>
            where TCreatedTime : struct
        {
            creation.NotNull(nameof(creation));
            newCreatedByFactory.NotNull(nameof(newCreatedByFactory));

            return(creation.CreatedBy = newCreatedByFactory.Invoke(creation.CreatedBy));
        }
Exemplo n.º 3
0
        public static void ImportCreation <TCreatedBy, TCreatedTime>(this ICreation <TCreatedBy, TCreatedTime> creation,
                                                                     string by, string time, IFormatProvider provider = null)
            where TCreatedBy : IEquatable <TCreatedBy>
            where TCreatedTime : struct
        {
            creation.NotNull(nameof(creation));

            creation.CreatedBy   = by.ToCreatedBy <TCreatedBy>(provider);
            creation.CreatedTime = time.ToCreatedTime <TCreatedTime>(provider);
        }
Exemplo n.º 4
0
    /// <summary>
    /// 填充创建属性。
    /// </summary>
    /// <typeparam name="TCreatedBy">指定的创建者类型(提供对整数、字符串、GUID 等类型的支持)。</typeparam>
    /// <param name="creation">给定的 <see cref="ICreation{TCreatedBy}"/>。</param>
    /// <param name="newCreatedBy">给定的新创建者。</param>
    /// <param name="newCreatedTime">给定的新创建日期。</param>
    /// <returns>返回 <see cref="ICreation{TCreatedBy}"/>。</returns>
    public static ICreation <TCreatedBy> PopulateCreation <TCreatedBy>(this ICreation <TCreatedBy> creation,
                                                                       TCreatedBy?newCreatedBy, DateTimeOffset newCreatedTime)
        where TCreatedBy : IEquatable <TCreatedBy>
    {
        creation.CreatedTime      = newCreatedTime;
        creation.CreatedTimeTicks = creation.CreatedTime.Ticks;
        creation.CreatedBy        = newCreatedBy;

        return(creation);
    }
Exemplo n.º 5
0
        /// <summary>
        /// 异步获取创建者。
        /// </summary>
        /// <typeparam name="TCreatedBy">指定的创建者类型。</typeparam>
        /// <typeparam name="TCreatedTime">指定的创建时间类型(兼容 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/>)。</typeparam>
        /// <param name="creation">给定的 <see cref="ICreation{TCreatedBy, TCreatedTime}"/>。</param>
        /// <param name="newCreatedByFactory">给定的新创建者工厂方法。</param>
        /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
        /// <returns>返回一个包含 <typeparamref name="TCreatedBy"/>(兼容标识或字符串)的异步操作。</returns>
        public static ValueTask <TCreatedBy> SetCreatedByAsync <TCreatedBy, TCreatedTime>
            (this ICreation <TCreatedBy, TCreatedTime> creation, Func <TCreatedBy, TCreatedBy> newCreatedByFactory,
            CancellationToken cancellationToken = default)
            where TCreatedBy : IEquatable <TCreatedBy>
            where TCreatedTime : struct
        {
            creation.NotNull(nameof(creation));

            return(cancellationToken.RunOrCancelValueAsync(()
                                                           => creation.CreatedBy = newCreatedByFactory.Invoke(creation.CreatedBy)));
        }
Exemplo n.º 6
0
        public static ICreation <TCreatedBy> PopulateCreation <TCreatedBy>
            (this ICreation <TCreatedBy> creation, IClockService clock)
            where TCreatedBy : IEquatable <TCreatedBy>
        {
            creation.NotNull(nameof(creation));
            clock.NotNull(nameof(clock));

            creation.CreatedTime      = clock.GetNowOffset();
            creation.CreatedTimeTicks = creation.CreatedTime.Ticks;

            return(creation);
        }
Exemplo n.º 7
0
    /// <summary>
    /// 异步填充创建属性。
    /// </summary>
    /// <typeparam name="TCreatedBy">指定的创建者类型(提供对整数、字符串、GUID 等类型的支持)。</typeparam>
    /// <param name="creation">给定的 <see cref="ICreation{TCreatedBy}"/>。</param>
    /// <param name="newCreatedBy">给定的新创建者。</param>
    /// <param name="newCreatedTime">给定的新创建日期。</param>
    /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
    /// <returns>返回一个包含 <see cref="ICreation{TCreatedBy}"/> 的异步操作。</returns>
    public static Task <ICreation <TCreatedBy> > PopulateCreationAsync <TCreatedBy>(this ICreation <TCreatedBy> creation,
                                                                                    TCreatedBy?newCreatedBy, DateTimeOffset newCreatedTime, CancellationToken cancellationToken = default)
        where TCreatedBy : IEquatable <TCreatedBy>
    {
        return(cancellationToken.RunTask(() =>
        {
            creation.CreatedTime = newCreatedTime;
            creation.CreatedTimeTicks = creation.CreatedTime.Ticks;
            creation.CreatedBy = newCreatedBy;

            return creation;
        }));
    }
Exemplo n.º 8
0
 /// <summary>
 /// Adds an item to the created items list
 /// </summary>
 /// <param name="item">The item to add to the list.</param>
 public void CreateItem(ICreation item)
 {
     Items.Add(item);
     _createdItemList.Add(ItemCreationMark + item.GetAssociatedPath());
     if (item is FileCreation)
     {
         FileCreation creation = item as FileCreation;
         for (int i = 0; i < creation.GetContent().Length; i++)
         {
             _createdItemList.Add(LineInsertionMark + i + LineInsertionMark + creation.GetContent()[i]);
         }
     }
     _createdItemList.Add(BlockSeparatorMark);
 }
Exemplo n.º 9
0
        public static async Task <ICreation <TCreatedBy> > PopulateCreationAsync <TCreatedBy>
            (this ICreation <TCreatedBy> creation, IClockService clock,
            CancellationToken cancellationToken = default)
            where TCreatedBy : IEquatable <TCreatedBy>
        {
            creation.NotNull(nameof(creation));
            clock.NotNull(nameof(clock));

            creation.CreatedTime = await clock.GetNowOffsetAsync(cancellationToken : cancellationToken)
                                   .ConfigureAwait();

            creation.CreatedTimeTicks = creation.CreatedTime.Ticks;

            return(creation);
        }
Exemplo n.º 10
0
        public async Task CreateEntityAsync(ICreation <TEntity> creation)
        {
            var table = await GetTable();

            var entity = new TEntity
            {
                RowKey       = new Random().Next(0, int.MaxValue).ToString(),
                PartitionKey = Program.PartitionKey
            };

            creation.Mutation.Invoke(entity);

            var operation = TableOperation.Insert(entity);

            await table.ExecuteAsync(operation);

            creation.CreatedId = int.Parse(entity.RowKey);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creando un grupo de objetos
 /// </summary>
 /// <param name="creator">Un objeto al que el grupo delegará
 /// la responsabilidad de crear objetos que los administre</param>
 public ObjectPool(ICreation <T> creator)
     : this(creator, Int32.MaxValue)
 {
 }