/// <summary>
        /// Stores the value into the store and returns a <see cref="StoreBackedProperty{T}" /> with the Id for retrieval
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value">The property to store</param>
        /// <returns>The link to retrieve he object from the store</returns>
        /// <exception cref="InvalidOperationException">
        /// When there is no encoder set for <typeparamref name="T"/> and <see cref="FallbackToBsonEncoder"/> is false
        /// </exception>
        public virtual async Task <StoreBackedProperty <T> > StoreValueAsync <T>(T value)
        {
            ThrowIfDisposed();
            ThrowIfNoDataCommunicator();
            var property = new StoreBackedProperty <T>(Guid.NewGuid().ToString());
            var encoder  = GetEncoder <T>();
            var bytes    = encoder.Encode(value);
            await DataCommunicator.StoreDataAsync(property.Id, bytes).ConfigureAwait(false);

            return(property);
        }
        /// <summary>
        /// Retrieves the value from the store using the <see cref="DataCommunicator"/> and the appropriate <see cref="IStoreBackedPropertyEncoder{T}"/>
        /// </summary>
        /// <typeparam name="T">The type of value to retrieve</typeparam>
        /// <param name="property">The property that is being pulled.  The <see cref="StoreBackedProperty{T}.Id"/> should be set properly</param>
        /// <returns>The deserialized property from the store</returns>
        public virtual async Task <T> GetValueAsync <T>(StoreBackedProperty <T> property)
        {
            ThrowIfDisposed();
            ThrowIfNoDataCommunicator();
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }
            var encoder = GetEncoder <T>();
            var data    = await DataCommunicator.GetDataAsync(property.Id)
                          .ConfigureAwait(false);

            return(encoder.Decode(data));
        }
예제 #3
0
        public ExtendedModule UpsertModule(IPAddress ip)
        {
            var comm = new DataCommunicator(ip);
            var dto  = comm.GetConfig();
            var mod  = mf.UpsertModule(dto, ip);
            var old  = Modules.SingleOrDefault(x => x.Module.Id == mod.Id);

            if (old != null)
            {
                moduleCache.Remove(old);
            }
            var features = mf.GetFeatures();
            var newMod   = new ExtendedModule(mod, features.Where(y => mod.FeatureIds.Contains(y.Id)),
                                              mod.Ip.Equals(IPAddress.Loopback), logger);

            moduleCache.Add(newMod);
            return(newMod);
        }
예제 #4
0
        public PresetDto[] GetAllPresets()
        {
            var comm = new DataCommunicator(Module.Ip);

            return(comm.GetAllPresets().Select(x => comm.GetPreset(x)).ToArray());
        }
예제 #5
0
        public PresetDto DownloadPreset(string presetName)
        {
            var comm = new DataCommunicator(Module.Ip);

            return(comm.GetPreset(presetName));
        }