当前位置: 首页>>代码示例>>C#>>正文


C# ICollection.AssertIsNotNull方法代码示例

本文整理汇总了C#中ICollection.AssertIsNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.AssertIsNotNull方法的具体用法?C# ICollection.AssertIsNotNull怎么用?C# ICollection.AssertIsNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICollection的用法示例。


在下文中一共展示了ICollection.AssertIsNotNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildStorageManifest

        /// <summary>
        /// Builds a StorageManifest for a large object. 
        /// The type of the manifest, static or dynamic, will be inferred based on the segments collection.
        /// </summary>
        /// <param name="containerName">The parent container name.</param>
        /// <param name="manifestName">The name of the manifest.</param>
        /// <param name="metadata">The associated metadata for the manifest.</param>
        /// <param name="segments">A collection of StorageObjects that represent the segments of the large object.</param>
        /// <param name="segmentContainer">A name of the container that contains the object segments.</param>
        /// <returns>A StorageManifest object.</returns>
        internal StorageManifest BuildStorageManifest(string containerName, string manifestName, IDictionary<string, string> metadata, ICollection<StorageObject> segments, string segmentContainer)
        {
            segments.AssertIsNotNull("segments", "Cannot build a manifest with a null segment collection.");
            if (segments.Count == 0)
            {
                throw new ArgumentException("Cannot build a manifest with an empty segment collection.", "segments");
            }

            //Based on the OpenStack Swift API 1.0 documentation:
            //1. All segments in a static large object must be at least 1MB in size (except for the last segment)
            //2. There is a max of 1000 segments.
            //3. The largest static file that can be represented by a manifest and still copied is 5GB
            var staticSegmentLimit = 1000;
            var minStaticSegmentSize = 1048576;
            var maxStaticObjectSize = 5368709120;

            var totalSize = segments.Select(s => s.Length).Sum();
            if (segments.Count() < staticSegmentLimit && HasMinSizeSegments(segments, minStaticSegmentSize) && totalSize < maxStaticObjectSize)
            {
                //If we can represent the segments using a static manifest, we should.
                return new StaticLargeObjectManifest(containerName, manifestName, segments);
            }

            return new DynamicLargeObjectManifest(containerName, manifestName, string.Format("{0}/{1}/", segmentContainer, manifestName));
        }
开发者ID:jasonzhuyx,项目名称:openstack-sdk-dotnet,代码行数:35,代码来源:LargeStorageObjectCreator.cs

示例2: HasMinSizeSegments

        /// <summary>
        /// Determines if the collection of StorageObjects meets the minimum size requirements for a static large object manifest.
        /// </summary>
        /// <param name="segments">A collection of StorageObjects.</param>
        /// <param name="minSegmentSize">The minimum size in bytes for segments.</param>
        /// <returns>A value indicating if the collection meets the minimum size criteria.</returns>
        internal bool HasMinSizeSegments(ICollection<StorageObject> segments, long minSegmentSize)
        {
            segments.AssertIsNotNull("segments", "Cannot ensure that a collection of segments meets minimum size criteria with a null segment collection.");
            var segmentsToCheck = new List<StorageObject>();
            if (segments.Count == 0)
            {
                //If the collection is empty it does not have any segments that are of the min size.
                return false;
            }

            if (segments.Count == 1)
            {
                //If the collection only has one element then it must meet the criteria (even though the spec says the last segment can be any size).
                segmentsToCheck.Add(segments.First());
            }
            else
            {
                //All segments except the last one must be large then the min size.
                segmentsToCheck.AddRange(segments.Take(segments.Count -1));
            }

            return segmentsToCheck.All(s => s.Length > minSegmentSize);
        }
开发者ID:jasonzhuyx,项目名称:openstack-sdk-dotnet,代码行数:29,代码来源:LargeStorageObjectCreator.cs

示例3: StaticLargeObjectManifest

 /// <summary>
 /// Creates a new instance of the StaticLargeObjectManifest class.
 /// </summary>
 /// <param name="containerName">The name of the parent container.</param>
 /// <param name="manifestFullName">The full name of the manifest.</param>
 /// <param name="objects">A collection of objects that are included in the manifest.</param>
 /// <param name="metadata">The metadata associated with the storage manifest.</param>
 public StaticLargeObjectManifest(string containerName, string manifestFullName, IDictionary<string, string> metadata, ICollection<StorageObject> objects)
     : base(containerName, manifestFullName, metadata)
 {
     objects.AssertIsNotNull("objects", "Cannot create a static large object manifest with a null object collection.");
     this.Objects = objects;
 }
开发者ID:jasonzhuyx,项目名称:openstack-sdk-dotnet,代码行数:13,代码来源:StaticLargeObjectManifest.cs


注:本文中的ICollection.AssertIsNotNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。