Skip to content

Commit

Permalink
0.9.0.6 -
Browse files Browse the repository at this point in the history
ready for use #2 -
background working is still remained -
destroy work item defenition is added
  • Loading branch information
mahdiehsanifar committed Oct 17, 2015
1 parent 5dc8359 commit 804215b
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 25 deletions.
1 change: 1 addition & 0 deletions TfsWitAdminTools/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private void Application_Startup(object sender, StartupEventArgs e)
DiManager.Current.Register<WIDExportVM, WIDExportVM>(lifeCycle: LifeCycle.Transient);
DiManager.Current.Register<WIDImportVM, WIDImportVM>(lifeCycle: LifeCycle.Transient);
DiManager.Current.Register<WIDRenameVM, WIDRenameVM>(lifeCycle: LifeCycle.Transient);
DiManager.Current.Register<WIDDestroyVM, WIDDestroyVM>(lifeCycle: LifeCycle.Transient);
DiManager.Current.Register<CategoryViewerVM, CategoryViewerVM>(lifeCycle: LifeCycle.Transient);
DiManager.Current.Register<CategoryExportVM, CategoryExportVM>(lifeCycle: LifeCycle.Transient);
DiManager.Current.Register<CategoryImportVM, CategoryImportVM>(lifeCycle: LifeCycle.Transient);
Expand Down
2 changes: 2 additions & 0 deletions TfsWitAdminTools/Core/IWitAdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void ExportWorkItemDefenition(ITFManager tfManager, string projectCollectionName

string RenameWorkItem(ITFManager tfManager, string projectCollectionName, string teamProjectName, string workItemTypeName, string newName);

string DestroyWorkItem(ITFManager tfManager, string projectCollectionName, string teamProjectName, string workItemTypeName);

string ExportCategories(ITFManager tfManager, string projectCollectionName, string teamProjectName);

void ExportCategories(ITFManager tfManager, string projectCollectionName, string teamProjectName, string fileName);
Expand Down
9 changes: 9 additions & 0 deletions TfsWitAdminTools/Service/WitAdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public string RenameWorkItem(ITFManager tfManager, string projectCollectionName,
return result;
}

public string DestroyWorkItem(ITFManager tfManager, string projectCollectionName, string teamProjectName, string workItemTypeName)
{
string argument = string.Format("destroywitd /collection:{0}/{1} /p:{2} /n:\"{3}\" /noprompt", tfManager.TfsAddress, projectCollectionName, teamProjectName, workItemTypeName);

string result = InvokeCommand(argument, true);

return result;
}

public string ExportCategories(ITFManager tfManager, string projectCollectionName, string teamProjectName)
{
string argument = string.Format("exportcategories /collection:{0}/{1} /p:{2}", tfManager.TfsAddress, projectCollectionName, teamProjectName);
Expand Down
1 change: 1 addition & 0 deletions TfsWitAdminTools/TfsWitAdminTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<Compile Include="ViewModel\ToolsVM.cs" />
<Compile Include="ViewModel\ViewModelBase.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="ViewModel\WIDDestroyVM.cs" />
<Compile Include="ViewModel\WIDExportVM.cs" />
<Compile Include="ViewModel\WIDImportVM.cs" />
<Compile Include="ViewModel\WIDRenameVM.cs" />
Expand Down
8 changes: 7 additions & 1 deletion TfsWitAdminTools/UserControls/ToolsForm.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@
<Button Command="{Binding ImportCommand}" Content="Import"/>
</StackPanel>
</TabItem>
<TabItem Header="Rename Work Item" DataContext="{Binding Path=WIDRename}">
<TabItem Header="Rename" DataContext="{Binding Path=WIDRename}">
<StackPanel>
<TextBox Text="{Binding NewName, UpdateSourceTrigger=PropertyChanged}"/>
<CheckBox IsChecked="{Binding IsAllTeamProjects}" Content="All Team Projects"/>
<Button Command="{Binding RenameCommand}" Content="Rename"/>
</StackPanel>
</TabItem>
<TabItem Header="Destroy" DataContext="{Binding Path=WIDDestroy}">
<StackPanel>
<CheckBox IsChecked="{Binding IsAllTeamProjects}" Content="All Team Projects"/>
<Button Command="{Binding DestroyCommand}" Content="Destroy"/>
</StackPanel>
</TabItem>
</TabControl>
</TabItem>
<TabItem Header="Categories">
Expand Down
17 changes: 17 additions & 0 deletions TfsWitAdminTools/ViewModel/ToolsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private void Init(IWitAdminService wiAdminService)
WIDExport = DiManager.Current.Resolve<WIDExportVM>(new { tools = this });
WIDImport = DiManager.Current.Resolve<WIDImportVM>(new { tools = this });
WIDRename = DiManager.Current.Resolve<WIDRenameVM>(new { tools = this });
WIDDestroy = DiManager.Current.Resolve<WIDDestroyVM>(new { tools = this });
CategoryViewer = DiManager.Current.Resolve<CategoryViewerVM>(new { tools = this });
CategoryExport = DiManager.Current.Resolve<CategoryExportVM>(new { tools = this });
CategoryImport = DiManager.Current.Resolve<CategoryImportVM>(new { tools = this });
Expand Down Expand Up @@ -274,6 +275,20 @@ public WIDRenameVM WIDRename
}
}

