コード例 #1
0
        /// <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, ServicePlacementPreferPrimaryDomainPolicyDescription obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.Type, "Type", ServicePlacementPolicyTypeConverter.Serialize);
            if (obj.DomainName != null)
            {
                writer.WriteProperty(obj.DomainName, "DomainName", JsonWriterExtensions.WriteStringValue);
            }

            writer.WriteEndObject();
        }
コード例 #2
0
        public static ServicePlacementPolicyDescription GetClone(this ServicePlacementPolicyDescription other)
        {
            if (other == null)
            {
                return(null);
            }
            ServicePlacementPolicyDescription clone;

            if (other is ServicePlacementInvalidDomainPolicyDescription)
            {
                clone = new ServicePlacementInvalidDomainPolicyDescription()
                {
                    DomainName = (other as ServicePlacementInvalidDomainPolicyDescription).DomainName
                };
            }
            else if (other is ServicePlacementRequiredDomainPolicyDescription)
            {
                clone = new ServicePlacementRequiredDomainPolicyDescription()
                {
                    DomainName = (other as ServicePlacementRequiredDomainPolicyDescription).DomainName
                };
            }
            else if (other is ServicePlacementPreferPrimaryDomainPolicyDescription)
            {
                clone = new ServicePlacementPreferPrimaryDomainPolicyDescription()
                {
                    DomainName = (other as ServicePlacementPreferPrimaryDomainPolicyDescription).DomainName
                };
            }
            else if (other is ServicePlacementRequireDomainDistributionPolicyDescription)
            {
                clone = new ServicePlacementRequireDomainDistributionPolicyDescription();
            }
            else
            {
                clone = new ServicePlacementNonPartiallyPlaceServicePolicyDescription();
            }

            return(clone);
        }
コード例 #3
0
        private ServicePlacementPolicyDescription GetServicePlacementPolicyDescription(ArmServicePlacementPolicyDescription policy)
        {
            string errorMessage;
            ServicePlacementPolicyDescription placementPolicy;

            switch (policy.Type)
            {
            case ArmServicePlacementPolicyType.InvalidDomain:
            {
                if (!this.ValidObjectType <ArmServicePlacementInvalidDomainPolicyDescription>(policy, out errorMessage))
                {
                    throw new InvalidCastException(errorMessage);
                }

                var policyOperation = (ArmServicePlacementInvalidDomainPolicyDescription)policy;
                placementPolicy = new ServicePlacementInvalidDomainPolicyDescription()
                {
                    DomainName = policyOperation.DomainName
                };

                break;
            }

            case ArmServicePlacementPolicyType.NonPartiallyPlaceService:
            {
                placementPolicy = new ServicePlacementNonPartiallyPlaceServicePolicyDescription();
                break;
            }

            case ArmServicePlacementPolicyType.PreferredPrimaryDomain:
            {
                if (!this.ValidObjectType <ArmServicePlacementPreferPrimaryDomainPolicyDescription>(policy, out errorMessage))
                {
                    throw new InvalidCastException(errorMessage);
                }

                var policyOperation = (ArmServicePlacementPreferPrimaryDomainPolicyDescription)policy;
                placementPolicy = new ServicePlacementPreferPrimaryDomainPolicyDescription()
                {
                    DomainName = policyOperation.DomainName
                };

                break;
            }

            case ArmServicePlacementPolicyType.RequiredDomain:
            {
                if (!this.ValidObjectType <ArmServicePlacementRequiredDomainPolicyDescription>(policy, out errorMessage))
                {
                    throw new InvalidCastException(errorMessage);
                }

                var policyOperation = (ArmServicePlacementRequiredDomainPolicyDescription)policy;
                placementPolicy = new ServicePlacementRequiredDomainPolicyDescription()
                {
                    DomainName = policyOperation.DomainName
                };

                break;
            }

            case ArmServicePlacementPolicyType.RequiredDomainDistribution:
            {
                placementPolicy = new ServicePlacementRequireDomainDistributionPolicyDescription();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(policy.Type),
                          policy.Type,
                          $"{this.TraceType}: Unexpected ArmServicePlacementPolicyType");
            }

            return(placementPolicy);
        }