internal static new unsafe StatefulServiceDescription CreateFromNative(IntPtr native)
        {
            ReleaseAssert.AssertIfNot(native != IntPtr.Zero, StringResources.Error_NullNativePointer);

            var casted = (NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION *)native;

            var description = new StatefulServiceDescription();

            description.ApplicationName            = NativeTypes.FromNativeUri(casted->ApplicationName);
            description.ServiceName                = NativeTypes.FromNativeUri(casted->ServiceName);
            description.ServiceTypeName            = NativeTypes.FromNativeString(casted->ServiceTypeName);
            description.PartitionSchemeDescription = PartitionSchemeDescription.CreateFromNative(casted->PartitionScheme, casted->PartitionSchemeDescription);
            description.TargetReplicaSetSize       = casted->TargetReplicaSetSize;
            description.MinReplicaSetSize          = casted->MinReplicaSetSize;
            description.PlacementConstraints       = NativeTypes.FromNativeString(casted->PlacementConstraints);
            description.HasPersistedState          = NativeTypes.FromBOOLEAN(casted->HasPersistedState);
            description.InitializationData         = NativeTypes.FromNativeBytes(casted->InitializationData, casted->InitializationDataSize);
            description.ParseCorrelations(casted->CorrelationCount, casted->Correlations);
            description.ParseLoadMetrics(casted->MetricCount, casted->Metrics);

            if (casted->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex1 = (NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX1 *)casted->Reserved;

            if (ex1->PolicyList != IntPtr.Zero)
            {
                var pList = (NativeTypes.FABRIC_SERVICE_PLACEMENT_POLICY_LIST *)ex1->PolicyList;
                description.ParsePlacementPolicies(pList->PolicyCount, pList->Policies);
            }

            if (ex1->FailoverSettings != IntPtr.Zero)
            {
                var failoverSettings = (NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS *)ex1->FailoverSettings;

                if ((failoverSettings->Flags & (uint)NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_REPLICA_RESTART_WAIT_DURATION) != 0)
                {
                    description.ReplicaRestartWaitDuration = TimeSpan.FromSeconds(failoverSettings->ReplicaRestartWaitDurationSeconds);
                }

                if ((failoverSettings->Flags & (uint)NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_QUORUM_LOSS_WAIT_DURATION) != 0)
                {
                    description.QuorumLossWaitDuration = TimeSpan.FromSeconds(failoverSettings->QuorumLossWaitDurationSeconds);
                }

                if (failoverSettings->Reserved != IntPtr.Zero)
                {
                    var failoverSettingsEx1 = (NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_EX1 *)failoverSettings->Reserved;
                    if (failoverSettingsEx1 == null)
                    {
                        throw new ArgumentException(StringResources.Error_UnknownReservedType);
                    }

                    if ((failoverSettings->Flags & (uint)NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_STANDBY_REPLICA_KEEP_DURATION) != 0)
                    {
                        description.StandByReplicaKeepDuration = TimeSpan.FromSeconds(failoverSettingsEx1->StandByReplicaKeepDurationSeconds);
                    }
                }
            }

            if (ex1->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex2 = (NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX2 *)ex1->Reserved;

            if (NativeTypes.FromBOOLEAN(ex2->IsDefaultMoveCostSpecified))
            {
                // This will correctly set the property IsDefaultMoveCostSpecified to true if move cost is valid.
                description.ParseDefaultMoveCost(ex2->DefaultMoveCost);
            }

            if (ex2->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex3 = (NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX3 *)ex2->Reserved;

            description.ServicePackageActivationMode = InteropHelpers.FromNativeServicePackageActivationMode(ex3->ServicePackageActivationMode);
            description.ServiceDnsName = NativeTypes.FromNativeString(ex3->ServiceDnsName);

            if (ex3->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex4 = (NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX4 *)ex3->Reserved;

            description.ParseScalingPolicies(ex4->ScalingPolicyCount, ex4->ServiceScalingPolicies);

            return(description);
        }
        internal static new unsafe StatelessServiceDescription CreateFromNative(IntPtr native)
        {
            ReleaseAssert.AssertIfNot(native != IntPtr.Zero, StringResources.Error_NullNativePointer);

            var casted = (NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION *)native;

            var description = new StatelessServiceDescription();

            description.ApplicationName            = NativeTypes.FromNativeUri(casted->ApplicationName);
            description.ServiceName                = NativeTypes.FromNativeUri(casted->ServiceName);
            description.ServiceTypeName            = NativeTypes.FromNativeString(casted->ServiceTypeName);
            description.PartitionSchemeDescription = PartitionSchemeDescription.CreateFromNative(casted->PartitionScheme, casted->PartitionSchemeDescription);
            description.PlacementConstraints       = NativeTypes.FromNativeString(casted->PlacementConstraints);
            description.InstanceCount              = casted->InstanceCount;
            description.ParseCorrelations(casted->CorrelationCount, casted->Correlations);
            description.ParseLoadMetrics(casted->MetricCount, casted->Metrics);
            description.InitializationData = NativeTypes.FromNativeBytes(casted->InitializationData, casted->InitializationDataSize);

            if (casted->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex1 = (NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX1 *)casted->Reserved;

            if (ex1 == null)
            {
                throw new ArgumentException(StringResources.Error_UnknownReservedType);
            }

            if (ex1->PolicyList != IntPtr.Zero)
            {
                NativeTypes.FABRIC_SERVICE_PLACEMENT_POLICY_LIST *pList = (NativeTypes.FABRIC_SERVICE_PLACEMENT_POLICY_LIST *)ex1->PolicyList;
                description.ParsePlacementPolicies(pList->PolicyCount, pList->Policies);
            }

            if (ex1->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex2 = (NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX2 *)ex1->Reserved;

            if (ex2 == null)
            {
                throw new ArgumentException(StringResources.Error_UnknownReservedType);
            }

            if (NativeTypes.FromBOOLEAN(ex2->IsDefaultMoveCostSpecified))
            {
                // This will correctly set the property IsDefaultMoveCostSpecified to true if move cost is valid.
                description.ParseDefaultMoveCost(ex2->DefaultMoveCost);
            }

            if (ex2->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex3 = (NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX3 *)ex2->Reserved;

            description.ServicePackageActivationMode = InteropHelpers.FromNativeServicePackageActivationMode(ex3->ServicePackageActivationMode);
            description.ServiceDnsName = NativeTypes.FromNativeString(ex3->ServiceDnsName);

            if (ex3->Reserved == IntPtr.Zero)
            {
                return(description);
            }

            var ex4 = (NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX4 *)ex3->Reserved;

            if (ex4->ServiceScalingPolicies != IntPtr.Zero && ex4->ScalingPolicyCount > 0)
            {
                description.ParseScalingPolicies(ex4->ScalingPolicyCount, ex4->ServiceScalingPolicies);
            }

            return(description);
        }
Пример #3
0
 /// <summary>
 /// <para>
 /// Instantiates a <see cref="System.Fabric.Description.PartitionSchemeDescription" /> class with parameters from another
 /// <see cref="System.Fabric.Description.PartitionSchemeDescription" /> object.
 /// </para>
 /// </summary>
 /// <param name="other">
 /// <para>The partition scheme description from which parameters are copied.</para>
 /// </param>
 protected PartitionSchemeDescription(PartitionSchemeDescription other)
 {
     this.Scheme = other.Scheme;
 }