|  | 
| 5 | 5 | using Rubberduck.VBEditor.Application; | 
| 6 | 6 | using Rubberduck.VBEditor.SafeComWrappers.Abstract; | 
| 7 | 7 | using Rubberduck.VBEditor.SafeComWrappers.MSForms; | 
| 8 |  | -using Exception = System.Exception; | 
| 9 | 8 | 
 | 
| 10 | 9 | namespace Rubberduck.VBEditor.Extensions | 
| 11 | 10 | { | 
| @@ -205,100 +204,4 @@ public static bool HostSupportsUnitTests(this IVBE vbe) | 
| 205 | 204 |             return false; | 
| 206 | 205 |         } | 
| 207 | 206 |     } | 
| 208 |  | - | 
| 209 |  | -    public static class VBProjectExtensions | 
| 210 |  | -    { | 
| 211 |  | -        /// <summary> | 
| 212 |  | -        /// Imports all source code files from target directory into project. | 
| 213 |  | -        /// </summary> | 
| 214 |  | -        /// <remarks> | 
| 215 |  | -        /// Only files with extensions "cls", "bas, "frm", and "doccls" are imported. | 
| 216 |  | -        /// It is the callers responsibility to remove any existing components prior to importing. | 
| 217 |  | -        /// </remarks> | 
| 218 |  | -        /// <param name="project"></param> | 
| 219 |  | -        /// <param name="filePath">Directory path containing the source files.</param> | 
| 220 |  | -        public static void ImportDocumentTypeSourceFiles(this IVBProject project, string filePath) | 
| 221 |  | -        { | 
| 222 |  | -            var dirInfo = new DirectoryInfo(filePath); | 
| 223 |  | - | 
| 224 |  | -            var files = dirInfo.EnumerateFiles() | 
| 225 |  | -                                .Where(f => f.Extension == ComponentTypeExtensions.DocClassExtension); | 
| 226 |  | -            foreach (var file in files) | 
| 227 |  | -            { | 
| 228 |  | -                try | 
| 229 |  | -                { | 
| 230 |  | -                    project.VBComponents.ImportSourceFile(file.FullName); | 
| 231 |  | -                } | 
| 232 |  | -                catch (IndexOutOfRangeException) { }    // component didn't exist | 
| 233 |  | -            } | 
| 234 |  | -        } | 
| 235 |  | - | 
| 236 |  | -        public static void LoadAllComponents(this IVBProject project, string filePath) | 
| 237 |  | -        { | 
| 238 |  | -            var dirInfo = new DirectoryInfo(filePath); | 
| 239 |  | - | 
| 240 |  | -            var files = dirInfo.EnumerateFiles() | 
| 241 |  | -                                .Where(f => f.Extension == ComponentTypeExtensions.StandardExtension || | 
| 242 |  | -                                            f.Extension == ComponentTypeExtensions.ClassExtension || | 
| 243 |  | -                                            f.Extension == ComponentTypeExtensions.DocClassExtension || | 
| 244 |  | -                                            f.Extension == ComponentTypeExtensions.FormExtension | 
| 245 |  | -                                            ) | 
| 246 |  | -                                .ToList(); | 
| 247 |  | - | 
| 248 |  | -            var exceptions = new List<Exception>(); | 
| 249 |  | - | 
| 250 |  | -            foreach (var component in project.VBComponents) | 
| 251 |  | -            { | 
| 252 |  | -                try | 
| 253 |  | -                { | 
| 254 |  | -                    var name = component.Name; | 
| 255 |  | -                    project.VBComponents.RemoveSafely(component); | 
| 256 |  | - | 
| 257 |  | -                    var file = files.SingleOrDefault(f => f.Name == name + f.Extension); | 
| 258 |  | -                    if (file != null) | 
| 259 |  | -                    { | 
| 260 |  | -                        try | 
| 261 |  | -                        { | 
| 262 |  | -                            project.VBComponents.ImportSourceFile(file.FullName); | 
| 263 |  | -                        } | 
| 264 |  | -                        catch (IndexOutOfRangeException) | 
| 265 |  | -                        { | 
| 266 |  | -                            exceptions.Add(new IndexOutOfRangeException(string.Format(VBEEditorText.NonexistentComponentErrorText, Path.GetFileNameWithoutExtension(file.FullName)))); | 
| 267 |  | -                        } | 
| 268 |  | -                    } | 
| 269 |  | -                } | 
| 270 |  | -                catch (Exception ex) | 
| 271 |  | -                { | 
| 272 |  | -                    exceptions.Add(ex); | 
| 273 |  | -                } | 
| 274 |  | -            } | 
| 275 |  | - | 
| 276 |  | -            foreach (var file in files) | 
| 277 |  | -            { | 
| 278 |  | -                try | 
| 279 |  | -                { | 
| 280 |  | -                    if (project.VBComponents.All(v => v.Name + file.Extension != file.Name)) | 
| 281 |  | -                    { | 
| 282 |  | -                        try | 
| 283 |  | -                        { | 
| 284 |  | -                            project.VBComponents.ImportSourceFile(file.FullName); | 
| 285 |  | -                        } | 
| 286 |  | -                        catch (IndexOutOfRangeException) | 
| 287 |  | -                        { | 
| 288 |  | -                            exceptions.Add(new IndexOutOfRangeException(string.Format(VBEEditorText.NonexistentComponentErrorText, Path.GetFileNameWithoutExtension(file.FullName)))); | 
| 289 |  | -                        } | 
| 290 |  | -                    } | 
| 291 |  | -                } | 
| 292 |  | -                catch (Exception ex) | 
| 293 |  | -                { | 
| 294 |  | -                    exceptions.Add(ex); | 
| 295 |  | -                } | 
| 296 |  | -            } | 
| 297 |  | - | 
| 298 |  | -            if (exceptions.Count != 0) | 
| 299 |  | -            { | 
| 300 |  | -                throw new AggregateException(string.Empty, exceptions); | 
| 301 |  | -            } | 
| 302 |  | -        } | 
| 303 |  | -    } | 
| 304 | 207 | } | 
0 commit comments