private WIDDestroyVM _wiDDestroy;

public WIDDestroyVM WIDDestroy
{
get { return _wiDDestroy; }
set
{
if (Set(ref _wiDDestroy, value))
{
RaiseCommandsCanExecute();
}
}
}

private CategoryViewerVM _categoryViewer;

public CategoryViewerVM CategoryViewer
Expand Down Expand Up @@ -399,6 +414,8 @@ private void RaiseCommandsCanExecute()
WIDImport.ImportCommand.RaiseCanExecuteChanged();
if (WIDRename != null)
WIDRename.RenameCommand.RaiseCanExecuteChanged();
if (WIDDestroy != null)
WIDDestroy.DestroyCommand.RaiseCanExecuteChanged();

if (CategoryViewer != null)
CategoryViewer.ShowCommand.RaiseCanExecuteChanged();
Expand Down
36 changes: 31 additions & 5 deletions TfsWitAdminTools/ViewModel/ViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Threading;

namespace TfsWitAdminTools.ViewModel
{
Expand All @@ -15,13 +17,37 @@ protected bool Set<T>(ref T prop, T value, [CallerMemberName]string propName = n
if (EqualityComparer<T>.Default.Equals(prop, value))
return false;

if (PropertyChanging != null)
PropertyChanging(this, new PropertyChangingEventArgs(propName));
PropertyChangingEventHandler tempPropertyChanging = PropertyChanging;

if (tempPropertyChanging != null)
{
if (Dispatcher.CurrentDispatcher != null)
{
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
tempPropertyChanging(this, new PropertyChangingEventArgs(propName));
}));
}
}
//if (PropertyChanging != null)
// PropertyChanging(this, new PropertyChangingEventArgs(propName));

prop = value;

if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propName));
PropertyChangedEventHandler tempPropertyChanged = PropertyChanged;

if (tempPropertyChanged != null)
{
if (Dispatcher.CurrentDispatcher != null)
{
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
tempPropertyChanged(this, new PropertyChangedEventArgs(propName));
}));
}
}
//if (PropertyChanged != null)
// PropertyChanged(this, new PropertyChangedEventArgs(propName));

return true;
}
Expand Down
81 changes: 81 additions & 0 deletions TfsWitAdminTools/ViewModel/WIDDestroyVM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TfsWitAdminTools.Model;

