Changeset 7623 for lang/powershell
- Timestamp:
- 03/07/08 19:15:22 (9 months ago)
- Location:
- lang/powershell/PSCustomProviders/trunk
- Files:
-
- 8 added
- 11 modified
-
format/pstodo.format.ps1xml (modified) (2 diffs)
-
src/Dotnet.PowerShell.PSTodo.Test/Dotnet.PowerShell.PSTodo.Test.2005.csproj (modified) (1 diff)
-
src/Dotnet.PowerShell.PSTodo.Test/PSTodo/PSTodoProvider_Test.cs (modified) (5 diffs)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-2/100 (modified) (previous)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-2/200 (modified) (previous)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-2/300 (modified) (previous)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-2/400 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-4/100 (modified) (previous)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-4/200 (modified) (previous)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-4/300 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-4/400 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-4/500 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-5 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-5/100 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-5/200 (added)
-
src/Dotnet.PowerShell.PSTodo.Test/TestData/case-5/300 (added)
-
src/Dotnet.PowerShell.PSTodo/Dotnet.PowerShell.PSTodo.2005.csproj.user (modified) (1 diff)
-
src/Dotnet.PowerShell.PSTodo/PSTodo/PSTodoItem.cs (modified) (3 diffs)
-
src/Dotnet.PowerShell.PSTodo/PSTodo/PSTodoProvider.cs (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/powershell/PSCustomProviders/trunk/format/pstodo.format.ps1xml
r7503 r7623 31 31 <TableColumnHeader> 32 32 <Label>完了</Label> 33 <Width>8</Width> 33 <Width>4</Width> 34 <Alignment>Center</Alignment> 35 </TableColumnHeader> 36 <TableColumnHeader> 37 <Label>優先度</Label> 38 <Width>6</Width> 39 <Alignment>Center</Alignment> 34 40 </TableColumnHeader> 35 41 <TableColumnHeader> … … 46 52 <TableColumnItems> 47 53 <TableColumnItem> 48 <PropertyName>IsComplete</PropertyName> 54 <ScriptBlock> 55 if($_.IsComplete) { "○" } else { "×" } 56 </ScriptBlock> 57 </TableColumnItem> 58 <TableColumnItem> 59 <ScriptBlock> 60 switch($_.Priority) { 61 "Higher" { "最高" } 62 "High" { "高い" } 63 "Middle" { "普通" } 64 "Low" { "低い" } 65 "Lower" { "最低" } 66 } 67 </ScriptBlock> 49 68 </TableColumnItem> 50 69 <TableColumnItem> -
lang/powershell/PSCustomProviders/trunk/src/Dotnet.PowerShell.PSTodo.Test/Dotnet.PowerShell.PSTodo.Test.2005.csproj
r7590 r7623 40 40 <None Include="TestData\case-2\200" /> 41 41 <None Include="TestData\case-2\300" /> 42 <None Include="TestData\case-2\400" /> 42 43 <None Include="TestData\case-3\100" /> 43 44 <None Include="TestData\case-4\100" /> 44 45 <None Include="TestData\case-4\200" /> 46 <None Include="TestData\case-4\300" /> 47 <None Include="TestData\case-4\400" /> 48 <None Include="TestData\case-4\500" /> 49 <None Include="TestData\case-5\100" /> 50 <None Include="TestData\case-5\200" /> 51 <None Include="TestData\case-5\300" /> 45 52 <None Include="UnitTest.2005.nunit" /> 46 53 </ItemGroup> -
lang/powershell/PSCustomProviders/trunk/src/Dotnet.PowerShell.PSTodo.Test/PSTodo/PSTodoProvider_Test.cs
r7590 r7623 133 133 CreateTodoDrive("case-1"); 134 134 135 Collection<PSObject> result = rsEngine.Invoke("New-Item Hoge -Description HogeHoge ");135 Collection<PSObject> result = rsEngine.Invoke("New-Item Hoge -Description HogeHoge -Priority High"); 136 136 137 137 Assert.That(result, Has.Property("Count", 1)); … … 141 141 Assert.That(item.Title, Is.EqualTo("Hoge")); 142 142 Assert.That(item.Description, Is.EqualTo("HogeHoge")); 143 Assert.That(item.Priority, Is.EqualTo(ItemPriority.High)); 143 144 Assert.That(item.IsComplete, Is.False); 144 145 } … … 148 149 /// </summary> 149 150 [Test, Category("Success")] 150 public void アイテム一覧を列挙できる () {151 public void アイテム一覧を列挙できる_ケース1() { 151 152 CreateTodoDrive("case-2"); 152 153 153 154 Collection<PSObject> result = rsEngine.Invoke("Get-ChildItem"); 154 155 Assert.That(result, Has.Property("Count", 3)); 155 // 未完了のものしか引っ掛からない 156 Assert.That(result, Has.Property("Count", 2)); 157 158 result = rsEngine.Invoke("Get-ChildItem -Force"); 159 // 全て引っ掛かる 160 Assert.That(result, Has.Property("Count", 4)); 161 } 162 163 /// <summary> 164 /// アイテム一覧を列挙する(ワイルドカード)。 165 /// </summary> 166 [Test, Category("Success")] 167 public void アイテム一覧を列挙できる_ケース2() { 168 CreateTodoDrive("case-2"); 169 170 Collection<PSObject> result = rsEngine.Invoke("Get-ChildItem 1*"); 171 172 Assert.That(result, Has.Property("Count", 1)); 156 173 } 157 174 … … 179 196 rsEngine.Invoke("Rename-Item 100 101"); 180 197 181 Collection<PSObject> result = rsEngine.Invoke("Get- ChildItem");198 Collection<PSObject> result = rsEngine.Invoke("Get-Item 101"); 182 199 183 200 PSTodoItem item = (PSTodoItem)result[0].BaseObject; 184 201 185 202 Assert.That(item.Title, Is.EqualTo("101")); 186 } 187 188 /// <summary> 189 /// アイテムの情報を編集する。(詳細、完了フラグ) 203 // 変わってないよな? 204 Assert.That(item.Priority, Is.EqualTo(ItemPriority.High)); 205 } 206 207 /// <summary> 208 /// アイテムの情報を編集する。(詳細、完了フラグ、優先度) 190 209 /// </summary> 191 210 [Test, Category("Success")] … … 193 212 CreateTodoDrive("case-4"); 194 213 195 rsEngine.Invoke("Set-Item 200 -Description Hello - Complete");196 197 Collection<PSObject> result = rsEngine.Invoke("Get- ChildItem");198 199 PSTodoItem item = (PSTodoItem)result[ 1].BaseObject;214 rsEngine.Invoke("Set-Item 200 -Description Hello -Priority Lower -Complete"); 215 216 Collection<PSObject> result = rsEngine.Invoke("Get-Item 200"); 217 218 PSTodoItem item = (PSTodoItem)result[0].BaseObject; 200 219 201 220 Assert.That(item.Description, Is.EqualTo("Hello")); 221 Assert.That(item.Priority, Is.EqualTo(ItemPriority.Lower)); 202 222 Assert.That(item.IsComplete, Is.True); 223 } 224 225 /// <summary> 226 /// アイテムの情報を編集する。(Move-Item) 227 /// </summary> 228 [Test, Category("Success")] 229 public void アイテムの情報を編集できる_ケース3() { 230 CreateTodoDrive("case-4"); 231 232 rsEngine.Invoke("Move-Item 500 501"); 233 234 Collection<PSObject> result = rsEngine.Invoke("Get-Item 501"); 235 236 PSTodoItem item = (PSTodoItem)result[0].BaseObject; 237 238 Assert.That(item.Title, Is.EqualTo("501")); 239 } 240 241 /// <summary> 242 /// アイテムをコピーする。 243 /// </summary> 244 [Test, Category("Success")] 245 public void アイテムをコピーできる() { 246 CreateTodoDrive("case-4"); 247 248 rsEngine.Invoke("Copy-Item 300 301 -Description 'Hello, World'"); 249 250 Collection<PSObject> result = rsEngine.Invoke("Get-Item 301"); 251 252 PSTodoItem item = (PSTodoItem)result[0].BaseObject; 253 254 Assert.That(item.Title, Is.EqualTo("301")); 255 Assert.That(item.Description, Is.EqualTo("Hello, World")); 203 256 } 204 257 -
lang/powershell/PSCustomProviders/trunk/src/Dotnet.PowerShell.PSTodo/Dotnet.PowerShell.PSTodo.2005.csproj.user
r7503 r7623 7 7 <StartAction>Project</StartAction> 8 8 </PropertyGroup> 9 <PropertyGroup> 10 <ProjectView>ProjectFiles</ProjectView> 11 </PropertyGroup> 9 12 </Project> -
lang/powershell/PSCustomProviders/trunk/src/Dotnet.PowerShell.PSTodo/PSTodo/PSTodoItem.cs
r7590 r7623 45 45 private string title; 46 46 private string description; 47 private ItemPriority priority = ItemPriority.Middle; 47 48 48 49 private bool isComplete; … … 66 67 get { return description; } 67 68 set { description = value; } 69 } 70 71 /// <summary> 72 /// 優先度を取得、設定します。 73 /// </summary> 74 public ItemPriority Priority { 75 get { return priority; } 76 set { priority = value; } 68 77 } 69 78 … … 132 141 #endregion 133 142 143 #region ItemPriority enum 144 145 /// <summary> 146 /// アイテムの優先度を定義する列挙型 147 /// </summary> 148 public enum ItemPriority { 149 /// <summary> 150 /// 最低 151 /// </summary> 152 Lower = 1, 153 /// <summary> 154 /// 低い 155 /// </summary> 156 Low, 157 /// <summary> 158 /// 普通 159 /// </summary> 160 Middle, 161 /// <summary> 162 /// 高い 163 /// </summary> 164 High, 165 /// <summary> 166 /// 最高 167 /// </summary> 168 Higher 169 } 170 171 #endregion 172 134 173 } -
lang/powershell/PSCustomProviders/trunk/src/Dotnet.PowerShell.PSTodo/PSTodo/PSTodoProvider.cs
r7590 r7623 31 31 using System.Diagnostics; 32 32 33 using Dotnet.Commons; 34 using System.Collections.Generic; 35 33 36 #endregion 34 37 … … 41 44 /// </summary> 42 45 [CmdletProvider("Todo", ProviderCapabilities.ShouldProcess)] 43 public class PSTodoProvider : NavigationCmdletProvider {46 public sealed class PSTodoProvider : NavigationCmdletProvider { 44 47 45 48 #region innerClass 46 49 47 #region PSTodoItemParameters class48 49 /// <summary> 50 /// アイテムのパラメータ情報を格納するクラス50 #region NewTodoItemParameters class 51 52 /// <summary> 53 /// 作成するアイテムのパラメータ情報を格納するクラス 51 54 /// </summary> 52 55 [Serializable] 53 56 [DebuggerStepThrough] 54 public sealed class PSTodoItemParameters {57 internal sealed class NewTodoItemParameters { 55 58 56 59 #region fields 57 60 58 61 private string description; 62 private ItemPriority? priority; 59 63 private SwitchParameter complete; 60 64 … … 73 77 74 78 /// <summary> 79 /// 優先度を取得、設定します。 80 /// </summary> 81 [Parameter(Position = 1)] 82 public ItemPriority? Priority { 83 get { return priority; } 84 set { priority = value; } 85 } 86 87 /// <summary> 75 88 /// 完了したかどうかを取得、設定します。 76 89 /// </summary> 77 [Parameter(Position = 1)]90 [Parameter(Position = 2)] 78 91 public SwitchParameter Complete { 79 92 get { return complete; } … … 88 101 /// 標準的なコンストラクタ 89 102 /// </summary> 90 public PSTodoItemParameters() {103 public NewTodoItemParameters() { 91 104 } 92 105 … … 135 148 return (PSTodoItem)formatter.Deserialize(fs); 136 149 } 150 } 151 152 /// <summary> 153 /// 指定したパスにあるTodoアイテムの一覧を取得します。 154 /// </summary> 155 /// <param name="path">パス</param> 156 /// <param name="recurse">子ディレクトリも探すかどうか</param> 157 /// <param name="nameOnly">名前だけ出力するかどうか</param> 158 private void GetTodoItems(string path, bool recurse, bool nameOnly) { 159 List<string> fileNames = new List<string>(Directory.GetFiles(path)); 160 // 作成日順でソート 161 fileNames.Sort(delegate(string file1, string file2) { 162 return File.GetCreationTime(file1).CompareTo(File.GetCreationTime(file2)); 163 }); 164 foreach(string fileName in fileNames) { 165 if(base.Stopping) return; 166 167 PSTodoItem item = Deserialize(fileName); 168 // 完了したアイテムは、Forceフラグが指定された場合のみ表示する。 169 if(item.IsComplete && !base.Force) continue; 170 171 WriteItemObject( 172 (nameOnly ? (object)item.Title : item), fileName, false 173 ); 174 } 175 } 176 177 /// <summary> 178 /// 指定したパスのアイテムをコピーします。 179 /// </summary> 180 /// <param name="path">パス</param> 181 /// <param name="destPath">コピー先のパス</param> 182 /// <param name="itemParams">パラメータ</param> 183 /// <returns>更新したアイテム</returns> 184 private PSTodoItem CopyTodoItem(string path, string destPath, NewTodoItemParameters itemParams) { 185 PSTodoItem item = Deserialize(path); 186 item.Title = Path.GetFileName(destPath); 187 // Move-Itemの時はnullなのよね 188 if(itemParams != null) { 189 if(!string.IsNullOrEmpty(itemParams.Description)) { 190 item.Description = itemParams.Description; 191 } 192 if(itemParams.Priority.HasValue) { 193 item.Priority = itemParams.Priority.Value; 194 } 195 item.IsComplete = itemParams.Complete; 196 } 197 Serialize(item, destPath); 198 199 return item; 200 } 201 202 /// <summary> 203 /// 指定したパスのアイテムの情報を更新します。 204 /// </summary> 205 /// <param name="path">パス</param> 206 /// <param name="itemParams">パラメータ</param> 207 /// <returns>更新したアイテム</returns> 208 private PSTodoItem UpdateTodoItem(string path, NewTodoItemParameters itemParams) { 209 return CopyTodoItem(path, path, itemParams); 137 210 } 138 211 … … 174 247 /// <param name="newItemValue"></param> 175 248 protected override void NewItem(string path, string itemTypeName, object newItemValue) { 176 PSTodoItemParameters itemParams = (PSTodoItemParameters)base.DynamicParameters;249 NewTodoItemParameters itemParams = (NewTodoItemParameters)base.DynamicParameters; 177 250 178 251 PSTodoItem item = new PSTodoItem( 179 Path.GetFileName(path), 180 itemParams.Description, itemParams.Complete 252 Path.GetFileName(path), itemParams.Description, itemParams.Complete 181 253 ); 254 if(itemParams.Priority.HasValue) { 255 item.Priority = itemParams.Priority.Value; 256 } 182 257 Serialize(item, path); 183 258 … … 186 261 } 187 262 } 188 189 263 /// <summary> 190 264 /// <see cref="ContainerCmdletProvider.NewItemDynamicParameters(string, string, object)"/> … … 194 268 /// <param name="newItemValue"></param> 195 269 /// <returns></returns> 196 protected override object NewItemDynamicParameters(string path, string itemTypeName, object newItemValue) { 197 return new PSTodoItemParameters(); 198 } 270 protected override object NewItemDynamicParameters(string path, string itemTypeName, object newItemValue) { return new NewTodoItemParameters(); } 199 271 200 272 /// <summary> … … 204 276 /// <param name="recurse"></param> 205 277 protected override void GetChildItems(string path, bool recurse) { 206 foreach(string fileName in Directory.GetFiles(path)) { 207 if(base.Stopping) return; 208 209 WriteItemObject( 210 Deserialize(fileName), fileName, false 211 ); 212 } 278 GetTodoItems(path, recurse, false); 279 } 280 281 /// <summary> 282 /// <see cref="ContainerCmdletProvider.GetChildNames(string, ReturnContainers)"/> 283 /// </summary> 284 /// <param name="path"></param> 285 /// <param name="returnContainers"></param> 286 protected override void GetChildNames(string path, ReturnContainers returnContainers) { 287 GetTodoItems(path, false, true); 213 288 } 214 289 … … 219 294 /// <param name="newName"></param> 220 295 protected override void RenameItem(string path, string newName) { 221 string destPath = Path.Combine( 222 Path.GetDirectoryName(path), newName 296 MoveItem(path, 297 Path.Combine( 298 Path.GetDirectoryName(path), newName 299 ) 223 300 ); 224 File.Move(path, destPath); 301 } 302 303 /// <summary> 304 /// <see cref="ItemCmdletProvider.SetItem(string, object)"/> 305 /// </summary> 306 /// <param name="path"></param> 307 /// <param name="value"></param> 308 protected override void SetItem(string path, object value) { 309 NewTodoItemParameters itemParams = (NewTodoItemParameters)base.DynamicParameters; 310 311 UpdateTodoItem(path, itemParams); 312 } 313 /// <summary> 314 /// <see cref="ItemCmdletProvider.SetItemDynamicParameters(string, object)"/> 315 /// </summary> 316 /// <param name="path"></param> 317 /// <param name="value"></param> 318 /// <returns></returns> 319 protected override object SetItemDynamicParameters(string path, object value) { return new NewTodoItemParameters(); } 320 321 /// <summary> 322 /// <see cref="ItemCmdletProvider.GetItem(string)"/> 323 /// </summary> 324 /// <param name="path"></param> 325 protected override void GetItem(string path) { 326 WriteItemObject( 327 Deserialize(path), path, false 328 ); 329 } 330 331 /// <summary> 332 /// <see cref="ContainerCmdletProvider.CopyItem(string, string, bool)"/> 333 /// </summary> 334 /// <param name="path"></param> 335 /// <param name="copyPath"></param> 336 /// <param name="recurse"></param> 337 protected override void CopyItem(string path, string copyPath, bool recurse) { 338 File.Copy(path, copyPath, base.Force); 225 339 try { 226 PSTodoItem item = Deserialize(destPath); 227 item.Title = newName; 228 229 Serialize(item, destPath); 340 UpdateTodoItem( 341 copyPath, (NewTodoItemParameters)base.DynamicParameters 342 ); 230 343 231 344 } catch(Exception exp) { 232 File.Move(destPath, path); 345 // 問答無用で上書きされた場合のみ、コピー先のファイルを削除する。 346 if(!base.Force) File.Delete(copyPath); 347 348 base.ThrowTerminatingError( 349 new ErrorRecord(exp, "002", ErrorCategory.WriteError, path) 350 ); 351 } 352 } 353
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)