public IEnumerable <MockObject> GetObjects(EtpVersion version, MockGraphContext context, bool?activeStatusFilter = null, DateTime?storeLastWriteFilter = null) { CheckLocked(); var uri = context.Uri; if (!((version == EtpVersion.v11 && uri.IsEtp11) || (version == EtpVersion.v12 && uri.IsEtp12))) { yield break; } IEnumerable <MockObject> objects = null; var dataspace = GetDataspace(uri); if (dataspace == null) { if (uri.IsRootUri) { objects = Dataspaces.SelectMany(d => d.Objects.Values); } else { yield break; } } if (objects == null) { if (uri.IsBaseUri) { if (uri.IsFamilyVersionUri) { objects = dataspace.Objects.Values.FilterByFamilyAndVersion(uri.DataObjectType); } else { objects = dataspace.Objects.Values; } } else { var @object = GetObject(version, uri); if (@object == null) { yield break; } objects = @object.WalkGraph(context); } } var objectTypes = context.DataObjectTypes; foreach (var @object in objects.FilterByType(objectTypes).FilterByActiveStatus(activeStatusFilter).FilterByStoreLastWrite(storeLastWriteFilter)) { yield return(@object); } }
public IEnumerable <MockSupportedType> GetSupportedTypes(EtpVersion version, MockGraphContext context, bool includeEmptyTypes) { CheckLocked(); var uri = context.Uri; if (!((version == EtpVersion.v11 && uri.IsEtp11) || (version == EtpVersion.v12 && uri.IsEtp12))) { yield break; } var dataspace = GetDataspace(uri); if (dataspace == null || context.IsSelfOnly) { yield break; } IEnumerable <IDataObjectType> primarySupportedTypes, secondarySupportedTypes = Enumerable.Empty <IDataObjectType>(); IEnumerable <MockObject> objects; if (uri.IsDataRootUri) { primarySupportedTypes = SupportedDataObjects.Select(sdo => sdo.QualifiedType); if (uri.IsFamilyVersionUri) { primarySupportedTypes = primarySupportedTypes.FilterByFamilyAndVersion(uri.DataObjectType); } objects = dataspace.Objects.Values; } else { MockObject @object; if (!ObjectsByUri[version].TryGetValue(uri, out @object)) { yield break; } primarySupportedTypes = @object.SupportedPrimarySourceAndTargetTypes(context); secondarySupportedTypes = @object.SupportedSecondarySourceAndTargetTypes(context); objects = @object.SourcesAndTargets(context); } foreach (var supportedType in primarySupportedTypes) { var count = objects.Count(o => o.DataObjectType.MatchesExact(supportedType)); if (count > 0 || includeEmptyTypes) { yield return new MockSupportedType { Uri = uri.Append(supportedType), DataObjectType = supportedType, ObjectCount = count, IsPrimaryRelationship = true } } ; } foreach (var supportedType in secondarySupportedTypes) { var count = objects.Count(o => o.DataObjectType.MatchesExact(supportedType)); if (count > 0 || includeEmptyTypes) { yield return new MockSupportedType { Uri = uri.Append(supportedType), DataObjectType = supportedType, ObjectCount = count, IsPrimaryRelationship = false } } ; } } } }
private MockGraphContext GetContext(string uri) { var context = new MockGraphContext { Uri = new EtpUri(uri), DataObjectTypes = new HashSet <EtpDataObjectType>(), Depth = 1, IncludeSelf = false, IncludeSources = true, IncludeTargets = false, IncludeSecondarySources = false, IncludeSecondaryTargets = false, NavigatePrimaryEdges = true, NavigateSecondaryEdges = false, }; while (true) { Console.WriteLine("Choose an option:"); Console.WriteLine($" D - Set depth (current value: {context.Depth})"); Console.WriteLine($" S - Toggle Include Self (current value: {(context.IncludeSelf ? "Include" : "Exclude")})"); Console.WriteLine($" O - Toggle Include Sources (current value: {(context.IncludeSources ? "Include" : "Exclude")})"); Console.WriteLine($" P - Toggle Include Secondary Sources (current value: {(context.IncludeSecondarySources ? "Include" : "Exclude")})"); Console.WriteLine($" T - Toggle Include Targets (current value: {(context.IncludeTargets ? "Include" : "Exclude")})"); Console.WriteLine($" U - Toggle Include Secondary Targets (current value: {(context.IncludeSecondaryTargets ? "Include" : "Exclude")})"); Console.WriteLine($" 1 - Toggle Navigate Primary Edges (current value: {(context.NavigatePrimaryEdges ? "Navigate" : "Do Not Navigate")})"); Console.WriteLine($" 2 - Toggle Navigate Secondary Edges (current value: {(context.NavigateSecondaryEdges ? "Navigate" : "Do Not Navigate")})"); Console.WriteLine($" Y - Add Data Types"); if (context.DataObjectTypes.Count > 0) { Console.WriteLine($" Current Data Types:"); foreach (var dataType in context.DataObjectTypes) { Console.WriteLine($" {dataType}"); } } Console.WriteLine($" (enter / other) - Submit request"); Console.WriteLine(); var info = Console.ReadKey(); Console.WriteLine(" - processing..."); Console.WriteLine(); if (IsKey(info, "D")) { Console.WriteLine("Enter depth:"); var depth = Console.ReadLine(); int depthValue; if (int.TryParse(depth, out depthValue)) { context.Depth = depthValue; } } else if (IsKey(info, "S")) { context.IncludeSelf = !context.IncludeSelf; } else if (IsKey(info, "O")) { context.IncludeSources = !context.IncludeSources; } else if (IsKey(info, "P")) { context.IncludeSecondarySources = !context.IncludeSecondarySources; } else if (IsKey(info, "T")) { context.IncludeTargets = !context.IncludeTargets; } else if (IsKey(info, "U")) { context.IncludeSecondaryTargets = !context.IncludeSecondaryTargets; } else if (IsKey(info, "1")) { context.NavigatePrimaryEdges = !context.NavigatePrimaryEdges; } else if (IsKey(info, "2")) { context.NavigateSecondaryEdges = !context.NavigateSecondaryEdges; } else if (IsKey(info, "Y")) { Console.WriteLine("Enter data type:"); var dataType = Console.ReadLine(); var dataTypeValue = new EtpDataObjectType(dataType); if (dataTypeValue.IsValid) { context.DataObjectTypes.Add(dataTypeValue); } } else { break; } } return(context); }