• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IContentAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Configuration
      • Introduction
      • Configuration Binding
      • ConfigurationExtensions
      • MemoryConfiguration
      • PrintTree
      • Saving IOptions
      • Yaml
    • Avalanche.Converter
      • Introduction
      • EnumConverter
      • Func<,>
      • HexConverter
      • PrimitiveConverter
      • StringConverter
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IRealType
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystem
          • IFileSystemBrowse
          • IFileSystemCreateDirectory
          • IFileSystemDelete
          • IFileSystemFileAttribute
          • IFileSystemMount
          • IFileSystemMove
          • IFileSystemObserve
          • IFileSystemOpen
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Events
      • Utilities
        • Dispose
        • File Scanner
        • Visit Tree
        • File Operation
        • FilterEnumerable
        • PollingFilterWatchToken
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Logging
        • Validation
    • Avalanche.Options
      • Introduction
      • OptionsExtensions
      • OptionsMonitorCast
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
        • IHostBuilder
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • StorageMessages
        • ItfMessages
        • Win32Messages
        • WindowsMessages
        • SspiMessages
        • CertMessages
        • MediaServerMessages
        • SetupApiMessages
        • ScardMessages
        • ComPlusMessages
        • ClrMessages
        • UserModeFilterManagerMessages
        • GraphicsMessages
        • TpmServicesMessages
        • TpmSoftwareMessages
        • PlaMessages
        • FveMessages
        • FwpMessages
        • NdisMessages
        • DltMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Utilities
      • Introduction
      • Collections
        • Tuples
        • StructList
        • ArrayList
        • BijectionMap
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • EnumerableExtensions
        • TupleUtilities
        • ArrayUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
        • IProviderEvent
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • Reflection
        • EnumDescription
      • String
        • IEscaper
        • UnicodeString
        • Hex
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • ITreeNode
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    IEntry

    IEntry<Response> is interface for classes that hold result object. Entry is also used for tracking the build process of a value, and as cache container.

    IEntry is interface for accessing basic information.

    /// <summary>Holds and caches a value.</summary>
    public interface IEntry
    {
        /// <summary>Current status</summary>
        EntryStatus Status { get; }
        /// <summary>Policy flags</summary>
        EntryPolicy Policy { get; set; }
        /// <summary>Processing thread id. 0=unassigned.</summary>
        int ThreadId { get; set; }
    }
    

    IEntryReadable is interface for reading entry state.

    /// <summary>Indiciates that entry is readable.</summary>
    public interface IEntryReadable : IEntry
    {
        /// <summary>Error</summary>
        Exception? Error { get; }
        /// <summary>Snapshot of state</summary>
        EntryState State { get; }
        /// <summary>Entry value as object.</summary>
        object? Value { get; }
    }
    

    IEntryReadable<T> is for reading as T.

    /// <summary>Readable entry of <typeparamref name="T"/> value.</summary>
    public interface IEntryReadable<out T> : IEntryReadableT
    {
        /// <summary>Entry value as <typeparamref name="T"/>.</summary>
        new T Value { get; }
    }
    

    IEntryWritable is for writing entry state.

    /// <summary>Indiciates that entry is writable.</summary>
    public interface IEntryWritable : IEntry
    {
        /// <summary>Try to mark entry into processing state. Only one thread may reserve the processing state. The thread that gets the state must complete the entry into <see cref="EntryStatus.Completed"/> state, and other threads must wait for it.</summary>
        /// <returns>True if state changed from <see cref="EntryStatus.Unassigned"/> to <see cref="EntryStatus.Processing"/></returns>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetProcessing();
    
        /// <summary>Try dispose associated value.</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetCanceled();
    
        /// <summary>Try to assign <see cref="EntryStatus.NoValue"/> state.</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetNoValue();
    
        /// <summary>Try to assign <paramref name="value"/>.</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetValue(object? value);
    
        /// <summary>Try to assign default value, e.g. null</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetValueDefault();
    
        /// <summary>Try to assign <paramref name="errorValue"/> and set state to <see cref="EntryStatus.Error"/>.</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetError(Exception errorValue);
    
        /// <summary>Assign <paramref name="error"/> and set state to <see cref="EntryStatus.UnexpectedError"/>.</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetUnexpectedError(Exception error);
    
        /// <summary>Assign flags.</summary>
        /// <exception cref="Exception">Unexpected error (from an observer)</exception>
        bool TrySetFlags(EntryStatus flagsToInclude, EntryStatus flagsToExclude);
    
        /// <summary>
        /// Try to dispose associated value.
        /// Entry must be in <see cref="EntryStatus.Value"/> state.
        /// If value implements <see cref="IDisposable"/> it's called, if not then function succeeds.
        /// If dispose fails, then exception is let to fly, and state is not changed.
        /// 
        /// If dispose was successful or value did not implement <see cref="IDisposable"/> then state is changed to <see cref="EntryStatus.ValueDisposed"/>.
        /// </summary>
        /// <exception cref="AggregateException">Any exception thrown from <see cref="IDisposable.Dispose"/> or observers.</exception>
        bool TryDisposeValue();
    
        /// <summary>
        /// Try to the reference to the associated value. 
        /// Entry must be in <see cref="EntryStatus.Value"/>, <see cref="EntryStatus.Error"/>, <see cref="EntryStatus.UnexpectedError"/> or <see cref="EntryStatus.ValueDisposed"/> state.
        /// If value has not been dispose, this method does not dispose it. 
        /// 
        /// If value is not nullable then default value is set. 
        /// State of entry is set to <see cref="EntryStatus.ValueNulled"/>.
        /// </summary>
        /// <exception cref="Exception">Any exception thrown from observers.</exception>
        bool TryNullValue();
    }
    

    IEntryWritable<T> is for writing value as T.

    /// <summary>Writable entry for <typeparamref name="T"/> values.</summary>
    public interface IEntryWritable<in T> : IEntryWritableT
    {
        /// <summary>Assign <paramref name="value"/>.</summary>
        bool TrySetValue(T value);
    }
    

    Usage

    Entry<T> is the default implementation.

    // Create entry
    IEntry<string> entry = new Entry<string>();
    

    .SetProcessing() marks entry into Processing state.

    // Set processing
    entry.SetProcessing();
    

    .SetValue() assigns a value.

    // Set value
    entry.SetValue("Result");
    

    .SetError() assigns an error state.

    // Set error result
    entry.SetError(new NotSupportedException());
    

    .SetQueryError() assigns an unexpected error (cathed from handler).

    // Set unexpected error
    entry.SetUnexpectedError(new InvalidOperationException());
    

    .Dispose() disposes entry and value.

    // Disepose entry and value
    ((IDisposable)entry).Dispose();
    

    Full Example

    Full example
    using System;
    using System.Threading;
    using Avalanche.Service;
    using static System.Console;
    
    public class entry_entry
    {
        public static void Run()
        {
            {
                // <01>
                // Create entry
                IEntry<string> entry = new Entry<string>();
                // </01>
                // Print status
                WriteLine(entry.Status); // "Unassigned"
            }
            {
                // Create entry
                IEntry<string> entry = new Entry<string>();
                // <02>
                // Set processing
                entry.SetProcessing();
                // </02>
                // Print status
                WriteLine(entry.Status); // "Processing"
            }
            {
                // Create entry
                IEntry<string> entry = new Entry<string>();
                // <03>
                // Set value
                entry.SetValue("Result");
                // </03>
                // Print status
                WriteLine(entry.Status); // "Value"
            }
            {
                // Create entry
                IEntry<string> entry = new Entry<string>();
                // <04>
                // Set error result
                entry.SetError(new NotSupportedException());
                // </04>
                // Print status
                WriteLine(entry.Status); // "Error"
            }
            {
                // Create entry
                IEntry<string> entry = new Entry<string>();
                // <05>
                // Set unexpected error
                entry.SetUnexpectedError(new InvalidOperationException());
                // </05>
                // Print status
                WriteLine(entry.Status); // "UnexpectedError"
            }
            {
                // Create entry
                IEntry<Semaphore> entry = new Entry<Semaphore>(EntryPolicy.Default);
                // Set value
                entry.SetValue(new Semaphore(1, 1));
                // <06>
                // Disepose entry and value
                ((IDisposable)entry).Dispose();
                // </06>
                // Print status
                WriteLine(entry.Status); // "Disposed"
            }
        }
    }
    
    In This Article
    Back to top Copyright © Toni Kalajainen