Пример #1
0
        /// <summary>
        /// Loads the specified HV item-types assembly.  If not found or fails to load, returns null.
        /// </summary>
        private static Assembly GetItemTypesAssembly(string name)
        {
            // otherwise, try loading it by name
            Assembly coreAssemblyName = typeof(ItemTypeManager).GetTypeInfo().Assembly;

            var itemTypesAssemblyName = new AssemblyName
            {
                Name        = name,
                Version     = coreAssemblyName.GetName().Version,
                CultureName = coreAssemblyName.GetName().CultureName
            };

            itemTypesAssemblyName.SetPublicKeyToken(coreAssemblyName.GetName().GetPublicKeyToken());

            HealthVaultPlatformTrace.Log(
                TraceEventType.Information,
                "Looking for ItemTypes assembly '{0}': {1}",
                name,
                itemTypesAssemblyName.FullName);

            try
            {
                return(Assembly.Load(itemTypesAssemblyName));
            }
            catch (FileNotFoundException e)
            {
                // assembly not found
                HealthVaultPlatformTrace.Log(
                    TraceEventType.Information,
                    "ItemTypes assembly '{0}' loading skipped.  It was not found: {1}",
                    name,
                    e.Message);

                return(null);
            }
            catch (IOException e)
            {
                // assembly found, but failed to load
                HealthVaultPlatformTrace.Log(
                    TraceEventType.Warning,
                    "ItemTypes assembly '{0}' loading skipped.  It was found, but failed to load: {1}",
                    name,
                    e.Message);

                return(null);
            }
            catch (BadImageFormatException e)
            {
                // assembly found, but not valid
                HealthVaultPlatformTrace.Log(
                    TraceEventType.Warning,
                    "ItemTypes assembly '{0}' loading skipped.  It was found, but was not valid: {1}",
                    name,
                    e.Message);

                return(null);
            }
        }
        private async Task <HealthServiceResponseData> SendRequestAsync(string requestXml, Guid?correlationId = null)
        {
            try
            {
                Debug.WriteLine($"Sent message: {requestXml}");

                byte[] requestXmlBytes = Encoding.UTF8.GetBytes(requestXml);

                CancellationTokenSource cancellationTokenSource = null;
                HttpResponseMessage     response;
                try
                {
                    cancellationTokenSource = new CancellationTokenSource(Configuration.RequestTimeoutDuration);

                    response = await _webRequestClient.SendAsync(
                        ServiceInstance.HealthServiceUrl,
                        requestXmlBytes,
                        requestXml.Length,
                        new Dictionary <string, string> {
                        { CorrelationIdContextKey, correlationId.GetValueOrDefault(Guid.NewGuid()).ToString() }
                    },
                        (CancellationToken)cancellationTokenSource?.Token).ConfigureAwait(false);
                }
                finally
                {
                    cancellationTokenSource?.Dispose();
                }

                // Platform returns a platform request id with the responses. This allows
                // developers to have additional information if necessary for debugging/logging purposes.
                Guid responseId;
                if (response.Headers != null &&
                    response.Headers.Contains(ResponseIdContextKey) &&
                    Guid.TryParse(response.Headers.GetValues(ResponseIdContextKey)?.FirstOrDefault(), out responseId))
                {
                    // TODO: Provide a plug in for applications to plug in their telemetry
                    if (HealthVaultPlatformTrace.LoggingEnabled)
                    {
                        HealthVaultPlatformTrace.Log(TraceEventType.Information, "Response Id: {0}", responseId);
                    }
                }

                HealthServiceResponseData responseData = await _healthServiceResponseParser.ParseResponseAsync(response).ConfigureAwait(false);

                return(responseData);
            }
            catch (XmlException xmlException)
            {
                throw new HealthServiceException(
                          Resources.InvalidResponseFromXMLRequest,
                          xmlException);
            }
        }