namespace TfsWitAdminTools.ViewModel
{
public class WIDDestroyVM : ToolsChildVM
{
#region Ctor

public WIDDestroyVM(ToolsVM tools)
: base(tools)
{
DestroyCommand = new DelegateCommand(() =>
{
//ToDo
try
{
Tools.IsWorrking = true;
Destroy();
}
finally
{
if (Tools.IsWorrking)
Tools.IsWorrking = false;
}
},
() => (
Tools.CurrentProjectCollection != null &&
(IsAllTeamProjects == true || Tools.CurrentTeamProject != null) &&
Tools.CurrentWorkItemType != null
)
);
}

private void Destroy()
{
TeamProjectInfo[] teamProjects = null;
if (IsAllTeamProjects)
teamProjects = Tools.CurrentProjectCollection.TeamProjectInfos;
else
teamProjects = new TeamProjectInfo[] { Tools.CurrentTeamProject };

foreach (TeamProjectInfo teamProject in teamProjects)
{
string projectCollectionName = Tools.CurrentProjectCollection.Name;
string teamProjectName = teamProject.Name;
string workItemTypeName = Tools.CurrentWorkItemType.Name;

Tools.WIAdminService.DestroyWorkItem(TFManager, projectCollectionName, teamProjectName, workItemTypeName);
}
}

#endregion

#region Props

private bool _isAllTeamProjects;
public bool IsAllTeamProjects
{
get { return _isAllTeamProjects; }
set
{
if (Set(ref _isAllTeamProjects, value))
DestroyCommand.RaiseCanExecuteChanged();
}
}

#endregion

#region Commands

public DelegateCommand DestroyCommand { get; set; }


#endregion
}
}
41 changes: 27 additions & 14 deletions TfsWitAdminTools/ViewModel/WIDExportVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,44 @@ public WIDExportVM(ToolsVM tools, IDialogProvider dialogProvider)
Path = path;
});

//ExportCommand = new DelegateCommand(async () =>
ExportCommand = new DelegateCommand(() =>
ExportCommand = new DelegateCommand(async () =>
//ExportCommand = new DelegateCommand(() =>
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (sender, e) =>
Export();
//BackgroundWorker bw = new BackgroundWorker();
//bw.DoWork += (sender, e) =>
// Export();

bw.RunWorkerCompleted += (sender, e) =>
Tools.IsWorrking = false;
//bw.RunWorkerCompleted += (sender, e) =>
// Tools.IsWorrking = false;

//Tools.IsWorrking = true;
//bw.RunWorkerAsync();

//ToDo
try
{
Tools.IsWorrking = true;
await Export();
}
finally
{
if (Tools.IsWorrking)
Tools.IsWorrking = false;
}

Tools.IsWorrking = true;
bw.RunWorkerAsync();

//try
//{
// Tools.IsWorrking = true;


// //ToDo: using wait
// //await Task.Factory.StartNew(() =>
// //{
// // Export();
// //});
// Task.Factory.StartNew(() =>
// {
// Export();
// }).Wait();

// await Export();
// //await Export();

//}
//finally
Expand Down
30 changes: 26 additions & 4 deletions TfsWitAdminTools/ViewModel/WIDImportVM.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using TfsWitAdminTools.Cmn;
using System.ComponentModel;
using System.Threading.Tasks;
using TfsWitAdminTools.Cmn;
using TfsWitAdminTools.Core;
using TfsWitAdminTools.Model;

Expand All @@ -23,7 +25,27 @@ public WIDImportVM(ToolsVM tools, IDialogProvider dialogProvider)

ImportCommand = new DelegateCommand(() =>
{
Import();
//ToDo
try
{
Tools.IsWorrking = true;
Import();
}
finally
{
if (Tools.IsWorrking)
Tools.IsWorrking = false;
}

//BackgroundWorker bw = new BackgroundWorker();
//bw.DoWork += (sender, e) =>
// Import();

//bw.RunWorkerCompleted += (sender, e) =>
// Tools.IsWorrking = false;

//Tools.IsWorrking = true;
//bw.RunWorkerAsync();
},
() => (
Tools.CurrentProjectCollection != null &&
Expand Down Expand Up @@ -84,8 +106,8 @@ private void Import()
string projectCollectionName = Tools.CurrentProjectCollection.Name;
string teamProjectName = teamProject.Name;

Tools.WIAdminService.ImportWorkItemDefenition(TFManager, projectCollectionName,
teamProjectName, FileName);
Tools.WIAdminService.ImportWorkItemDefenition(TFManager, projectCollectionName,teamProjectName,
FileName);
}
}

Expand Down
12 changes: 11 additions & 1 deletion TfsWitAdminTools/ViewModel/WIDRenameVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ public WIDRenameVM(ToolsVM tools)
{
RenameCommand = new DelegateCommand(() =>
{
Rename();
//ToDo
try
{
Tools.IsWorrking = true;
Rename();
}
finally
{
if (Tools.IsWorrking)
Tools.IsWorrking = false;
}
},
() => (
Tools.CurrentProjectCollection != null &&
Expand Down

0 comments on commit 804215b

Please sign in to comment.