Esempio n. 1
0
        internal IntPtr ToNative(PinCollection pin)
        {
            var initializationData = NativeTypes.ToNativeBytes(pin, this.InitializationData);

            var serviceDnsName = "";

            if (!string.IsNullOrWhiteSpace(this.ServiceDnsName))
            {
                serviceDnsName = this.ServiceDnsName;
            }

            var desc = new NativeTypes.FABRIC_SERVICE_FROM_TEMPLATE_DESCRIPTION
            {
                ApplicationName = pin.AddObject(this.ApplicationName),
                ServiceName     = pin.AddObject(this.ServiceName),
                ServiceDnsName  = pin.AddBlittable(serviceDnsName),
                ServiceTypeName = pin.AddObject(this.ServiceTypeName),
                ServicePackageActivationMode = InteropHelpers.ToNativeServicePackageActivationMode(this.ServicePackageActivationMode),
                InitializationDataSize       = initializationData.Item1,
                InitializationData           = initializationData.Item2,
                Reserved = IntPtr.Zero
            };

            return(pin.AddBlittable(desc));
        }
        internal override IntPtr ToNative(PinCollection pin, out NativeTypes.FABRIC_SERVICE_DESCRIPTION_KIND kind)
        {
            this.ValidateDefaultMetricValue();

            var nativeDescription = new NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION[1];

            nativeDescription[0].ApplicationName            = pin.AddObject(this.ApplicationName);
            nativeDescription[0].ServiceName                = pin.AddObject(this.ServiceName);
            nativeDescription[0].ServiceTypeName            = pin.AddBlittable(this.ServiceTypeName);
            nativeDescription[0].PartitionScheme            = (NativeTypes.FABRIC_PARTITION_SCHEME) this.PartitionSchemeDescription.Scheme;
            nativeDescription[0].PartitionSchemeDescription = this.PartitionSchemeDescription.ToNative(pin);
            nativeDescription[0].PlacementConstraints       = pin.AddBlittable(this.PlacementConstraints);
            nativeDescription[0].InstanceCount              = this.InstanceCount;

            var correlations = this.ToNativeCorrelations(pin);

            nativeDescription[0].CorrelationCount = correlations.Item1;
            nativeDescription[0].Correlations     = correlations.Item2;

            var initializationData = NativeTypes.ToNativeBytes(pin, this.InitializationData);

            nativeDescription[0].InitializationDataSize = initializationData.Item1;
            nativeDescription[0].InitializationData     = initializationData.Item2;

            var metrics = NativeTypes.ToNativeLoadMetrics(pin, this.Metrics);

            nativeDescription[0].MetricCount = metrics.Item1;
            nativeDescription[0].Metrics     = metrics.Item2;

            var ex1 = new NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX1[1];

            if (this.PlacementPolicies != null)
            {
                var policies = this.ToNativePolicies(pin);
                var pList    = new NativeTypes.FABRIC_SERVICE_PLACEMENT_POLICY_LIST[1];
                pList[0].PolicyCount = policies.Item1;
                pList[0].Policies    = policies.Item2;

                ex1[0].PolicyList = pin.AddBlittable(pList);
            }

            var ex2 = new NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX2[1];

            ex2[0].DefaultMoveCost            = this.ToNativeDefaultMoveCost();
            ex2[0].IsDefaultMoveCostSpecified = NativeTypes.ToBOOLEAN(this.IsDefaultMoveCostSpecified);

            var ex3 = new NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX3[1];

            ex3[0].ServicePackageActivationMode = InteropHelpers.ToNativeServicePackageActivationMode(this.ServicePackageActivationMode);
            ex3[0].ServiceDnsName = pin.AddBlittable(this.ServiceDnsName);

            var ex4 = new NativeTypes.FABRIC_STATELESS_SERVICE_DESCRIPTION_EX4[1];

            if (this.ScalingPolicies != null)
            {
                var scalingPolicies = this.ToNativeScalingPolicies(pin);
                ex4[0].ScalingPolicyCount     = scalingPolicies.Item1;
                ex4[0].ServiceScalingPolicies = scalingPolicies.Item2;
            }

            ex3[0].Reserved = pin.AddBlittable(ex4);
            ex2[0].Reserved = pin.AddBlittable(ex3);
            ex1[0].Reserved = pin.AddBlittable(ex2);
            nativeDescription[0].Reserved = pin.AddBlittable(ex1);

            kind = NativeTypes.FABRIC_SERVICE_DESCRIPTION_KIND.FABRIC_SERVICE_DESCRIPTION_KIND_STATELESS;
            return(pin.AddBlittable(nativeDescription));
        }
        internal override IntPtr ToNative(PinCollection pin, out NativeTypes.FABRIC_SERVICE_DESCRIPTION_KIND kind)
        {
            this.ValidateDefaultMetricValue();

            var nativeDescription = new NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION[1];

            nativeDescription[0].ApplicationName            = pin.AddObject(this.ApplicationName);
            nativeDescription[0].ServiceName                = pin.AddObject(this.ServiceName);
            nativeDescription[0].ServiceTypeName            = pin.AddBlittable(this.ServiceTypeName);
            nativeDescription[0].PartitionScheme            = (NativeTypes.FABRIC_PARTITION_SCHEME) this.PartitionSchemeDescription.Scheme;
            nativeDescription[0].PartitionSchemeDescription = this.PartitionSchemeDescription.ToNative(pin);
            nativeDescription[0].TargetReplicaSetSize       = this.TargetReplicaSetSize;
            nativeDescription[0].MinReplicaSetSize          = this.MinReplicaSetSize;
            nativeDescription[0].PlacementConstraints       = pin.AddBlittable(this.PlacementConstraints);
            nativeDescription[0].HasPersistedState          = NativeTypes.ToBOOLEAN(this.HasPersistedState);

            var correlations = this.ToNativeCorrelations(pin);

            nativeDescription[0].CorrelationCount = correlations.Item1;
            nativeDescription[0].Correlations     = correlations.Item2;

            var initializationData = NativeTypes.ToNativeBytes(pin, this.InitializationData);

            nativeDescription[0].InitializationDataSize = initializationData.Item1;
            nativeDescription[0].InitializationData     = initializationData.Item2;

            var metrics = NativeTypes.ToNativeLoadMetrics(pin, this.Metrics);

            nativeDescription[0].MetricCount = metrics.Item1;
            nativeDescription[0].Metrics     = metrics.Item2;

            var ex1 = new NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX1[1];

            if (this.PlacementPolicies != null)
            {
                var policies = this.ToNativePolicies(pin);
                var pList    = new NativeTypes.FABRIC_SERVICE_PLACEMENT_POLICY_LIST[1];

                pList[0].PolicyCount = policies.Item1;
                pList[0].Policies    = policies.Item2;

                ex1[0].PolicyList = pin.AddBlittable(pList);
            }

            var failoverSettings    = new NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS[1];
            var failoverSettingsEx1 = new NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_EX1[1];
            var flags = NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_NONE;

            if (ReplicaRestartWaitDuration.HasValue)
            {
                flags |= NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_REPLICA_RESTART_WAIT_DURATION;
                failoverSettings[0].ReplicaRestartWaitDurationSeconds = (uint)this.ReplicaRestartWaitDuration.Value.TotalSeconds;
            }

            if (QuorumLossWaitDuration.HasValue)
            {
                flags |= NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_QUORUM_LOSS_WAIT_DURATION;
                failoverSettings[0].QuorumLossWaitDurationSeconds = (uint)this.QuorumLossWaitDuration.Value.TotalSeconds;
            }

            if (StandByReplicaKeepDuration.HasValue)
            {
                flags |= NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_STANDBY_REPLICA_KEEP_DURATION;
                failoverSettingsEx1[0].StandByReplicaKeepDurationSeconds = (uint)this.StandByReplicaKeepDuration.Value.TotalSeconds;
            }

            if (flags != NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_NONE)
            {
                failoverSettings[0].Flags = (uint)flags;

                if ((flags & NativeTypes.FABRIC_STATEFUL_SERVICE_FAILOVER_SETTINGS_FLAGS.FABRIC_STATEFUL_SERVICE_SETTINGS_STANDBY_REPLICA_KEEP_DURATION) != 0)
                {
                    failoverSettings[0].Reserved = pin.AddBlittable(failoverSettingsEx1);
                }

                ex1[0].FailoverSettings = pin.AddBlittable(failoverSettings);
            }

            var ex2 = new NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX2[1];

            ex2[0].DefaultMoveCost            = this.ToNativeDefaultMoveCost();
            ex2[0].IsDefaultMoveCostSpecified = NativeTypes.ToBOOLEAN(this.IsDefaultMoveCostSpecified);

            var ex3 = new NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX3[1];

            ex3[0].ServicePackageActivationMode = InteropHelpers.ToNativeServicePackageActivationMode(ServicePackageActivationMode);
            ex3[0].ServiceDnsName = pin.AddBlittable(this.ServiceDnsName);

            ex2[0].Reserved = pin.AddBlittable(ex3);
            ex1[0].Reserved = pin.AddBlittable(ex2);

            var ex4 = new NativeTypes.FABRIC_STATEFUL_SERVICE_DESCRIPTION_EX4[1];

            if (ScalingPolicies != null)
            {
                var scalingPolicies = this.ToNativeScalingPolicies(pin);

                ex4[0].ScalingPolicyCount     = scalingPolicies.Item1;
                ex4[0].ServiceScalingPolicies = scalingPolicies.Item2;
            }

            ex3[0].Reserved = pin.AddBlittable(ex4);

            nativeDescription[0].Reserved = pin.AddBlittable(ex1);

            kind = NativeTypes.FABRIC_SERVICE_DESCRIPTION_KIND.FABRIC_SERVICE_DESCRIPTION_KIND_STATEFUL;
            return(pin.AddBlittable(nativeDescription));
        }