Beispiel #1
0
        /// <inheritdoc />
        public Result <InfoPin> SetPin(string path, string description)
        {
            if (_disposed)
            {
                return(Result <InfoPin> .Failure(NoDb));
            }

            lock (_storageLock)
            {
                try
                {
                    _writeLock = true;
                    var pins = _db.GetCollection <InfoPin>("pins");
                    if (pins == null)
                    {
                        return(Result <InfoPin> .Failure(NoDb));
                    }
                    var pin = new InfoPin {
                        Id = path, Description = description
                    };
                    pins.Upsert(path, pin);
                    return(Result <InfoPin> .Success(pin));
                }
                finally
                {
                    _writeLock = false;
                }
            }
        }
        /// <inheritdoc />
        public Result <InfoPin> GetPin(string path)
        {
            var ok = _db.Get($"pins/{path}", out var rawStream);

            return((ok && rawStream != null)
                ? Result <InfoPin> .Success(InfoPin.FromStream(rawStream))
                : Result <InfoPin> .Failure(NotFound));
        }
        /// <inheritdoc />
        public Result <InfoPin> SetPin(string path, string description)
        {
            var pin = new InfoPin {
                Id = path, Description = description
            };

            _db.WriteDocument($"pins/{path}", pin.ToStream());
            return(Result <InfoPin> .Success(pin));
        }
        /// <inheritdoc />
        public Result <InfoPin[]> ReadAllPins()
        {
            var pinPaths = _db.Search("pins/");

            var result = new List <InfoPin>();

            foreach (var path in pinPaths)
            {
                var ok = _db.Get(path, out var rawStream);
                if (ok && rawStream != null)
                {
                    result.Add(InfoPin.FromStream(rawStream));
                }
            }

            return(Result <InfoPin[]> .Success(result.ToArray()));
        }