Beispiel #1
0
        public void Get(string key, Action <PackageCacherResponse> response)
        {
            lock (_lock)
            {
                if (cacheContent.ContainsKey(key))
                {
                    var bundle = cacheContent[key];
                    bundle.UpdateLastAccessTime();
                    if (bundle.IsDownloaded)
                    {
                        U.LogDebug(U.Message(IU.FILE_FOUND_BY_KEY, U.Arg("Key", key)));
                        response(new PackageCacherResponse(key, bundle.LocalAddress, null, bundle.RevisionNumber));
                    }
                    else
                    {
                        U.LogDebug(U.Message(IU.FILE_IS_DOWNLOADING, U.Arg("Key", key)));
                        bundle.PackageDownloaded +=
                            (sender, args) => { response(new PackageCacherResponse(key, bundle.LocalAddress, null, bundle.RevisionNumber)); };
                    }
                    return;
                }
            }

            U.LogDebug(U.Message(IU.KEY_NOT_FOUND, U.Arg("Key", key)));

            response(new PackageCacherResponse(key, null, null, -1));
        }
Beispiel #2
0
        public void Remove(string key)
        {
            lock (_lock)
            {
                if (cacheContent.ContainsKey(key))
                {
                    cacheContent.Remove(key);

                    U.LogDebug(U.Message(IU.ENTRY_REMOVED, U.Arg("Key", key)));
                }
            }
        }
Beispiel #3
0
        public void RegisterDownloaded(string key, int revisionNumber)
        {
            lock (_lock)
            {
                cacheContent[key].RevisionNumber = revisionNumber;
                cacheContent[key].UpdateLastAccessTime();
                cacheContent[key].SetDownloaded();

                U.LogDebug(U.Message(IU.ADDRESS_CONFIRMED, U.Arg("Key", key),
                                     U.Arg("RevNumber", revisionNumber)));
            }
        }
Beispiel #4
0
        public string ReserveAddress(string key)
        {
            lock (_lock)
            {
                string localAddress = null;

                if (cacheContent.ContainsKey(key))
                {
                    throw new InvalidDataException(U.Message(IU.NOT_ALLOWED_KEYS_DUPLICATION,
                                                             U.Arg("Key", key)));
                }
                localAddress = GetLocalAddress(key);
                var bundle = new StaffBundle()
                {
                    LocalAddress = localAddress,
                };
                cacheContent.Add(key, bundle);

                U.LogDebug(U.Message(IU.LOCAL_ADDRESS_RESERVED, U.Arg("LocalAddress", localAddress)));

                return(localAddress);
            }
        }