internal static unsafe ServiceGroupDescription CreateFromNative(NativeClient.IFabricServiceGroupDescriptionResult nativeResult)
        {
            if (nativeResult == null)
            {
                return(null);
            }

            var nativeDescription        = (NativeTypes.FABRIC_SERVICE_GROUP_DESCRIPTION *)nativeResult.get_Description();
            var nativeServiceDescription = (NativeTypes.FABRIC_SERVICE_DESCRIPTION *)nativeDescription->Description;

            ServiceDescription serviceDescription = ServiceDescription.CreateFromNative(nativeDescription->Description);

            bool isStateful = (serviceDescription.Kind == ServiceDescriptionKind.Stateful);

            ServiceGroupDescription description = new ServiceGroupDescription(serviceDescription);

            var members = (NativeTypes.FABRIC_SERVICE_GROUP_MEMBER_DESCRIPTION *)nativeDescription->MemberDescriptions;

            for (int i = 0; i < nativeDescription->MemberCount; ++i)
            {
                var memberDescription = ServiceGroupMemberDescription.CreateFromNative((IntPtr)(members + i), isStateful);
                description.MemberDescriptions.Add(memberDescription);
            }

            GC.KeepAlive(nativeResult);

            return(description);
        }
 internal static void Validate(ServiceGroupDescription description)
 {
     Requires.Argument <ServiceDescription>("ServiceDescription", description.ServiceDescription).NotNull();
     ServiceDescription.Validate(description.ServiceDescription);
     foreach (ServiceGroupMemberDescription memberDescription in description.MemberDescriptions)
     {
         ServiceGroupMemberDescription.Validate(memberDescription);
     }
 }
        internal static void Validate(ServiceGroupMemberDescription serviceGroupMemberDescription)
        {
            Requires.Argument <Uri>("serviceGroupMemberDescription.Name", serviceGroupMemberDescription.ServiceName).NotNullOrWhiteSpace();
            Requires.Argument <string>("serviceGroupMemberDescription.ServiceTypeName", serviceGroupMemberDescription.ServiceTypeName).NotNullOrWhiteSpace();

            foreach (var metric in serviceGroupMemberDescription.Metrics)
            {
                ServiceLoadMetricDescription.Validate(metric);
            }
        }
        internal static unsafe ServiceGroupMemberDescription CreateFromNative(IntPtr nativeDescriptionPtr, bool isStateful)
        {
            var nativeDescription = (NativeTypes.FABRIC_SERVICE_GROUP_MEMBER_DESCRIPTION *)nativeDescriptionPtr;

            var description = new ServiceGroupMemberDescription
            {
                ServiceName        = NativeTypes.FromNativeUri(nativeDescription->ServiceName),
                ServiceTypeName    = NativeTypes.FromNativeString(nativeDescription->ServiceTypeName),
                InitializationData = NativeTypes.FromNativeBytes(nativeDescription->InitializationData, nativeDescription->InitializationDataSize),
            };

            var nativeMetrics = (NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION *)nativeDescription->Metrics;

            for (int i = 0; i < (int)nativeDescription->MetricCount; i++)
            {
                var item = ServiceLoadMetricDescription.CreateFromNative((IntPtr)(nativeMetrics + i), isStateful);
                description.Metrics.Add(item);
            }

            return(description);
        }