internal static unsafe new StatefulServiceTypeDescription CreateFromNative(IntPtr descriptionPtr)
        {
            NativeTypes.FABRIC_STATEFUL_SERVICE_TYPE_DESCRIPTION *nativeDescription = (NativeTypes.FABRIC_STATEFUL_SERVICE_TYPE_DESCRIPTION *)descriptionPtr;

            StatefulServiceTypeDescription description = new StatefulServiceTypeDescription();

            description.ReadCommonProperties(
                nativeDescription->ServiceTypeName,
                nativeDescription->PlacementConstraints,
                nativeDescription->LoadMetrics,
                nativeDescription->Extensions);

            if (nativeDescription->Reserved != IntPtr.Zero)
            {
                NativeTypes.FABRIC_STATEFUL_SERVICE_TYPE_DESCRIPTION_EX1 *ex1 = (NativeTypes.FABRIC_STATEFUL_SERVICE_TYPE_DESCRIPTION_EX1 *)nativeDescription->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);
                }
            }

            description.HasPersistedState = NativeTypes.FromBOOLEAN(nativeDescription->HasPersistedState);
            return(description);
        }
Ejemplo n.º 2
0
        internal static unsafe bool TryCreateFromNative(IntPtr descriptionPtr, out ServiceTypeDescription serviceTypeDescription)
        {
            serviceTypeDescription = null;

            var nativeDescription = (NativeTypes.FABRIC_SERVICE_TYPE_DESCRIPTION *)descriptionPtr;

            switch (nativeDescription->Kind)
            {
            case NativeTypes.FABRIC_SERVICE_KIND.FABRIC_SERVICE_KIND_STATELESS:
                serviceTypeDescription = StatelessServiceTypeDescription.CreateFromNative(nativeDescription->Value);
                break;

            case NativeTypes.FABRIC_SERVICE_KIND.FABRIC_SERVICE_KIND_STATEFUL:
                serviceTypeDescription = StatefulServiceTypeDescription.CreateFromNative(nativeDescription->Value);
                break;

            default:
                AppTrace.TraceSource.WriteNoise(
                    "ServiceTypeDescription.TryCreateFromNative",
                    "Ignoring the result with unsupported ServiceKind value {0}",
                    (int)nativeDescription->Kind);
                break;
            }

            return(serviceTypeDescription != null);
        }