Пример #1
0
        /// <summary>
        /// Open a dialog form to create new work item.
        /// </summary>
        /// <param name="workItemTypeName">work item type name</param>
        /// <param name="title">work item title</param>
        /// <param name="fields">A dictionary represents the workitem fields. The key should be the ReferenceName of a field.</param>
        public static void OpenWorkItemForm(string workItemTypeName, string title = null, Dictionary <string, object> fields = null)
        {
            var settings     = MySettingsManager.GetSettings <TfsSettings>();
            var uri          = new Uri(settings.ProjectCollectionUri);
            var project      = TfsHelper.GetProject(settings.ProjectCollectionUri, settings.ProjectName);
            var workItemType = project.WorkItemTypes[workItemTypeName];

            var workItem = new WorkItem(workItemType);

            workItem.IterationPath = settings.Iteration;
            workItem.AreaPath      = settings.Area;
            workItem.Title         = title;
            if (fields != null)
            {
                foreach (var field in fields)
                {
                    foreach (Field wField in workItem.Fields)
                    {
                        if (wField.ReferenceName == field.Key)
                        {
                            wField.Value = field.Value;
                            break;
                        }
                    }
                }
            }

            var form = new WorkItemWindow(workItem);

            form.ShowDialog();
        }
Пример #2
0
        public static bool CheckSettings()
        {
            var settings = MySettingsManager.GetSettings <TfsSettings>();

            if (string.IsNullOrEmpty(settings.ProjectName) || string.IsNullOrEmpty(settings.WorkItemType))
            {
                return(false);
            }

            var uri = new Uri(settings.ProjectCollectionUri);

            try
            {
                var project      = TfsHelper.GetProject(settings.ProjectCollectionUri, settings.ProjectName);
                var workItemType = project.WorkItemTypes[settings.WorkItemType];
                if (workItemType == null)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to connect to TFS", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            var registered = RegisteredTfsConnections.GetProjectCollection(uri);

            if (registered == null)
            {
                RegisteredTfsConnections.RegisterProjectCollection(new TfsTeamProjectCollection(uri));
            }
            return(true);
        }
Пример #3
0
        internal static bool SaveWorkItem(WorkItem workItem)
        {
            ArrayList fields = workItem.Validate();

            if (fields.Count > 0)
            {
                StringBuilder error = new StringBuilder();
                error.Append(string.Format("The following {0} fields is in invalid status:", fields.Count)).Append(Environment.NewLine);
                foreach (Field field in fields)
                {
                    error.Append(Environment.NewLine);
                    error.Append(string.Format("{0} - {1}", field.Name, field.Status));
                }
                MessageBox.Show(error.ToString(), "Validation Failded", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            workItem.Save();

            var settings = MySettingsManager.GetSettings <TfsSettings>();

            if (settings.RememberPaths)
            {
                settings.Area      = workItem.AreaPath;
                settings.Iteration = workItem.IterationPath;
                MySettingsManager.SaveSingle(settings);
            }
            return(true);
        }
Пример #4
0
        public static void OpenWorkItemForm(int id)
        {
            var settings = MySettingsManager.GetSettings <TfsSettings>();
            var workItem = TfsHelper.GetWorkItem(settings.ProjectCollectionUri, id);
            var form     = new WorkItemWindow(workItem);

            form.ShowDialog();
        }
Пример #5
0
        public SettingsViewModel()
        {
            this.CancelCommand        = new DelegateCommand(ExecuteCancelCommand);
            this.SaveAndCloseCommand  = new DelegateCommand(ExecuteSaveAndCloseCommand);
            this.ChooseProjectCommand = new DelegateCommand(ExecuteChooseProjectCommand);

            this._settings               = MySettingsManager.GetSettings <TfsSettings>();
            this.ProjectCollectionUri    = this._settings.ProjectCollectionUri;
            this.ProjectName             = this._settings.ProjectName;
            this.WorkItemType            = this._settings.WorkItemType;
            this.FieldRefNameForMailBody = this._settings.FieldRefNameForMailBody;
            this.Area          = this._settings.Area;
            this.Iteration     = this._settings.Iteration;
            this.RememberPaths = this._settings.RememberPaths;
        }
Пример #6
0
        public void ExecuteSaveAndCloseCommand(object parameter)
        {
            _settings.ProjectCollectionUri    = this.ProjectCollectionUri;
            _settings.ProjectName             = this.ProjectName;
            _settings.WorkItemType            = this.WorkItemType;
            _settings.FieldRefNameForMailBody = this.FieldRefNameForMailBody;
            _settings.Area          = this.Area;
            _settings.Iteration     = this.Iteration;
            _settings.RememberPaths = this.RememberPaths;
            MySettingsManager.SaveSingle(_settings);

            var window = parameter as Window;

            window.DialogResult = true;
            window.Close();
        }
Пример #7
0
        public static void OpenWorkItemForm()
        {
            var settings = MySettingsManager.GetSettings <TfsSettings>();

            OpenWorkItemForm(settings.WorkItemType);
        }