public override async Task PublishModule(RootConfiguration configuration, OciArtifactModuleReference moduleReference, Stream compiled) { var config = new StreamDescriptor(Stream.Null, BicepMediaTypes.BicepModuleConfigV1); var layer = new StreamDescriptor(compiled, BicepMediaTypes.BicepModuleLayerV1Json); await this.client.PushArtifactAsync(configuration, moduleReference, config, layer); }
/// <summary> /// Creates a default stream descriptor, if there is none yet, and returns it. /// If there is one already present, then returns the current instance. /// </summary> /// <returns>stream descriptor representing the default stream.</returns> private StreamDescriptor CreateDefaultStreamDescriptor() { if (this.defaultStreamDescriptor == null) { this.defaultStreamDescriptor = new StreamDescriptor(this); } return(this.defaultStreamDescriptor); }
/// <summary> /// Gets the stream info with the given name. /// </summary> /// <param name="name">name of the stream.</param> /// <param name="namedStreamInfo">information about the stream with the given name.</param> /// <returns>true if there is a stream with the given name, otherwise returns false.</returns> internal bool TryGetNamedStreamInfo(string name, out StreamDescriptor namedStreamInfo) { namedStreamInfo = null; if (this.streamDescriptors != null) { return(this.streamDescriptors.TryGetValue(name, out namedStreamInfo)); } return(false); }
private static void ValidateCopier(int bufferLength, long?copyLength, long?maxLength, bool inputSync, int inputDelayInMs, int inputFailRequest, bool outputSync, int outputDelayInMs, int outputFailRequest, DateTime?copyTimeout, bool seekable) { byte[] buffer = GetRandomBuffer(bufferLength); // Finds ceiling of division operation int expectedCallCount = (int) (copyLength.HasValue && buffer.Length > copyLength ? (-1L + copyLength + Constants.DefaultBufferSize) / Constants.DefaultBufferSize : (-1L + buffer.Length + Constants.DefaultBufferSize) / Constants.DefaultBufferSize); int totalDelayInMs = (expectedCallCount + 1) * inputDelayInMs + expectedCallCount * outputDelayInMs; DataValidationStream input = new DataValidationStream(buffer, inputSync, inputDelayInMs, inputFailRequest, seekable); DataValidationStream output = new DataValidationStream(buffer, outputSync, outputDelayInMs, outputFailRequest, seekable); RESTCommand <NullType> cmdWithTimeout = new RESTCommand <NullType>(new StorageCredentials(), null) { OperationExpiryTime = copyTimeout }; ExecutionState <NullType> state = new ExecutionState <NullType>(cmdWithTimeout, null, null); StreamDescriptor copyState = new StreamDescriptor(); using (ManualResetEvent waitHandle = new ManualResetEvent(false)) { var mockBufferManager = new MockBufferManager(Constants.DefaultBufferSize); input.WriteToAsync(output, mockBufferManager, copyLength, maxLength, false, state, copyState, _ => waitHandle.Set()); Assert.IsTrue(waitHandle.WaitOne(totalDelayInMs + 10 * 1000)); Assert.AreEqual(0, mockBufferManager.OutstandingBufferCount, "Outstanding buffers not returned to IBufferManager"); } if (inputFailRequest >= 0) { Assert.AreEqual(input.LastException, state.ExceptionRef); Assert.AreEqual(inputFailRequest, input.ReadCallCount); } if (outputFailRequest >= 0) { Assert.AreEqual(output.LastException, state.ExceptionRef); Assert.AreEqual(outputFailRequest, output.WriteCallCount); } if (state.ExceptionRef != null) { throw state.ExceptionRef; } Assert.AreEqual(copyLength.HasValue ? copyLength : buffer.Length, copyState.Length); Assert.AreEqual(copyLength.HasValue ? expectedCallCount : expectedCallCount + 1, input.ReadCallCount); Assert.AreEqual(expectedCallCount, output.WriteCallCount); }
/// <summary> /// Gets string representation of the specified stream descriptor. /// </summary> /// <param name="streamDescriptor">The stream descriptor.</param> /// <returns>The string representation of the specified stream descriptor.</returns> public static string ToTraceString(this StreamDescriptor streamDescriptor) { ExceptionUtilities.CheckArgumentNotNull(streamDescriptor, "streamDescriptor"); return(string.Format( CultureInfo.InvariantCulture, "{{ State = {0}, Name = '{1}', Edit = '{2}', Self = '{3}', ContentType = '{4}', ETag = '{5}' }}", streamDescriptor.State, streamDescriptor.StreamLink.Name, streamDescriptor.StreamLink.EditLink, streamDescriptor.StreamLink.SelfLink, streamDescriptor.StreamLink.ContentType, streamDescriptor.StreamLink.ETag)); }
private void VerifyDescriptor(DescriptorData expected, Descriptor actual, int responseOrder) { EntityDescriptorData entityDescriptorData = expected as EntityDescriptorData; LinkDescriptorData linkDescriptorData = expected as LinkDescriptorData; StreamDescriptorData streamDescriptorData = expected as StreamDescriptorData; if (entityDescriptorData != null) { EntityDescriptor entityDescriptor = actual as EntityDescriptor; this.Assert.IsNotNull(entityDescriptor, GetVerificationFailureMessage(responseOrder, "Unexpected descriptor type:\r\nExpected: {0}\r\nActual: {1}\r\nExpected descriptor data: {2}.", typeof(EntityDescriptor).Name, actual.GetType().Name, entityDescriptorData)); this.Assert.AreSame( entityDescriptorData.Entity, entityDescriptor.Entity, GetVerificationFailureMessage(responseOrder, "Entity verification failed for the entity descriptor data: {0}.", expected)); } else if (linkDescriptorData != null) { LinkDescriptor linkDescriptor = actual as LinkDescriptor; this.Assert.IsNotNull(linkDescriptor, GetVerificationFailureMessage(responseOrder, "Unexpected descriptor type:\r\nExpected: {0}\r\nActual: {1}\r\nExpected descriptor data: {2}.", typeof(LinkDescriptor).Name, actual.GetType().Name, linkDescriptorData)); bool notMatch = linkDescriptorData.SourceDescriptor.Entity != linkDescriptor.Source || (linkDescriptorData.TargetDescriptor == null && linkDescriptor.Target != null) || (linkDescriptorData.TargetDescriptor != null && linkDescriptorData.TargetDescriptor.Entity != linkDescriptor.Target) || linkDescriptorData.SourcePropertyName != linkDescriptor.SourceProperty; this.Assert.IsFalse(notMatch, GetVerificationFailureMessage(responseOrder, "Link verification failed.\r\nExpected: {0}\r\nActual: {1}", linkDescriptorData, linkDescriptor.ToTraceString())); } else { #if WINDOWS_PHONE throw new TaupoNotSupportedException("StreamDescriptors are not supported on Windows Phone"); #else ExceptionUtilities.CheckObjectNotNull(streamDescriptorData, "Expected was not an entity, link, or stream descriptor: {0}", expected); StreamDescriptor streamDescriptor = actual as StreamDescriptor; this.Assert.IsNotNull(streamDescriptor, GetVerificationFailureMessage(responseOrder, "Unexpected descriptor type:\r\nExpected: {0}\r\nActual: {1}\r\nExpected descriptor data: {2}.", typeof(StreamDescriptor).Name, actual.GetType().Name, streamDescriptorData)); this.Assert.AreEqual(streamDescriptorData.State.ToProductEnum(), streamDescriptor.State, GetVerificationFailureMessage(responseOrder, "Stream descriptor state verification failed.")); this.Assert.AreEqual(streamDescriptorData.Name, streamDescriptor.StreamLink.Name, GetVerificationFailureMessage(responseOrder, "Stream descriptor name verification failed.")); this.Assert.AreEqual(streamDescriptorData.ETag, streamDescriptor.StreamLink.ETag, GetVerificationFailureMessage(responseOrder, "Stream descriptor etag verification failed.")); this.Assert.AreEqual(streamDescriptorData.ContentType, streamDescriptor.StreamLink.ContentType, GetVerificationFailureMessage(responseOrder, "Stream descriptor content type verification failed.")); this.Assert.AreEqual(streamDescriptorData.EditLink, streamDescriptor.StreamLink.EditLink, GetVerificationFailureMessage(responseOrder, "Stream descriptor edit link verification failed.")); this.Assert.AreEqual(streamDescriptorData.SelfLink, streamDescriptor.StreamLink.SelfLink, GetVerificationFailureMessage(responseOrder, "Stream descriptor self link verification failed.")); #endif } }
/// <summary> /// Constructs a new async result object /// </summary> /// <param name="context">The source of the operation.</param> /// <param name="method">Name of the method which is invoked asynchronously.</param> /// <param name="request">The <see cref="HttpWebRequest"/> object which is wrapped by this async result.</param> /// <param name="callback">User specified callback for the async operation.</param> /// <param name="state">User state for the async callback.</param> /// <param name="streamDescriptor">stream descriptor whose value is getting queried.</param> internal GetReadStreamResult( DataServiceContext context, string method, ODataRequestMessageWrapper request, AsyncCallback callback, object state, StreamDescriptor streamDescriptor) : base(context, method, callback, state) { Debug.Assert(request != null, "Null request can't be wrapped to a result."); Debug.Assert(streamDescriptor != null, "streamDescriptor != null"); this.requestMessage = request; this.Abortable = request; this.streamDescriptor = streamDescriptor; this.requestInfo = new RequestInfo(context); }
/// <summary> /// Check if there is a stream with this name. If yes, returns the information about that stream, otherwise add a streams with the given name. /// </summary> /// <param name="name">name of the stream.</param> /// <returns>an existing or new namedstreaminfo instance with the given name.</returns> internal StreamDescriptor AddStreamInfoIfNotPresent(string name) { StreamDescriptor namedStreamInfo; if (this.streamDescriptors == null) { this.streamDescriptors = new Dictionary <string, StreamDescriptor>(StringComparer.Ordinal); } if (!this.streamDescriptors.TryGetValue(name, out namedStreamInfo)) { namedStreamInfo = new StreamDescriptor(name, this); this.streamDescriptors.Add(name, namedStreamInfo); } return(namedStreamInfo); }
private static void CreateMediaSinkActivate(PresentationDescriptor pd, StreamDescriptor sd, int streamIndex, IntPtr hVideoWnd, out Activate?activate) { var handler = sd.MediaTypeHandler; var majorType = handler.MajorType; if (majorType == MediaTypeGuids.Audio) { MediaFactory.CreateAudioRendererActivate(out activate); } else if (majorType == MediaTypeGuids.Video) { MediaFactory.CreateVideoRendererActivate(hVideoWnd, out activate); } else { pd.DeselectStream(streamIndex); activate = null; } }
public override async Task PublishModule(RootConfiguration configuration, OciArtifactModuleReference moduleReference, Stream compiled) { var config = new StreamDescriptor(Stream.Null, BicepMediaTypes.BicepModuleConfigV1); var layer = new StreamDescriptor(compiled, BicepMediaTypes.BicepModuleLayerV1Json); try { await this.client.PushArtifactAsync(configuration, moduleReference, config, layer); } catch (AggregateException exception) when(CheckAllInnerExceptionsAreRequestFailures(exception)) { // will include several retry messages, but likely the best we can do throw new ExternalModuleException(exception.Message, exception); } catch (RequestFailedException exception) { // can only happen if client retries are disabled throw new ExternalModuleException(exception.Message, exception); } }
/// <summary> /// Merges the given named stream info object. /// If the stream descriptor is already present, then this method merges the info from the given stream descriptor /// into the existing one, otherwise justs add this given stream descriptor to the list of stream descriptors for /// this entity. /// </summary> /// <param name="materializedStreamDescriptor">namedStreamInfo instance containing information about the stream.</param> internal void MergeStreamDescriptor(StreamDescriptor materializedStreamDescriptor) { if (this.streamDescriptors == null) { this.streamDescriptors = new Dictionary <string, StreamDescriptor>(StringComparer.Ordinal); } StreamDescriptor existingStreamDescriptor = null; if (!this.streamDescriptors.TryGetValue(materializedStreamDescriptor.Name, out existingStreamDescriptor)) { this.streamDescriptors[materializedStreamDescriptor.Name] = materializedStreamDescriptor; materializedStreamDescriptor.EntityDescriptor = this; } else { StreamDescriptor.MergeStreamDescriptor(existingStreamDescriptor, materializedStreamDescriptor); Debug.Assert(ReferenceEquals(existingStreamDescriptor.EntityDescriptor, this), "All stream descriptors that are already tracked by the entity must point to the same entity descriptor instance"); } }
private TopologyNode CreateOutputNode(StreamDescriptor streamDescriptor, IntPtr hwnd) { TopologyNode outputNode; Activate rendererActivate; if (streamDescriptor.MediaTypeHandler.MajorType == MediaTypeGuids.Audio) { MediaFactory.CreateAudioRendererActivate(out rendererActivate); } else if (streamDescriptor.MediaTypeHandler.MajorType == MediaTypeGuids.Video) { MediaFactory.CreateVideoRendererActivate(hwnd, out rendererActivate); } else { throw new Exception("Bad stream"); } MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode); outputNode.Object = rendererActivate; return(outputNode); }
/// <summary> /// Merge the information from the new stream info into the existing one. /// </summary> /// <param name="existingStreamDescriptor">stream info into which the data needs to be merged.</param> /// <param name="newStreamDescriptor">stream info which contains the latest data.</param> internal static void MergeStreamDescriptor(StreamDescriptor existingStreamDescriptor, StreamDescriptor newStreamDescriptor) { // overwrite existing information with new ones (coming from the payload). if (newStreamDescriptor.SelfLink != null) { existingStreamDescriptor.SelfLink = newStreamDescriptor.SelfLink; } if (newStreamDescriptor.EditLink != null) { existingStreamDescriptor.EditLink = newStreamDescriptor.EditLink; } if (newStreamDescriptor.ContentType != null) { existingStreamDescriptor.ContentType = newStreamDescriptor.ContentType; } if (newStreamDescriptor.ETag != null) { existingStreamDescriptor.ETag = newStreamDescriptor.ETag; } }
/// <summary> /// Streams are the basic interface to write or read data with /// Simutrace. Streams always belong to a store. This method registers /// a new stream in the session's active store. Before doing so, the /// caller must initially create a new store with StSessionCreateStore(). /// </summary> /// <param name="session">The id of the session, whose store should /// register the stream.</param> /// <param name="desc">Reference to a stream descriptor defining the /// properties of the new stream (e.g., the desired type of data /// entries). To create a descriptor see StMakeStreamDescriptor() /// or StMakeStreamDescriptorFromType().</param> /// <returns>The id of the new stream if successful, INVALID_STREAM_ID /// otherwise. For a more detailed error description call /// StGetLastError().</returns> public static uint StStreamRegister(uint session, ref StreamDescriptor desc) { return(NativeMethods.StStreamRegister(session, ref desc)); }
/// <summary> /// Updates the entity descriptor. /// </summary> public void UpdateEntityDescriptor() { if (!this.EntityDescriptorUpdated) { // Named stream properties are represented on the result type as a DataServiceStreamLink, which contains the // ReadLink and EditLink for the stream. We need to build this metadata information even with NoTracking, // because it is exposed on the result instances directly, not just in the context. foreach (ODataProperty property in this.Properties) { ODataStreamReferenceValue streamValue = property.Value as ODataStreamReferenceValue; if (streamValue != null) { StreamDescriptor streamInfo = this.EntityDescriptor.AddStreamInfoIfNotPresent(property.Name); if (streamValue.ReadLink != null) { streamInfo.SelfLink = streamValue.ReadLink; } if (streamValue.EditLink != null) { streamInfo.EditLink = streamValue.EditLink; } streamInfo.ETag = streamValue.ETag; streamInfo.ContentType = streamValue.ContentType; } } if (this.IsAtomOrTracking) { if (this.Id == null) { throw DSClient.Error.InvalidOperation(DSClient.Strings.Deserialize_MissingIdElement); } this.EntityDescriptor.Identity = this.entry.Id; this.EntityDescriptor.EditLink = this.entry.EditLink; this.EntityDescriptor.SelfLink = this.entry.ReadLink; this.EntityDescriptor.ETag = this.entry.ETag; if (this.entry.MediaResource != null) { if (this.entry.MediaResource.ReadLink != null) { this.EntityDescriptor.ReadStreamUri = this.entry.MediaResource.ReadLink; } if (this.entry.MediaResource.EditLink != null) { this.EntityDescriptor.EditStreamUri = this.entry.MediaResource.EditLink; } if (this.entry.MediaResource.ETag != null) { this.EntityDescriptor.StreamETag = this.entry.MediaResource.ETag; } } if (this.entry.Functions != null) { foreach (ODataFunction function in this.entry.Functions) { this.EntityDescriptor.AddOperationDescriptor(new FunctionDescriptor { Title = function.Title, Metadata = function.Metadata, Target = function.Target }); } } if (this.entry.Actions != null) { foreach (ODataAction action in this.entry.Actions) { this.EntityDescriptor.AddOperationDescriptor(new ActionDescriptor { Title = action.Title, Metadata = action.Metadata, Target = action.Target }); } } } this.EntityDescriptorUpdated = true; } }
public async Task PushArtifactAsync(Configuration.RootConfiguration configuration, OciArtifactModuleReference moduleReference, StreamDescriptor config, params StreamDescriptor[] layers) { // TODO: Add similar exception handling as in the pull* method // TODO: How do we choose this? Does it ever change? var algorithmIdentifier = DescriptorFactory.AlgorithmIdentifierSha256; var blobClient = this.CreateBlobClient(configuration, moduleReference); config.ResetStream(); var configDescriptor = DescriptorFactory.CreateDescriptor(algorithmIdentifier, config); config.ResetStream(); var configUploadResult = await blobClient.UploadBlobAsync(config.Stream); var layerDescriptors = new List <OciDescriptor>(layers.Length); foreach (var layer in layers) { layer.ResetStream(); var layerDescriptor = DescriptorFactory.CreateDescriptor(algorithmIdentifier, layer); layerDescriptors.Add(layerDescriptor); layer.ResetStream(); var layerUploadResult = await blobClient.UploadBlobAsync(layer.Stream); } var manifest = new OciManifest(2, configDescriptor, layerDescriptors); using var manifestStream = new MemoryStream(); OciSerialization.Serialize(manifestStream, manifest); manifestStream.Position = 0; // BUG: the client closes the stream :( var manifestUploadResult = await blobClient.UploadManifestAsync(manifestStream, new UploadManifestOptions(ContentType.ApplicationVndOciImageManifestV1Json, moduleReference.Tag)); }
internal static void ValidateResponseStreamMd5AndLength <T>(long?length, string md5, StorageCommandBase <T> cmd, StreamDescriptor streamCopyState) { if (streamCopyState == null) { throw new StorageException( cmd.CurrentResult, SR.ContentMD5NotCalculated, null) { IsRetryable = false }; } if (streamCopyState.Length != length) { throw new StorageException( cmd.CurrentResult, string.Format(SR.BlobDataCorruptedIncorrectNumberOfBytes, streamCopyState.Length, length), null) { IsRetryable = false }; } if (md5 != null && streamCopyState.Md5 != null && streamCopyState.Md5 != md5) { throw new StorageException(cmd.CurrentResult, SR.MD5MismatchError, null) { IsRetryable = false }; } }
internal static object ProjectionValueForPath(ODataEntityMaterializer materializer, MaterializerEntry entry, Type expectedType, ProjectionPath path) { if ((path.Count == 0) || ((path.Count == 1) && (path[0].Member == null))) { if (!entry.EntityHasBeenResolved) { materializer.Materialize(entry, expectedType, false); } return(entry.ResolvedObject); } object streamLink = null; ODataNavigationLink link = null; ODataProperty atomProperty = null; ICollection <ODataNavigationLink> navigationLinks = entry.NavigationLinks; IEnumerable <ODataProperty> properties = entry.Entry.Properties; ClientEdmModel model = ClientEdmModel.GetModel(materializer.ResponseInfo.MaxProtocolVersion); for (int i = 0; i < path.Count; i++) { Func <StreamDescriptor, bool> predicate = null; Func <ODataNavigationLink, bool> func2 = null; Func <ODataProperty, bool> func3 = null; Func <ODataProperty, bool> func4 = null; Func <ODataNavigationLink, bool> func5 = null; string propertyName; ProjectionPathSegment segment = path[i]; if (segment.Member != null) { bool flag = i == (path.Count - 1); propertyName = segment.Member; expectedType = segment.SourceTypeAs ?? expectedType; ClientPropertyAnnotation property = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(expectedType)).GetProperty(propertyName, false); if (property.IsStreamLinkProperty) { if (predicate == null) { predicate = sd => sd.Name == propertyName; } StreamDescriptor descriptor = entry.EntityDescriptor.StreamDescriptors.Where <StreamDescriptor>(predicate).SingleOrDefault <StreamDescriptor>(); if (descriptor == null) { if (segment.SourceTypeAs == null) { throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_PropertyMissing(propertyName, entry.Entry.Id)); } return(WebUtil.GetDefaultValue <DataServiceStreamLink>()); } streamLink = descriptor.StreamLink; } else { if (segment.SourceTypeAs != null) { if (func2 == null) { func2 = p => p.Name == propertyName; } if (!navigationLinks.Any <ODataNavigationLink>(func2)) { if (func3 == null) { func3 = p => p.Name == propertyName; } if (!properties.Any <ODataProperty>(func3) && flag) { return(WebUtil.GetDefaultValue(property.PropertyType)); } } } if (func4 == null) { func4 = p => p.Name == propertyName; } atomProperty = properties.Where <ODataProperty>(func4).FirstOrDefault <ODataProperty>(); if (func5 == null) { func5 = p => p.Name == propertyName; } link = ((atomProperty == null) && (navigationLinks != null)) ? navigationLinks.Where <ODataNavigationLink>(func5).FirstOrDefault <ODataNavigationLink>() : null; if ((link == null) && (atomProperty == null)) { throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_PropertyMissing(propertyName, entry.Entry.Id)); } if (link != null) { ValidatePropertyMatch(property, link); MaterializerNavigationLink link2 = MaterializerNavigationLink.GetLink(link); if (link2.Feed != null) { MaterializerFeed feed = MaterializerFeed.GetFeed(link2.Feed); Type implementationType = ClientTypeUtil.GetImplementationType(segment.ProjectionType, typeof(ICollection <>)); if (implementationType == null) { implementationType = ClientTypeUtil.GetImplementationType(segment.ProjectionType, typeof(IEnumerable <>)); } Type nestedExpectedType = implementationType.GetGenericArguments()[0]; Type projectionType = segment.ProjectionType; if (projectionType.IsInterfaceEx() || ODataMaterializer.IsDataServiceCollection(projectionType)) { projectionType = typeof(Collection <>).MakeGenericType(new Type[] { nestedExpectedType }); } IEnumerable list = (IEnumerable)Util.ActivatorCreateInstance(projectionType, new object[0]); MaterializeToList(materializer, list, nestedExpectedType, feed.Entries); if (ODataMaterializer.IsDataServiceCollection(segment.ProjectionType)) { list = (IEnumerable)Util.ActivatorCreateInstance(WebUtil.GetDataServiceCollectionOfT(new Type[] { nestedExpectedType }), new object[] { list, TrackingMode.None }); } ProjectionPlan plan = CreatePlanForShallowMaterialization(nestedExpectedType); materializer.FoundNextLinkForCollection(list, feed.Feed.NextPageLink, plan); streamLink = list; } else if (link2.Entry != null) { MaterializerEntry entry2 = link2.Entry; if (flag) { if ((entry2.Entry != null) && !entry2.EntityHasBeenResolved) { materializer.Materialize(entry2, property.PropertyType, false); } } else { CheckEntryToAccessNotNull(entry2, propertyName); } properties = entry2.Properties; navigationLinks = entry2.NavigationLinks; streamLink = entry2.ResolvedObject; entry = entry2; } } else { if (atomProperty.Value is ODataStreamReferenceValue) { streamLink = null; navigationLinks = ODataMaterializer.EmptyLinks; properties = ODataMaterializer.EmptyProperties; continue; } ValidatePropertyMatch(property, atomProperty); if (ClientTypeUtil.TypeOrElementTypeIsEntity(property.PropertyType)) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.AtomMaterializer_InvalidEntityType(property.EntityCollectionItemType ?? property.PropertyType)); } if (property.IsPrimitiveOrComplexCollection) { object instance = streamLink ?? (entry.ResolvedObject ?? Util.ActivatorCreateInstance(expectedType, new object[0])); ODataMaterializer.ApplyDataValue(model.GetClientTypeAnnotation(model.GetOrCreateEdmType(instance.GetType())), atomProperty, materializer.ResponseInfo.IgnoreMissingProperties, materializer.ResponseInfo, instance); navigationLinks = ODataMaterializer.EmptyLinks; properties = ODataMaterializer.EmptyProperties; } else if (atomProperty.Value is ODataComplexValue) { ODataComplexValue complexValue = atomProperty.Value as ODataComplexValue; ODataMaterializer.MaterializeComplexTypeProperty(property.PropertyType, complexValue, materializer.ResponseInfo.IgnoreMissingProperties, materializer.ResponseInfo); properties = complexValue.Properties; navigationLinks = ODataMaterializer.EmptyLinks; } else { if ((atomProperty.Value == null) && !ClientTypeUtil.CanAssignNull(property.NullablePropertyType)) { throw new InvalidOperationException(System.Data.Services.Client.Strings.AtomMaterializer_CannotAssignNull(atomProperty.Name, property.NullablePropertyType)); } ODataMaterializer.MaterializePrimitiveDataValue(property.NullablePropertyType, atomProperty); navigationLinks = ODataMaterializer.EmptyLinks; properties = ODataMaterializer.EmptyProperties; } streamLink = atomProperty.GetMaterializedValue(); } } expectedType = property.PropertyType; } } return(streamLink); }
public void WriteToMultiBufferMemoryStreamTestAPM() { using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { byte[] buffer = GetRandomBuffer(1 * 1024 * 1024); MemoryStream stream1 = new MemoryStream(buffer); RESTCommand <NullType> cmd = new RESTCommand <NullType>(TestBase.StorageCredentials, null, null); ExecutionState <NullType> state = new ExecutionState <NullType>(cmd, new NoRetry(), new OperationContext()); StreamDescriptor copyState = new StreamDescriptor(); MultiBufferMemoryStream stream2 = new MultiBufferMemoryStream(null /* bufferManager */); stream1.WriteToAsync(stream2, default(IBufferManager), null, null, false, state, copyState, CancellationToken.None, _ => waitHandle.Set()); waitHandle.WaitOne(); if (state.ExceptionRef != null) { throw state.ExceptionRef; } stream1.Seek(0, SeekOrigin.Begin); stream2.Seek(0, SeekOrigin.Begin); TestHelper.AssertStreamsAreEqual(stream1, stream2); MultiBufferMemoryStream stream3 = new MultiBufferMemoryStream(null /* bufferManager */); IAsyncResult ar = stream2.BeginFastCopyTo(stream3, DateTime.Now.AddMinutes(-1), _ => waitHandle.Set(), null); waitHandle.WaitOne(); TestHelper.ExpectedException <TimeoutException>( () => stream3.EndFastCopyTo(ar), "Past expiration time should immediately fail"); stream2.Seek(0, SeekOrigin.Begin); stream3.Seek(0, SeekOrigin.Begin); ar = stream2.BeginFastCopyTo(stream3, DateTime.Now.AddHours(1), _ => waitHandle.Set(), null); waitHandle.WaitOne(); stream2.EndFastCopyTo(ar); stream2.Seek(0, SeekOrigin.Begin); stream3.Seek(0, SeekOrigin.Begin); TestHelper.AssertStreamsAreEqual(stream2, stream3); MultiBufferMemoryStream stream4 = new MultiBufferMemoryStream(null, 12345); ar = stream3.BeginFastCopyTo(stream4, null, _ => waitHandle.Set(), null); waitHandle.WaitOne(); stream3.EndFastCopyTo(ar); stream3.Seek(0, SeekOrigin.Begin); stream4.Seek(0, SeekOrigin.Begin); TestHelper.AssertStreamsAreEqual(stream3, stream4); state = new ExecutionState <NullType>(cmd, new NoRetry(), new OperationContext()); copyState = new StreamDescriptor(); MemoryStream stream5 = new MemoryStream(); stream4.WriteToAsync(stream5, default(IBufferManager), null, null, false, state, copyState, CancellationToken.None, _ => waitHandle.Set()); waitHandle.WaitOne(); if (state.ExceptionRef != null) { throw state.ExceptionRef; } stream4.Seek(0, SeekOrigin.Begin); stream5.Seek(0, SeekOrigin.Begin); TestHelper.AssertStreamsAreEqual(stream4, stream5); TestHelper.AssertStreamsAreEqual(stream1, stream5); } }
/// <summary> /// clears all the changes - like closes the save stream, clears the transient entity descriptor. /// This method is called when the client is done with sending all the pending requests. /// </summary> internal override void ClearChanges() { this.transientNamedStreamInfo = null; this.CloseSaveStream(); }
public static extern bool StMakeStreamDescriptor(string name, uint entrySize, StreamTypeFlags flags, out StreamDescriptor descOut);
public void UpdateEntityDescriptor() { if (!this.EntityDescriptorUpdated) { if (this.entry.MediaResource != null) { if (this.entry.MediaResource.ReadLink != null) { this.EntityDescriptor.ReadStreamUri = this.entry.MediaResource.ReadLink; } if (this.entry.MediaResource.EditLink != null) { this.EntityDescriptor.EditStreamUri = this.entry.MediaResource.EditLink; } if (this.entry.MediaResource.ETag != null) { this.EntityDescriptor.StreamETag = this.entry.MediaResource.ETag; } } foreach (ODataProperty property in this.Properties) { ODataStreamReferenceValue value2 = property.Value as ODataStreamReferenceValue; if (value2 != null) { StreamDescriptor descriptor = this.EntityDescriptor.AddStreamInfoIfNotPresent(property.Name); if (value2.ReadLink != null) { descriptor.SelfLink = value2.ReadLink; } if (value2.EditLink != null) { descriptor.EditLink = value2.EditLink; } descriptor.ETag = value2.ETag; descriptor.ContentType = value2.ContentType; } } foreach (ODataAssociationLink link in this.entry.AssociationLinks) { this.EntityDescriptor.AddAssociationLink(link.Name, link.Url); } foreach (ODataFunction function in this.entry.Functions) { FunctionDescriptor operationDescriptor = new FunctionDescriptor { Title = function.Title, Metadata = function.Metadata, Target = function.Target }; this.EntityDescriptor.AddOperationDescriptor(operationDescriptor); } foreach (ODataAction action in this.entry.Actions) { ActionDescriptor descriptor3 = new ActionDescriptor { Title = action.Title, Metadata = action.Metadata, Target = action.Target }; this.EntityDescriptor.AddOperationDescriptor(descriptor3); } this.EntityDescriptorUpdated = true; } }
public static extern bool StMakeStreamDescriptorFromType( string name, ref StreamTypeDescriptor type, out StreamDescriptor descOut);
/* Stream API */ /// <summary> /// This method is a helper function to quickly create a new stream /// description needed to register a new stream. The description /// contains information about the stream's name and layout of trace /// entries, that is records written to or read from a stream. /// </summary> /// <param name="name">A friendly name of the new stream (e.g., /// "CPU Memory Accesses")</param> /// <param name="entrySize">The size of a single trace entry in bytes. /// To specify a variable-sized entry type, use /// makeVariableEntrySize().</param> /// <param name="flags">Supplies the flags used for the type of the new /// stream.</param> /// <param name="descOut">StreamDescriptor structure that will /// receive the new stream information.</param> /// <returns>true if successful, false otherwise. For a more /// detailed error description call StGetLastError().</returns> public static bool StMakeStreamDescriptor(string name, uint entrySize, StreamTypeFlags flags, out StreamDescriptor descOut) { return(NativeMethods.StMakeStreamDescriptor(name, entrySize, flags, out descOut)); }
public static extern uint StStreamRegister(uint session, ref StreamDescriptor desc);
/// <summary> /// This method is a helper function to quickly create a new stream /// description needed to register a new stream. The description /// contains information about the stream's name and layout of trace /// entries, that is records written to or read from a stream. This /// method uses the supplied type information. /// </summary> /// <param name="name">A friendly name of the new stream (e.g., /// "CPU Memory Accesses").</param> /// <param name="type">Reference to a valid StreamTypeDescriptor /// structure, defining the desired type of the new stream.</param> /// <param name="descOut">StreamDescriptor structure that will /// receive the new stream information.</param> /// <returns>true if successful, false otherwise. For a more /// detailed error description call StGetLastError().</returns> public static bool StMakeStreamDescriptorFromType(string name, ref StreamTypeDescriptor type, out StreamDescriptor descOut) { return(NativeMethods.StMakeStreamDescriptorFromType(name, ref type, out descOut)); }
private TopologyNode CreateSourceStreamNode(PresentationDescriptor presentationDescriptor, StreamDescriptor streamDescriptor) { TopologyNode inputNode; MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out inputNode); inputNode.Set(TopologyNodeAttributeKeys.Source.Guid, mediaSource); inputNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor.Guid, presentationDescriptor); inputNode.Set(TopologyNodeAttributeKeys.StreamDescriptor.Guid, streamDescriptor); return(inputNode); }