Example #1
0
        private static bool UpdateWorkItem(TFSData proxy, WorkItem workItem)
        {
            var success = true;
            workItem.Title = "Updated Title from the OData service for TFS";
            workItem.StackRank = "1.5";
            workItem.Priority = "2";
            workItem.Severity = "1 - Critical";
            workItem.Description = "Updated description from the OData service for TFS";
            workItem.ReproSteps = "Updated repro steps from the OData service for TFS";

            proxy.UpdateObject(workItem);
            var result = proxy.SaveChanges(System.Data.Services.Client.SaveChangesOptions.ReplaceOnUpdate);

            Console.WriteLine("Batch status code: {0}", result.BatchStatusCode);

            foreach (var opeartionResponse in result)
            {
                Console.WriteLine("Operation status code: {0}", opeartionResponse.StatusCode);
                if (opeartionResponse.Error != null)
                {
                    Console.WriteLine("Operation error: {0}", opeartionResponse.Error.Message);
                    success = false;
                }
            }

            return success;
        }
Example #2
0
        private static bool CreateNewWorkItem(TFSData proxy, string teamProject, string workItemType, string title)
        {
            var success = true;
            var workItem = WorkItem.CreateWorkItem(0, 0, DateTime.Now, DateTime.Now);
            workItem.Project = teamProject;
            workItem.Type = workItemType;
            workItem.Title = title;
            workItem.AreaPath = teamProject;
            workItem.IterationPath = teamProject;
            workItem.Reason = "New";
            workItem.StackRank = "3.5";
            workItem.Priority = "2";
            workItem.Severity = "1 - Critical";
            workItem.Description = "Sample description for a new Work Item created through the OData service for TFS";
            workItem.ReproSteps = "Sample repro steps for a new Work Item created through the OData service for TFS";

            proxy.AddToWorkItems(workItem);
            var result = proxy.SaveChanges();

            Console.WriteLine("Batch status code: {0}", result.BatchStatusCode);

            foreach (var opeartionResponse in result)
            {
                Console.WriteLine("Operation status code: {0}", opeartionResponse.StatusCode);
                if (opeartionResponse.Error != null)
                {
                    Console.WriteLine("Operation error: {0}", opeartionResponse.Error.Message);
                    success = false;
                }
            }

            return success;
        }
Example #3
0
        private static TFSData CreateTFSServiceProxy(out string baseUrl, out string teamProject, out string workItemType)
        {
            var projectCollection = ConfigReader.GetConfigValue("ODataTFS.TfsProjectCollection");

            baseUrl = ConfigReader.GetConfigValue("ODataTFS.BaseUrl");
            if (baseUrl.EndsWith("/"))
            {
                baseUrl = baseUrl.Remove(baseUrl.Length - 1);
            }

            baseUrl = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", baseUrl, projectCollection);

            teamProject = ConfigReader.GetConfigValue("ODataTFS.TfsTeamProject");
            workItemType = ConfigReader.GetConfigValue("ODataTFS.WorkItemType");

            var proxy = new TFSData(new Uri(baseUrl));
            proxy.SendingRequest += (s, e) =>
            {
                var credentials = string.Format(
                    CultureInfo.InvariantCulture,
                    @"{0}\{1}:{2}",
                    ConfigReader.GetConfigValue("ODataTFS.TfsDomain"),
                    ConfigReader.GetConfigValue("ODataTFS.TfsUsername"),
                    ConfigReader.GetConfigValue("ODataTFS.TfsPassword"));
                e.RequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(credentials)));
            };

            return proxy;
        }
Example #4
0
        private static bool CreateNewAttachment(TFSData proxy, int workItemId, string comment, string path)
        {
            var success = true;
            var attachment = Attachment.CreateAttachment(string.Empty, workItemId, 0, DateTime.Now, DateTime.Now, DateTime.Now, 0);

            attachment.Comment = comment;
            attachment.Name = Path.GetFileNameWithoutExtension(path);
            attachment.Extension = Path.GetExtension(path);

            DataServiceResponse response;
            using (var fileStream = new FileStream(path, FileMode.Open))
            {
                proxy.AddToAttachments(attachment);
                proxy.SetSaveStream(attachment, fileStream, false, RegistryHelper.GetMimeType(Path.GetExtension(path)), string.Empty);
                response = proxy.SaveChanges();
            }

            Console.WriteLine("Batch status code: {0}", response.BatchStatusCode);
            foreach (var opeartionResponse in response)
            {
                Console.WriteLine("Operation status code: {0}", opeartionResponse.StatusCode);
                if (opeartionResponse.Error != null)
                {
                    Console.WriteLine("Operation error: {0}", opeartionResponse.Error.Message);
                    success = false;
                }
            }

            return success;
        }