Пример #1
0
 /// <summary>
 /// Exports components to specified path and updates configuration file
 /// </summary>
 /// <param name="args">info about specified path, selected components etc. </param>
 /// <param name="config">a reference to a configuration file</param>
 /// <returns></returns>
 public virtual bool ExportComponents(Events.ExportEventArgs args, Configurations.ConfigurationBase config)
 {
     try
     {
         List <_VBComponent> comps = args.SelectedComponents.Select(x => x.VbComponent).ToList();
         foreach (var component in comps)
         {
             string fullPath = Path.Combine(args.Path, component.Name + VbeExtensions.GetExtension(component.Type));
             if (component.Type == vbext_ComponentType.vbext_ct_Document)
             {
                 string text = "";
                 if (component.CodeModule.CountOfLines > 0)
                 {
                     text = component.CodeModule.get_Lines(1, component.CodeModule.CountOfLines);
                 }
                 File.WriteAllText(fullPath, text);
             }
             else
             {
                 component.Export(fullPath);
             }
         }
         config.SaveProject(_projectName, args.Path);
         return(true);
     }
     catch (COMException comEx)
     {
         throw new COMException(string.Format(strings.ExportComExceptionText, comEx.ErrorCode), comEx.ErrorCode);
     }
 }
Пример #2
0
        /// <summary>
        /// Displays folder browser dialog and let user to choose a path to a folder.
        /// Raises event if a path was chosen
        ///  </summary>
        public void PathRequestHandler()
        {
            var selectedPath = Utils.DisplayFolderDialog(false);

            if (selectedPath == null)
            {
                return;
            }
            if (!Utils.HasComponent(selectedPath))
            {
                MessageBox.Show(strings.InvalidComponentFolder, strings.ImportFormMessageCaption, MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);
            }
            else
            {
                _components = Utils.GetComponents(selectedPath);
                Project project = null;
                // if manually added, check if already exists in list of projects
                // if not, save it to config and add it to list
                if (!HasProject(selectedPath))
                {
                    string projectName = System.IO.Path.GetFileName(selectedPath);
                    _config.SaveProject(projectName, selectedPath);
                    project = new Project()
                    {
                        Name = projectName, Path = selectedPath, Valid = true, Components = _components
                    };
                    AddProject(project);
                }
                else
                {
                    project = Projects.First(x => x.Path == selectedPath);
                }

                if (ValidProjectAdded != null)
                {
                    ValidProjectAdded(null, null);
                }
                if (CurrentProjectChanged != null)
                {
                    CurrentProjectChanged(project, null);
                }
            }
        }