示例#1
0
        /// <summary>
        /// Creates new context <see cref="IContext"/>.
        /// </summary>
        /// <param name="fullCorrelationId">Full correlation-id.</param>
        /// <param name="correlationId">Correlation-id of context to be created.</param>
        /// <param name="localTag">Special user defined tag.</param>
        /// <param name="ct">Cancellation token.</param>
        /// <param name="disposeRegistry">Dispose registry.</param>
        /// <param name="progress">Progress reporter.</param>
        /// <param name="displayName">Display name.</param>
        /// <param name="outerCtx">Outer context of context to be created.</param>
        /// <returns></returns>
        public static IContext Create(
            XFullCorrelationId fullCorrelationId = default,
            ArgumentPlaceholder <XCorrelationId> correlationId = default,
            object localTag = default,
            ArgumentPlaceholder <CancellationToken> ct = default,
            ArgumentPlaceholder <IVh <IDisposeRegistry> > disposeRegistry        = default,
            ArgumentPlaceholder <IVh <IAsyncProgress <IFormattable> > > progress = default,
            ArgumentPlaceholder <IFormattable> displayName = default,
            IContext outerCtx = default)
        {
            //
            var ctx = new GenericContext(fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, outerCtx: outerCtx);

            //
            if (ct.HasExplicitValue)
            {
                CtProp.SetLocalValue(ctx: ctx, value: ct.ExplicitValue);
            }
            if (disposeRegistry.HasExplicitValue)
            {
                DisposeRegistryProp.SetLocalValue(ctx: ctx, value: disposeRegistry.ExplicitValue);
            }
            if (progress.HasExplicitValue)
            {
                ProgressProp.SetLocalValue(ctx: ctx, value: progress.ExplicitValue);
            }
            if (displayName.HasExplicitValue)
            {
                DisplayNameProp.SetLocalValue(ctx: ctx, value: displayName.ExplicitValue);
            }
            //
            return(ctx);
        }
示例#2
0
 public static IContext New(
     this IContext outerCtx,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag = default,
     ArgumentPlaceholder <CancellationToken> ct = default,
     ArgumentPlaceholder <IVh <IDisposeRegistry> > disposeRegistry        = default,
     ArgumentPlaceholder <IVh <IAsyncProgress <IFormattable> > > progress = default,
     ArgumentPlaceholder <IFormattable> displayName = default)
 => Create(outerCtx: outerCtx, fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, ct: ct, disposeRegistry: disposeRegistry, progress: progress, displayName: displayName);
示例#3
0
 protected MetadataLoadContextBase(
     bool skipLinkedMetadata,
     Uri baseUri,
     string mediaType = default,
     Uri siteOrigin   = default,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag   = default,
     IContext outerCtx = default)
     : base(baseUri: baseUri, mediaType: mediaType, siteOrigin: siteOrigin, fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, outerCtx: outerCtx)
 {
     //
     _skipLinkedMetadata = skipLinkedMetadata;
 }
示例#4
0
 public SubjectFileLoadContext(
     Uri fileUri,
     string mediaType = default,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag         = default,
     IContext ambientContext = default)
     : base(
         baseUri: fileUri.Arg(nameof(fileUri)).EnsureFileScheme().EnsureLoopbackOrUnc(),
         mediaType: mediaType,
         fullCorrelationId: fullCorrelationId,
         correlationId: correlationId,
         localTag: localTag,
         outerCtx: ambientContext)
 {
 }
示例#5
0
 public SubjectFileLoadContext(
     string localFilePath,
     string mediaType = default,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag         = default,
     IContext ambientContext = default)
     : this(
         fileUri : new Uri(uriString : localFilePath.Arg(nameof(localFilePath)).EnsureNotNullOrWhiteSpace(), uriKind : UriKind.Absolute),
         mediaType : mediaType,
         fullCorrelationId : fullCorrelationId,
         correlationId : correlationId,
         localTag : localTag,
         ambientContext : ambientContext)
 {
 }
示例#6
0
 public DescriptionPackageLoadContext(
     DescriptionPackageLocator locator,
     Uri loadUri,
     bool skipLinkedMetadata,
     string mediaType = default,
     Uri siteOrigin   = default,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag   = default,
     IContext outerCtx = default)
     : base(skipLinkedMetadata: skipLinkedMetadata, baseUri: loadUri, mediaType: mediaType, siteOrigin: siteOrigin, fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, outerCtx: outerCtx)
 {
     //
     locator.EnsureNotNull(nameof(locator));
     //
     _locator = locator;
 }
示例#7
0
 public SubjectFileLoadContext(
     FileInfo localFile,
     string mediaType = default,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag         = default,
     IContext ambientContext = default)
     : this(
         fileUri : new Uri(localFile.EnsureNotNull(nameof(localFile)).Value.FullName, UriKind.Absolute),
         mediaType : mediaType,
         fullCorrelationId : fullCorrelationId,
         correlationId : correlationId,
         localTag : localTag,
         ambientContext : ambientContext)
 {
     //
     _file = localFile;
 }
示例#8
0
 public DescriptionPackageFileLoadContext(
     DescriptionPackageLocator locator,
     Uri fileUri,
     bool skipLinkedMetadata,
     string mediaType = default,
     Uri siteOrigin   = default,
     XFullCorrelationId fullCorrelationId = default,
     ArgumentPlaceholder <XCorrelationId> correlationId = default,
     object localTag   = default,
     IContext outerCtx = default)
     : base(
         locator: locator,
         loadUri: fileUri.Arg(nameof(fileUri)).EnsureAbsolute().EnsureFileScheme().EnsureLoopbackOrUnc().Value,
         skipLinkedMetadata: skipLinkedMetadata,
         mediaType: mediaType,
         siteOrigin: siteOrigin,
         fullCorrelationId: fullCorrelationId,
         correlationId: correlationId,
         localTag: localTag,
         outerCtx: outerCtx)
 {
 }
