Ejemplo n.º 1
0
        public async Task <bool> Update(IStorableObject o)
        {
            await cache.InsertObject(o.CacheKey, JsonConvert.SerializeObject(o, o.GetType(), settings));

            Debug.WriteLine("Updating in the cache: {0} ", o);
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Delete(IStorableObject o)
        {
            await cache.InvalidateObject <IStorableObject>(o.CacheKey);

            Debug.WriteLine("Deleting from the cache: {0} ", o);
            return(true);
        }
Ejemplo n.º 3
0
        public async Task <bool> Delete(IStorableObject o, bool deleteChildren)
        {
            bool success = true;
            var  delete  = (o is User) ? UserInitiated.Delete((o as User).UserToken, deleteChildren) : UserInitiated.Delete(o as MedicalDevice);

            if (await FinetunerServerReachable())
            {
                //returns void - to solve
                await Policy
                .Handle <WebException>()
                .WaitAndRetryAsync
                (
                    retryCount: 5,
                    sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                )
                .ExecuteAsync(async() => await delete);
            }
            else
            {
                o.ExpirationTime = DateTime.Now;
                Queue.Enqueue(o);
                System.Diagnostics.Debug.WriteLine(Queue);
            }
            return(success);
        }
Ejemplo n.º 4
0
        public async Task <bool> Store(IStorableObject o, string key)
        {
            await cache.InsertObject(key, JsonConvert.SerializeObject(o, o.GetType(), settings));

            Debug.WriteLine("Storing in the cache: {0} ", o);
            return(true);
        }
Ejemplo n.º 5
0
        internal static T LoadObjectFromContent <T>(Repository repo, GitObjectReader input, string sha, long length) where T : IStorableObject
        {
            ConstructorInfo constr = typeof(T).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Repository), typeof(String) }, null);
            IStorableObject result = (IStorableObject)constr.Invoke(new object[] { repo, sha });

            // Let the respective object type load itself from the object content
            result.Deserialize(input);

            return((T)result);
        }
Ejemplo n.º 6
0
        internal static Tag Load(Repository repo, string sha, string path)
        {
            if (!Utility.IsValidSHA(sha))
            {
                throw new ParseException("Tag does not contain valid sha");
            }

            IStorableObject obj = repo.Storage.GetObject(sha);

            // This is kind of flaky but for now the only way we can distinguish a regular and a lightweight tag
            if (obj is Tag)
            {
                ((Tag)obj).Path = path;
                return((Tag)obj);
            }
            else
            {
                Tag t = new Tag(repo, sha);
                t.Object = obj;
                t.Path   = path;
                return(t);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Find object in database and return it as an IStorableObject. Use the generic overload if you know the type up front. Throws ObjectNotFoundException if object was not found in database.
        /// </summary>
        /// <param name="sha">SHA object identifier. Throws ArgumentException if it is null or not a valid sha</param>
        /// <returns>GitObject in database</returns>
        public IStorableObject GetObject(string sha)
        {
            if (!Utility.SHAExpression.IsMatch(sha))
            {
                throw new ArgumentException("Need a valid sha", "sha");
            }


            string looseObjectPath = Path.Combine(ObjectsDir, Path.Combine(sha.Substring(0, 2), sha.Substring(2)));

            // First check if object is stored in loose format
            if (File.Exists(looseObjectPath))
            {             // Object is stored loose. Inflate and load it from content
                using (GitObjectReader reader = new GitObjectReader(Zlib.Decompress(looseObjectPath)))
                {
                    long       size;
                    ObjectType type;
                    size = reader.ReadObjectHeader(out type);

                    switch (type)
                    {
                    case ObjectType.Commit:
                        return(ObjectStorage.LoadObjectFromContent <Commit>(Repo, reader, sha, size));

                    case ObjectType.Tree:
                        return(ObjectStorage.LoadObjectFromContent <Tree>(Repo, reader, sha, size));

                    case ObjectType.Blob:
                        return(ObjectStorage.LoadObjectFromContent <Blob>(Repo, reader, sha, size));

                    case ObjectType.Tag:
                        return(ObjectStorage.LoadObjectFromContent <Tag>(Repo, reader, sha, size));

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            else
            {
                IStorableObject result = null;
                foreach (Pack pack in Packs)
                {
                    try
                    {
                        result = pack.GetObject(sha);
                    }
                    catch (ObjectNotFoundException)
                    {  }
                }

                if (result != null)
                {
                    return(result);
                }
            }


            // Object was not found
            throw new ObjectNotFoundException(sha);
        }
Ejemplo n.º 8
0
 public bool Store(IStorableObject target)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 public bool SaveToDatabase(IStorableObject target)
 {
     throw new NotImplementedException();
 }