예제 #1
0
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <returns>The object Value.</returns>
        internal static PartitionInformation GetFromJsonProperties(JsonReader reader)
        {
            PartitionInformation obj = null;
            var propName             = reader.ReadPropertyName();

            if (!propName.Equals("ServicePartitionKind", StringComparison.Ordinal))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is ServicePartitionKind.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("Int64Range", StringComparison.Ordinal))
            {
                obj = Int64RangePartitionInformationConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("Named", StringComparison.Ordinal))
            {
                obj = NamedPartitionInformationConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("Singleton", StringComparison.Ordinal))
            {
                obj = SingletonPartitionInformationConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServicePartitionKind.");
            }

            return(obj);
        }
예제 #2
0
        private void QueryPartition(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice)
        {
            PartitionInformation partInfo = QueryApi(pathNode, "PartitionInformation", vinfo, () => {
                return(vinfo.GetPartitionInfo(hDevice));
            }, out XmlElement partNode);

            if (partInfo == null)
            {
                return;
            }
            WriteApiResult(partNode, "Style", (int)partInfo.Style);
            WriteApiResult(partNode, "Number", partInfo.Number);
            WriteApiResult(partNode, "Offset", partInfo.Offset);
            WriteApiResult(partNode, "Length", partInfo.Length);

            switch (partInfo.Style)
            {
            case PartitionStyle.MasterBootRecord:
                MbrPartition mbrInfo = (MbrPartition)partInfo;
                WriteApiResult(partNode, "MbrType", mbrInfo.Type);
                WriteApiResult(partNode, "MbrBootable", mbrInfo.Bootable);
                WriteApiResult(partNode, "MbrOffset", mbrInfo.HiddenSectors);
                break;

            case PartitionStyle.GuidPartitionTable:
                GptPartition gptInfo = (GptPartition)partInfo;
                WriteApiResult(partNode, "GptAttributes", (long)gptInfo.Attributes);
                WriteApiResult(partNode, "GptId", gptInfo.Id.ToString());
                WriteApiResult(partNode, "GptType", gptInfo.Type.ToString());
                WriteApiResult(partNode, "GptName", gptInfo.Name);
                break;
            }
        }
예제 #3
0
        private PartitionInformation GetBackupServicePartitionInformationFromServicePartitionInformation(ServicePartitionInformation servicePartitionInformation)
        {
            PartitionInformation backupServicePartitionInformation = null;

            switch (servicePartitionInformation.Kind)
            {
            case ServicePartitionKind.Singleton:
                backupServicePartitionInformation = new SingletonPartitionInformation();
                break;

            case ServicePartitionKind.Int64Range:
                var int64RangePartitionInformation = servicePartitionInformation as Fabric.Int64RangePartitionInformation;
                ThrowIf.Null(int64RangePartitionInformation, "int64RangePartitionInformation");
                backupServicePartitionInformation = new Int64RangePartitionInformation()
                {
                    HighKey = int64RangePartitionInformation.HighKey,
                    LowKey  = int64RangePartitionInformation.LowKey
                };
                break;

            case ServicePartitionKind.Named:
                var namedPartitionInformation = servicePartitionInformation as Fabric.NamedPartitionInformation;
                ThrowIf.Null(namedPartitionInformation, "namedPartitionInformation");
                backupServicePartitionInformation = new NamedPartitionInformation()
                {
                    Name = namedPartitionInformation.Name
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(backupServicePartitionInformation);
        }
예제 #4
0
        /// <summary>
        /// Overloaded ToString function for formatting the output on the console.
        /// </summary>
        /// <param name="partitionInformation"> Object of type PartitionInformation </param>
        /// <returns>
        /// Returns formatted string.
        /// </returns>
        public static string ToString(PartitionInformation partitionInformation)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "PartitionId", partitionInformation.Id.ToString()));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "PartitionKind", partitionInformation.ServicePartitionKind));
            strBuilder.Append(Environment.NewLine);

            return(strBuilder.ToString());
        }
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, PartitionInformation obj)
        {
            var kind = obj.ServicePartitionKind;

            if (kind.Equals(ServicePartitionKind.Int64Range))
            {
                Int64RangePartitionInformationConverter.Serialize(writer, (Int64RangePartitionInformation)obj);
            }
            else if (kind.Equals(ServicePartitionKind.Named))
            {
                NamedPartitionInformationConverter.Serialize(writer, (NamedPartitionInformation)obj);
            }
            else if (kind.Equals(ServicePartitionKind.Singleton))
            {
                SingletonPartitionInformationConverter.Serialize(writer, (SingletonPartitionInformation)obj);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServicePartitionKind.");
            }
        }
        public static byte[] ConvertPartitionInformation(byte[] originalSignature, MailboxSignatureFlags originalSignatureFlags, PartitionInformation partitionInformation)
        {
            MailboxSignatureSectionsContainer mailboxSignatureSectionsContainer;

            if (originalSignatureFlags == MailboxSignatureFlags.GetLegacy)
            {
                mailboxSignatureSectionsContainer = MailboxSignatureSectionsContainer.Create(MailboxSignatureSectionType.BasicInformation, new MailboxSignatureConverter.MailboxBasicInformationSectionCreator(originalSignature));
            }
            else
            {
                mailboxSignatureSectionsContainer = MailboxSignatureSectionsContainer.Parse(originalSignature, NullMailboxSignatureSectionProcessor.Instance);
            }
            int num = partitionInformation.Serialize(null, 0);

            byte[] array = new byte[num];
            partitionInformation.Serialize(array, 0);
            mailboxSignatureSectionsContainer.UpdateSection(new MailboxSignatureSectionMetadata(MailboxSignatureSectionType.PartitionInformation, 1, 1, array.Length), array);
            return(mailboxSignatureSectionsContainer.Serialize());
        }