示例#9
0
        /// <summary>
        /// Creates a new context using context class <typeparamref name="TContext"/> special constructor.
        /// <para>A special constructor must meet the following signature: (<see cref="XFullCorrelationId"/> fullCorrelationId, <see cref="ArgumentPlaceholder{XCorrelationId}"/> correlationId, <see cref="object"/> localTag, <see cref="IContext"/> outerCtx).</para>
        /// <para>Visibility level of a special constructor doesn't matter.</para>
        /// </summary>
        /// <typeparam name="TContext">Type of context to be created.</typeparam>
        /// <param name="fullCorrelationId">
        /// Full correlation-id.
        /// </param>
        /// <param name="correlationId">
        /// Correlation-id of context to be created.
        /// </param>
        /// <param name="localTag">
        /// Special user defined tag.
        /// </param>
        /// <param name="ct">
        /// Cancellation token.
        /// </param>
        /// <param name="disposeRegistry">
        /// Dispose registry.
        /// </param>
        /// <param name="progress">
        /// Progress reporter.
        /// </param>
        /// <param name="displayName">
        /// Display name.
        /// </param>
        /// <param name="outerCtx">Outer context of context to be created.</param>
        public static TContext Create <TContext>(
            XFullCorrelationId fullCorrelationId = default,
            ArgumentPlaceholder <XCorrelationId> correlationId = default,
            object localTag = default,
            ArgumentPlaceholder <CancellationToken> ct = default,
            ArgumentPlaceholder <IVh <IDisposeRegistry> > disposeRegistry        = default,
            ArgumentPlaceholder <IVh <IAsyncProgress <IFormattable> > > progress = default,
            ArgumentPlaceholder <IFormattable> displayName = default,
            IContext outerCtx = default)
            where TContext : class, IContext
        {
            //
            var ctx =
                ActivationUtilities
                .RequireConstructor <XFullCorrelationId, ArgumentPlaceholder <XCorrelationId>, object, IContext, TContext>()
                    (arg1 : fullCorrelationId, arg2 : correlationId, arg3 : localTag, arg4 : outerCtx);

            //
            if (ct.HasExplicitValue)
            {
                CtProp.SetLocalValue(ctx: ctx, value: ct.ExplicitValue);
            }
            if (disposeRegistry.HasExplicitValue)
            {
                DisposeRegistryProp.SetLocalValue(ctx: ctx, value: disposeRegistry.ExplicitValue);
            }
            if (progress.HasExplicitValue)
            {
                ProgressProp.SetLocalValue(ctx: ctx, value: progress.ExplicitValue);
            }
            if (displayName.HasExplicitValue)
            {
                DisplayNameProp.SetLocalValue(ctx: ctx, value: displayName.ExplicitValue);
            }
            //
            return(ctx);
        }
示例#10
0
        public static IContext New(
            this IContext outerCtx,
            IDataContext2 dataCtx,
            XFullCorrelationId fullCorrelationId = default,
            ArgumentPlaceholder <XCorrelationId> correlationId = default,
            object localTag = default,
            ArgumentPlaceholder <CancellationToken> ct = default,
            ArgumentPlaceholder <IVh <IDisposeRegistry> > disposeRegistry        = default,
            ArgumentPlaceholder <IVh <IAsyncProgress <IFormattable> > > progress = default,
            ArgumentPlaceholder <IFormattable> displayName = default)
        {
            //
            var newCtx = default(IContext);

            try {
                newCtx = ContextUtilities.Create(outerCtx: outerCtx, fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, ct: ct, disposeRegistry: disposeRegistry, progress: progress, displayName: displayName);
                DataContextFlowContextProps.DataContextProp.SetLocalValue(ctx: newCtx, value: dataCtx);
                return(newCtx);
            }
            catch (Exception exception) {
                newCtx?.Dispose(exception);
                throw;
            }
        }
示例#11
0
 // TODO: Put strings into the resources.
 //
 public GenericContext(XFullCorrelationId fullCorrelationId = default, ArgumentPlaceholder <XCorrelationId> correlationId = default, object localTag = default, IContext outerCtx = default)
 {
     if (!(outerCtx is null))
     {
         fullCorrelationId.Arg(nameof(fullCorrelationId)).EnsureIsNull();
     }
示例#12
0
 protected SubjectLoadContextBase(Uri baseUri, string mediaType = default, Uri siteOrigin = default, XFullCorrelationId fullCorrelationId = default, ArgumentPlaceholder <XCorrelationId> correlationId = default, object localTag = default, IContext outerCtx = default)
     : base(fullCorrelationId: fullCorrelationId, correlationId: correlationId, localTag: localTag, outerCtx: outerCtx)
 {
     //
     SubjectLoadContextProps.SubjectLoadBaseUriProp.SetLocalValue(ctx: this, baseUri.Arg(nameof(baseUri)));
     SubjectLoadContextProps.SubjectLoadSiteOriginProp.SetLocalValue(ctx: this, siteOrigin is null ? baseUri.Arg(nameof(baseUri)) : siteOrigin.Arg(nameof(baseUri)));
     SubjectLoadContextProps.SubjectLoadMediaTypeProp.SetLocalValue(ctx: this, value: mediaType ?? MediaTypeNameUtilities.AppOctetStream);
 }