Exemple #1
0
 public ContextPropertyScope(IContextProperties properties, string key, object oldValue, bool oldValueExisted)
 {
     this.properties      = properties;
     this.key             = key;
     this.oldValue        = oldValue;
     this.oldValueExisted = oldValueExisted;
 }
Exemple #2
0
        public static IDisposable Use([NotNull] this IContextProperties properties, [NotNull] string name, [CanBeNull] object value)
        {
            var oldValueExisted = properties.Current.TryGetValue(name, out var oldValue);

            properties.Set(name, value);

            return(new ContextPropertyScope(properties, name, oldValue, oldValueExisted));
        }
Exemple #3
0
        internal bool HasEmbeddedContext(IList <string> structureInfos, IContextProperties contexts)
        {
            if (contexts == null)
            {
                return(false);
            }

            return(contexts.Contexts.Any(context => structureInfos.Contains(context.ContextType)));
        }
        // output context information, not required, but useful
        // information for the translator
        private void WriteContext(string ContextContent)
        {
            IContextProperties contextProperties = PropertiesFactory.CreateContextProperties();
            IContextInfo       contextInfo       = PropertiesFactory.CreateContextInfo(ContextContent);

            contextInfo.DisplayCode  = "EL";
            contextInfo.DisplayName  = "Element";
            contextInfo.Description  = ContextContent;
            contextInfo.DisplayColor = Color.Beige;
            contextProperties.Contexts.Add(contextInfo);
            Output.ChangeContext(contextProperties);
        }
        internal VostokHostingEnvironment(
            [NotNull] HostingShutdown hostingShutdown,
            [NotNull] ApplicationShutdown applicationShutdown,
            [NotNull] IVostokApplicationIdentity applicationIdentity,
            [NotNull] IVostokApplicationLimits applicationLimits,
            [NotNull] Func <IVostokApplicationReplicationInfo> replicationInfoProvider,
            [NotNull] IVostokApplicationMetrics metrics,
            [NotNull] IVostokApplicationDiagnostics diagnostics,
            [NotNull] ILog log,
            [NotNull] ITracer tracer,
            [NotNull] IHerculesSink herculesSink,
            [NotNull] IConfigurationSource configurationSource,
            [NotNull] IConfigurationSource secretConfigurationSource,
            [NotNull] IConfigurationProvider configurationProvider,
            [NotNull] IConfigurationProvider secretConfigurationProvider,
            [NotNull] IClusterConfigClient clusterConfigClient,
            [NotNull] IServiceBeacon serviceBeacon,
            [CanBeNull] int?port,
            [NotNull] IServiceLocator serviceLocator,
            [NotNull] IContextGlobals contextGlobals,
            [NotNull] IContextProperties contextProperties,
            [NotNull] IContextConfiguration contextConfiguration,
            [NotNull] IDatacenters datacenters,
            [NotNull] IVostokHostExtensions hostExtensions,
            [NotNull] Action onDispose)
        {
            this.hostingShutdown         = hostingShutdown ?? throw new ArgumentNullException(nameof(hostingShutdown));
            this.applicationShutdown     = applicationShutdown ?? throw new ArgumentNullException(nameof(applicationShutdown));
            this.replicationInfoProvider = replicationInfoProvider ?? throw new ArgumentNullException(nameof(replicationInfoProvider));
            this.onDispose = onDispose ?? throw new ArgumentNullException(nameof(onDispose));

            ApplicationIdentity = applicationIdentity ?? throw new ArgumentNullException(nameof(applicationIdentity));
            ApplicationLimits   = applicationLimits ?? throw new ArgumentNullException(nameof(applicationLimits));
            Metrics             = metrics ?? throw new ArgumentNullException(nameof(metrics));
            Diagnostics         = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics));
            Log                         = log ?? throw new ArgumentNullException(nameof(log));
            Tracer                      = tracer ?? throw new ArgumentNullException(nameof(tracer));
            HerculesSink                = herculesSink ?? throw new ArgumentNullException(nameof(herculesSink));
            ConfigurationSource         = configurationSource ?? throw new ArgumentNullException(nameof(configurationSource));
            ConfigurationProvider       = configurationProvider ?? throw new ArgumentNullException(nameof(configurationProvider));
            SecretConfigurationSource   = secretConfigurationSource ?? throw new ArgumentNullException(nameof(secretConfigurationSource));
            SecretConfigurationProvider = secretConfigurationProvider ?? throw new ArgumentNullException(nameof(secretConfigurationProvider));
            ClusterConfigClient         = clusterConfigClient ?? throw new ArgumentNullException(nameof(clusterConfigClient));
            ServiceBeacon               = serviceBeacon ?? throw new ArgumentNullException(nameof(serviceBeacon));
            Port                        = port;
            ServiceLocator              = serviceLocator ?? throw new ArgumentNullException(nameof(serviceLocator));
            ContextGlobals              = contextGlobals ?? throw new ArgumentNullException(nameof(contextGlobals));
            ContextProperties           = contextProperties ?? throw new ArgumentNullException(nameof(contextProperties));
            ContextConfiguration        = contextConfiguration ?? throw new ArgumentNullException(nameof(contextConfiguration));
            Datacenters                 = datacenters ?? throw new ArgumentNullException(nameof(datacenters));
            HostExtensions              = hostExtensions ?? throw new ArgumentNullException(nameof(hostExtensions));
        }