예제 #7
0
        private List <AddRangePartitionRequest> CheckForNeededPartitions(InsertRequest request, PartitionInformation currentPartitions)
        {
            var type = request.Items.First().GetType();

            var rangePartitionAttribute = Attribute
                                          .GetCustomAttributes(type, typeof(RangePartitionAttribute))
                                          .Cast <RangePartitionAttribute>()
                                          .FirstOrDefault();

            if (rangePartitionAttribute == null)
            {
                return(new List <AddRangePartitionRequest>());
            }

            var rangeProperty = type
                                .GetProperties()
                                .FirstOrDefault(property =>
            {
                var columnNameAttribute = Attribute
                                          .GetCustomAttributes(property, typeof(ColumnNameAttribute))
                                          .Cast <ColumnNameAttribute>()
                                          .FirstOrDefault();

                if (columnNameAttribute != null)
                {
                    return(columnNameAttribute.Name.ToLower() == rangePartitionAttribute.Column.ToLower());
                }

                return(property.Name.ToLower() == rangePartitionAttribute.Column.ToLower());
            });

            if (rangeProperty == null)
            {
                throw new Exception($"Column '{rangePartitionAttribute.Column}' not found");
            }

            var times = request.Items
                        .Select(item =>
            {
                var value = rangeProperty.GetValue(item);
                switch (value)
                {
                case DateTimeOffset time: return(time.ToUnixTimeMilliseconds());

                case DateTime time: return(new DateTimeOffset(time).ToUnixTimeMilliseconds());

                case int time: return(time);

                case long time: return(time);

                default:
                    throw new Exception($"Type '{value.GetType().Name}' is invalid for partitioning." +
                                        $" The valid types are DateTimeOffset, DateTime, long, and int");
                }
            })
                        .ToList();

            var bucketSize = (long)TimeSpan.FromDays(rangePartitionAttribute.BucketSizeInDays).TotalMilliseconds;

            var unPartitionedTimes = times
                                     .Where(time => currentPartitions.RangePartitions.All(partition => !partition.Contains(time)))
                                     .GroupBy(time => (long)Math.Floor(time / (double)bucketSize))
                                     .Select(group => group.Key)
                                     .ToList();

            return(unPartitionedTimes
                   .Select(bucketNumber =>
                           new AddRangePartitionRequest(bucketNumber * bucketSize, bucketNumber * bucketSize + bucketSize))
                   .ToList());
        }