internal static void CopyFrom(KeyedCollection <string, ServiceLoadMetricDescription> source, KeyedCollection <string, ServiceLoadMetricDescription> target) { if (source != null) { target.Clear(); source.ForEach(m => { ServiceLoadMetricDescription casted; if (m is StatefulServiceLoadMetricDescription) { casted = new StatefulServiceLoadMetricDescription(m as StatefulServiceLoadMetricDescription); } else if (m is StatelessServiceLoadMetricDescription) { casted = new StatelessServiceLoadMetricDescription(m as StatelessServiceLoadMetricDescription); } else { casted = new ServiceLoadMetricDescription(m); } target.Add(casted); }); } }
internal static unsafe ServiceLoadMetricDescription CreateFromNative(IntPtr nativeRaw, bool isStateful) { NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION nativeMetric = *(NativeTypes.FABRIC_SERVICE_LOAD_METRIC_DESCRIPTION *)nativeRaw; ServiceLoadMetricDescription managed; if (isStateful) { managed = new StatefulServiceLoadMetricDescription(); } else { managed = new StatelessServiceLoadMetricDescription(); } managed.Name = NativeTypes.FromNativeString(nativeMetric.Name); switch (nativeMetric.Weight) { case NativeTypes.FABRIC_SERVICE_LOAD_METRIC_WEIGHT.FABRIC_SERVICE_LOAD_METRIC_WEIGHT_ZERO: managed.Weight = ServiceLoadMetricWeight.Zero; break; case NativeTypes.FABRIC_SERVICE_LOAD_METRIC_WEIGHT.FABRIC_SERVICE_LOAD_METRIC_WEIGHT_LOW: managed.Weight = ServiceLoadMetricWeight.Low; break; case NativeTypes.FABRIC_SERVICE_LOAD_METRIC_WEIGHT.FABRIC_SERVICE_LOAD_METRIC_WEIGHT_MEDIUM: managed.Weight = ServiceLoadMetricWeight.Medium; break; case NativeTypes.FABRIC_SERVICE_LOAD_METRIC_WEIGHT.FABRIC_SERVICE_LOAD_METRIC_WEIGHT_HIGH: managed.Weight = ServiceLoadMetricWeight.High; break; default: ReleaseAssert.Failfast(string.Format(CultureInfo.CurrentCulture, StringResources.Error_UnknownWeight_Formatted, nativeMetric.Weight)); throw new ArgumentException(StringResources.Error_UnknownWeight); } managed.PrimaryDefaultLoad = checked ((int)nativeMetric.PrimaryDefaultLoad); managed.SecondaryDefaultLoad = checked ((int)nativeMetric.SecondaryDefaultLoad); return(managed); }
// Copy ctor internal StatefulServiceLoadMetricDescription(StatefulServiceLoadMetricDescription other) : this(other.Name, other.PrimaryDefaultLoad, other.SecondaryDefaultLoad, other.Weight) { }