Beispiel #1
0
        public async void DeleteFile(BasicAuthentication authentication, string project, string repo, string branch, string filename, string commitComment)
        {
            var client             = new RestHttpClient();
            var url                = $"{authentication.AccountUrl}/{project}/_apis/git/repositories/{repo}/pushes?api-version=2.0-preview&versionType=branch&version={branch}";
            var filePush           = new Push();
            var filePushRefUpdates = new RefUpdate
            {
                name        = $"refs/heads/{branch}",
                oldObjectId = GetBranchObjectId(authentication, project, repo, branch)
            };

            filePush.refUpdates.Add(filePushRefUpdates);

            var commit = new Commit();
            var change = new Change
            {
                changeType = "delete",
                item       = { path = filename }
            };

            commit.changes.Add(change);

            commit.comment = commitComment;

            filePush.commits.Add(commit);

            await client.PostAsync <object>(authentication, url, filePush);
        }
Beispiel #2
0
        public async void SaveTextFile(BasicAuthentication authentication, string project, string repo, string branch, string filename, string contents, string commitComment, bool isNewFile)
        {
            var client             = new RestHttpClient();
            var url                = $"{authentication.AccountUrl}/{project}/_apis/git/repositories/{repo}/pushes?api-version=2.0-preview&versionType=branch&version={branch}&scopePath={filename}";
            var filePush           = new Push();
            var filePushRefUpdates = new RefUpdate
            {
                name        = $"refs/heads/{branch}",
                oldObjectId = GetBranchObjectId(authentication, project, repo, branch)
            };


            filePush.refUpdates.Add(filePushRefUpdates);

            var commit = new Commit();
            var change = new Change
            {
                changeType = isNewFile ? "add" : "edit",
                item       = { path = filename },
                newContent = new NewContent
                {
                    content     = contents,
                    contentType = "rawtext"
                }
            };

            commit.changes.Add(change);

            commit.comment = commitComment;

            filePush.commits.Add(commit);

            await client.PostAsync <object>(authentication, url, filePush);
        }
Beispiel #3
0
        public async void Post()
        {
            var todo = new Todo
            {
                UserId = 1,
                Title  = "Lorem Ipsum"
            };

            var item = await client.PostAsync <Todo>("todos", todo);

            Assert.Equal(todo.UserId, item.UserId);
            Assert.Equal(todo.Title, item.Title);
        }
Beispiel #4
0
        public async Task PushAsync <T>() where T : EntityBase, new()
        {
            var items       = Connection.Table <T>().Where(e => e.Id == null).ToList();
            var remoteItems = await _client.PostAsync <List <T> >("contacts", items);

            for (int i = 0; i < remoteItems.Count; i++)
            {
                var local  = items[i];
                var remote = remoteItems[i];

                remote.Status  = EntityStatus.Synchronized;
                remote.LocalId = local.LocalId;
            }

            Connection.UpdateAll(remoteItems);
        }