Exemple #6
0
        public static TValue Get <TValue>([NotNull] this IContextProperties properties, [NotNull] string name, [CanBeNull] TValue defaultValue = default)
        {
            if (!properties.Current.TryGetValue(name, out var value))
            {
                return(defaultValue);
            }

            if (value is TValue typedValue)
            {
                return(typedValue);
            }

            return(defaultValue);
        }
        private IContextProperties CreateContext(string unitId)
        {
            IContextProperties contextProperties = PropertiesFactory.CreateContextProperties();
            IContextInfo       contextInfo       = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph);

            contextInfo.Purpose = ContextPurpose.Information;

            // add unit id as metadata
            IContextInfo contextId = PropertiesFactory.CreateContextInfo("UnitId");

            contextId.SetMetaData("UnitID", unitId);
            contextId.Description = "Original paragraph unit id";
            contextId.DisplayCode = "ID";

            contextProperties.Contexts.Add(contextInfo);
            contextProperties.Contexts.Add(contextId);

            return(contextProperties);
        }
Exemple #8
0
        private IContextProperties CreateContext(string id, string paraId)
        {
            IContextProperties contextProperties = PropertiesFactory.CreateContextProperties();

            IContextInfo contextId = PropertiesFactory.CreateContextInfo("id");

            contextId.SetMetaData("ID", id);
            contextId.Description = "Trans-unit id";
            contextId.DisplayCode = "ID";

            IContextInfo contextParaId = PropertiesFactory.CreateContextInfo("para-id");

            contextParaId.SetMetaData("PARA ID", paraId);
            contextParaId.Description = "Para-id";
            contextParaId.DisplayCode = "PARA ID";

            contextProperties.Contexts.Add(contextId);
            contextProperties.Contexts.Add(contextParaId);

            return(contextProperties);
        }
        private IContextProperties CreateContext(string spec, string unitID)
        {
            // context info for type information, e.g. heading, paragraph, etc.
            IContextProperties contextProperties = PropertiesFactory.CreateContextProperties();
            IContextInfo       contextInfo       = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph);

            contextInfo.Purpose = ContextPurpose.Information;

            // add unit id as metadata
            IContextInfo contextId = PropertiesFactory.CreateContextInfo("UnitId");

            contextId.SetMetaData("UnitID", unitID);

            switch (spec)
            {
            case "Heading":
                contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Topic);
                contextInfo.DisplayColor = Color.Green;
                break;

            case "Box":
                contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.TextBox);
                contextInfo.DisplayColor = Color.Gold;
                break;

            case "Paragraph":
                contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph);
                contextInfo.DisplayColor = Color.Silver;
                break;

            default:
                break;
            }

            contextProperties.Contexts.Add(contextInfo);
            contextProperties.Contexts.Add(contextId);

            return(contextProperties);
        }
 public void ChangeContext(IContextProperties newContexts)
 {
     _buffer.ChangeContext(newContexts);
 }
 public static IDisposable Use <TValue>(this IContextProperties properties, string key, TValue value)
 {
     properties.Current.TryGetValue(key, out var oldValue);
     properties.SetProperty(key, value);
     return(new ContextScope(key, oldValue, properties));
 }
Exemple #12
0
 public static void Set <TValue>(this IContextProperties properties, string key, TValue value)
 {
     properties.SetProperty(key, value);
 }
Exemple #13
0
 public ContextScope(string key, object oldValue, IContextProperties properties)
 {
     this.key        = key;
     this.oldValue   = oldValue;
     this.properties = properties;
 }
 public void TestSetup()
 {
     properties = new ContextProperties();
 }
Exemple #15
0
 public UserData(IContextProperties contextProperties)
 {
     _contextProperties = contextProperties;
 }
 public static TValue Get <TValue>(this IContextProperties properties, string key, TValue defaultValue = default(TValue))
 {
     return(properties.Current.TryGetValue(key, out var value) ? (TValue)value : defaultValue);
 }
Exemple #17
0
 public static IDisposable Use([NotNull] this IContextProperties properties, [NotNull] IReadOnlyDictionary <string, object> values)
 {
     var data      = new (string, object, bool)[values.Count];