@@ -24,77 +24,28 @@ namespace Microsoft.CLU
24
24
///
25
25
/// [_indexes]
26
26
/// |
27
- /// ===========================================
28
- /// | | |
29
- /// | | |
30
- /// [vm] [network] _cmdlet.idx
31
- /// | |
32
- /// ================== [virtual]
33
- /// | | | |
34
- /// [create] [delete] _cmdlet.idx ==================
35
- /// | | | | |
36
- /// _cmdlet.idx _cmdlet.idx [create] [delete] _cmdlet.idx
37
- /// | |
38
- /// _cmdlet.idx _cmdlet.idx
39
- ///
27
+ /// _cmdlet.idx
28
+ ///
40
29
/// The notation [abc] represents a directory, where 'abc' is the directory name.
41
30
///
42
31
/// [_indexes] represents the root directory "_indexes".
43
- /// There is a directory corrosponding to each discriminator of commands, each such directory contains a
44
- /// file named _cmdlet.idx which is the index for commands this discriminator participate.
45
- /// For example _cmdlet.idx under [virtual] diretory will contains index for following commands
46
- /// vm network create
47
- /// vm network delete
48
- /// _cmdlet.idx under [virtual]/[create] index
49
- /// vm network create
50
32
/// </summary>
51
33
internal class CmdletIndex
52
34
{
53
- /// <summary>
54
- /// Name of the index.
55
- /// </summary>
56
- public string Name { get ; set ; }
57
-
58
35
/// <summary>
59
36
/// The index-entries. These entries will be serialized to/from the file _cmdlet.idx.
60
37
/// </summary>
61
38
public ConfigurationDictionary Entries { get ; set ; } = new ConfigurationDictionary ( ) ;
62
39
63
- /// <summary>
64
- /// Child indicies.
65
- /// </summary>
66
- public Dictionary < string , CmdletIndex > Children { get ; set ; } = new Dictionary < string , CmdletIndex > ( ) ;
67
-
68
- /// <summary>
69
- /// Index a command identified by the given command discriminators.
70
- /// </summary>
71
- /// <param name="keys">The command discriminator list from which key needs to be derived</param>
72
- /// <param name="value">The value</param>
73
- public void Add ( List < string > keys , string value )
74
- {
75
- Add ( keys , 0 , value ) ;
76
- }
77
40
78
41
/// <summary>
79
42
/// Recursively index each discriminator in the given command keys.
80
43
/// </summary>
81
44
/// <param name="keys">The command discriminator list from which key needs to be derived</param>
82
- /// <param name="level">The discriminator level</param>
83
45
/// <param name="value">The value</param>
84
- private void Add ( List < string > keys , int level , string value )
46
+ private void Add ( List < string > keys , string value )
85
47
{
86
48
Entries . Add ( string . Join ( Constants . CmdletIndexWordSeparator , keys ) , value ) ;
87
- if ( level < keys . Count )
88
- {
89
- CmdletIndex childIndex ;
90
- if ( ! Children . TryGetValue ( keys [ level ] , out childIndex ) )
91
- {
92
- childIndex = new CmdletIndex { Name = keys [ level ] } ;
93
- Children . Add ( keys [ level ] , childIndex ) ;
94
- }
95
-
96
- childIndex . Add ( keys , level + 1 , value ) ;
97
- }
98
49
}
99
50
100
51
/// <summary>
@@ -105,51 +56,31 @@ public void Save(string path)
105
56
{
106
57
Debug . Assert ( ! string . IsNullOrEmpty ( path ) ) ;
107
58
108
- var fullPath = string . IsNullOrEmpty ( Name ) ? path : Path . Combine ( path , Name ) ;
109
- if ( ! Directory . Exists ( fullPath ) )
110
- Directory . CreateDirectory ( fullPath ) ;
59
+ if ( ! Directory . Exists ( path ) )
60
+ Directory . CreateDirectory ( path ) ;
111
61
112
- var indexFilePath = Path . Combine ( fullPath , Constants . CmdletsIndexFileName ) ;
62
+ var indexFilePath = Path . Combine ( path , Constants . CmdletsIndexFileName ) ;
113
63
if ( Entries . Count > 0 )
114
64
Entries . Store ( indexFilePath ) ;
115
-
116
- foreach ( var idx in Children . Values )
117
- {
118
- idx . Save ( fullPath ) ;
119
- }
120
65
}
121
66
122
67
/// <summary>
123
68
/// Load the index.
124
69
/// </summary>
125
- /// <param name="keys">The command discriminator list identifying the index to be loaded</param>
126
70
/// <param name="path">The index file path</param>
127
- /// <param name="recursive">
128
- /// True - If the index for all command discriminator in the discriminator list needs to be loaded
129
- /// False - Only the index of the root discriminator needs to be loaded</param>
130
71
/// <returns></returns>
131
- public static CmdletIndex Load ( IEnumerable < string > keys , string path , bool recursive )
72
+ public static CmdletIndex Load ( string path )
132
73
{
133
- Debug . Assert ( keys != null ) ;
134
74
Debug . Assert ( ! string . IsNullOrEmpty ( path ) ) ;
135
75
136
- var indexName = keys . FirstOrDefault ( ) ;
137
76
var indexFullPath = Path . Combine ( path , Constants . CmdletsIndexFileName ) ;
138
77
139
- var cmdletIndex = new CmdletIndex { Name = indexName } ;
78
+ var cmdletIndex = new CmdletIndex ( ) ;
140
79
if ( File . Exists ( indexFullPath ) )
141
80
{
142
81
cmdletIndex . Entries = ConfigurationDictionary . Load ( indexFullPath ) ;
143
82
}
144
83
145
- if ( recursive )
146
- {
147
- foreach ( var dir in Directory . EnumerateDirectories ( path ) )
148
- {
149
- cmdletIndex . Children . Add ( indexName , Load ( keys . Skip ( 1 ) , Path . Combine ( path , indexName ) , true ) ) ;
150
- }
151
- }
152
-
153
84
return cmdletIndex ;
154
85
}
155
86
@@ -158,9 +89,7 @@ public static CmdletIndex Load(IEnumerable<string> keys, string path, bool recur
158
89
/// </summary>
159
90
public void Clear ( )
160
91
{
161
- Name = null ;
162
92
Entries . Clear ( ) ;
163
- Children . Clear ( ) ;
164
93
}
165
94
}
166
95
}
0 commit comments