/// <summary>
        /// Create a new fork
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="parentForkId">If parent is null, a new master fork will be created</param>
        /// <returns>New fork id</returns>
        public int CreateFork(string name, string description, int?parentForkId = null)
        {
            var forkIds = GetForkIds();
            var newId   = forkIds.Max() + 1;

            forkIds.Add(newId);
            SetForkIds(forkIds);

            var newFork = new ForkRawData
            {
                Id              = newId,
                Name            = name,
                Description     = description,
                ParentId        = parentForkId ?? 0,
                IsInGracePeriod = true
            };

            if (parentForkId.HasValue)
            {
                var parentFork = GetFork(parentForkId.Value);

                parentFork.ChildrenIds.Add(newFork.Id);
                SetFork(parentFork);
            }
            SetFork(newFork);

            HandleGracePeriod(newFork);

            return(newId);
        }
        private void HandleGracePeriod(ForkRawData newFork)
        {
            Thread.Sleep(TimeSpan.FromSeconds(1));

            var fork = GetFork(newFork.Id);

            fork.IsInGracePeriod = false;
            SetFork(fork);

            Thread.Sleep(TimeSpan.FromSeconds(1));
        }
        private void CreateMasterFork()
        {
            var forkIds = new List <int>();

            forkIds.Add(1);

            var masterFork = new ForkRawData
            {
                Id   = 1,
                Name = "master"
            };

            SetForkIds(forkIds);
            SetFork(masterFork);
        }
 private void UpdateFork(Fork forkToUpdate, ForkRawData forkRawData)
 {
     forkToUpdate.Name            = forkRawData.Name;
     forkToUpdate.Description     = forkRawData.Description;
     forkToUpdate.IsInGracePeriod = forkRawData.IsInGracePeriod;
 }
 private void SetFork(ForkRawData fork)
 {
     KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.GenerateForkKey(AppId, fork.Id), ProtoBufSerializerHelper.Serialize(fork), null);
     KeyValueStore.Set(KeyValueStore.DefaultType, KeyGenerator.GenerateForkTimeStampKey(AppId, fork.Id), BinarySerializerHelper.SerializeObject(DateTime.UtcNow), null);
 }