internal override CommandLine Parse(string[] args) { if (args.Length < 1) { throw new CommandLineException(Properties.Resources.InvalidNumberOfOptions); } int currentArg = ProcessOptions(args, optionParams); //we know that there is, at least, one more parameters: databasefile CheckDatabase(args[currentArg]); DatabaseFile = args[currentArg]; containers = AccessApp.ContainersFactory(DatabaseFile); if (++currentArg < args.Length) { if (args[currentArg][0] == '@') { ProcessResponseFile(args[currentArg].Substring(1)); } else { ProcessFiles(args, currentArg); } } else { ProcessResponseFile(Console.In); } return(this); }
/// <summary> /// Gets an array of objects names for a specific object container /// </summary> /// <param name="objectType">object type to get its objects</param> public string[] ObjectNames(ObjectType objectType) { string[] result = new string[0]; if (tree.Nodes.Count == 0) { return(result); } Containers containers = AccessApp.ContainersFactory(tree.Nodes[0].Text); ObjectTypeExtension ote = containers.Find(objectType); if (ote != null) { ContainerNames names = ote.Container; TreeNode[] matchNodes = tree.Nodes[0].Nodes.Find(names.DisplayPluralName, true); if (matchNodes.Length == 1) { result = new string[matchNodes[0].Nodes.Count]; for (int i = 0; i < matchNodes[0].Nodes.Count; i++) { result[i] = matchNodes[0].Nodes[i].Text; } } } return(result); }
/// <summary> /// Implements the OnConnection method of the IDTExtensibility2 interface. /// Receives notification that the Add-in is being loaded. /// </summary> /// <param term='application'> /// Root object of the host application. /// </param> /// <param term='connectMode'> /// Describes how the Add-in is being loaded. /// </param> /// <param term='addInInst'> /// Object representing this Add-in. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { string strAppName = (string)application.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, application, null); if (strAppName == "Microsoft Word") { appThis = new WordApp(application); } else if (strAppName == "Microsoft Excel") { appThis = new ExcelApp(application); } else if (strAppName == "Microsoft Publisher") { appThis = new PubApp(application); } else if (strAppName == "Microsoft Access") { appThis = new AccessApp(application); } else { string strError = String.Format("The '{0}' application is not supported!", strAppName); System.Windows.Forms.MessageBox.Show(strError, OfficeApp.cstrCaption); throw new Exception(strError); } if (connectMode != ext_ConnectMode.ext_cm_Startup) { OnStartupComplete(ref custom); } }
/// <summary> /// Enumerate the allowed object types and, for each, the list of objects for that type /// </summary> /// <param name="app">Access application</param> /// <exception cref="ArgumentNullException"> if <paramref name="app"/> is null</exception> private void FillObjectTree(AccessIO.AccessApp app) { //TODO: Do the work in background if (app == null) { throw new ArgumentNullException("app"); } const string key = "db"; Images = new TreeImages(AccessApp.ContainersFactory(fileName)); tree.ImageList = Images.ImageList; tree.ImageKey = key; tree.SelectedImageKey = key; tree.Nodes.Clear(); TreeNode root = tree.Nodes.Add(Path.GetFileName(app.FileName)); root.ToolTipText = app.FileName; foreach (ContainerNames container in app.AllowedContainers) { TreeNode subItem = root.Nodes.Add(container.DisplayPluralName); subItem.ImageKey = container.DefaultExtension.ToString(); subItem.SelectedImageKey = container.DefaultExtension.ToString(); foreach (IObjecOptions item in app.LoadObjectNames(container.InvariantName)) { TreeNode node = new TreeNode(item.Name); node.Tag = item; node.ImageKey = app.AllowedContainers.Find(item.ObjectType).FileExtension.ToString(); node.SelectedImageKey = node.ImageKey; subItem.Nodes.Add(node); } } }
/// <summary> /// Load, in background, the selected objects to the database referenced by <see cref="AccessApp.FileName"/> /// </summary> public void LoadSelectedObjectsAsync(AccessApp app) { LoadObjectsAsyncParams loadParams = new LoadObjectsAsyncParams(); loadParams.App = app; loadParams.SelectedObjects = SelectedNodes; backgroundWorker.RunWorkerAsync(loadParams); }
private void FillTree(string rootPath) { if (String.IsNullOrEmpty(rootPath)) { return; } if (!Directory.Exists(rootPath)) { throw new ArgumentException(Properties.Resources.RootPathNotValid); } tree.Nodes.Clear(); TreeNode rootNode = new TreeNode(BuildRootNodeText(rootPath)); tree.Nodes.Add(rootNode); //Get the list of containers depending on the 'database properties' file //If do not exists that file, containers will be null and we don't know what folders structure should to expect Containers containers = AccessApp.ContainersFactory(rootNode.Text); if (containers == null) { rootNode.Nodes.Add(Properties.Resources.EmptyFileStructure); tree.CheckBoxes = false; return; } else { tree.CheckBoxes = true; } const string key = "folder"; Images = new TreeImages(containers); tree.ImageList = Images.ImageList; tree.ImageKey = key; tree.SelectedImageKey = key; DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); IEnumerable <DirectoryInfo> directories = rootDirectory.EnumerateDirectories(); foreach (ContainerNames names in containers) { TreeNode node = rootNode.Nodes.Add(names.InvariantName, names.InvariantName); node.ImageKey = names.DefaultExtension.ToString(); node.SelectedImageKey = node.ImageKey; DirectoryInfo di = directories.FirstOrDefault <DirectoryInfo>(d => d.Name == names.InvariantName); if (di != null) { FillContainerFiles(di, node, names.ObjectTypes); } } }
private void ProcessAccessObject(string accessObjectName) { Regex regex = new Regex(@"([a-z]{3})\.(.+)", RegexOptions.IgnoreCase); Match match = regex.Match(accessObjectName); if (!match.Success) { throw new CommandLineException(Properties.Resources.InvalidObjectName); } AccessIO.FileExtensions fileExtension; if (!Enum.TryParse <AccessIO.FileExtensions>(match.Groups[1].Value, out fileExtension)) { throw new CommandLineException(Properties.Resources.InvalidObjectName); } Containers containers = AccessApp.ContainersFactory(DatabaseFile); Objects.Add(new AccessIO.ObjectOptions(match.Groups[2].Value, containers.Find(fileExtension).ObjectType)); }
/// <summary> Returns the type of Office Application that is hosting the VBE. </summary> public static IHostApplication HostApplication(this IVBE vbe) { var host = Path.GetFileName(System.Windows.Forms.Application.ExecutablePath).ToUpperInvariant(); //This needs the VBE as a ctor argument. if (host.Equals("SLDWORKS.EXE")) { return(new SolidWorksApp(vbe)); } //The rest don't. if (HostAppMap.ContainsKey(host)) { return((IHostApplication)Activator.CreateInstance(HostAppMap[host])); } //Guessing the above will work like 99.9999% of the time for supported applications. var project = vbe.ActiveVBProject; { if (project.IsWrappingNullReference) { const int ctlViewHost = 106; var commandBars = vbe.CommandBars; var hostAppControl = commandBars.FindControl(ControlType.Button, ctlViewHost); { IHostApplication result; if (hostAppControl.IsWrappingNullReference) { result = null; } else { switch (hostAppControl.Caption) { case "Microsoft Excel": result = new ExcelApp(); break; case "Microsoft Access": result = new AccessApp(); break; case "Microsoft Word": result = new WordApp(); break; case "Microsoft PowerPoint": result = new PowerPointApp(vbe); break; case "Microsoft Outlook": result = new OutlookApp(); break; case "Microsoft Project": result = new ProjectApp(); break; case "Microsoft Publisher": result = new PublisherApp(); break; case "Microsoft Visio": result = new VisioApp(); break; case "AutoCAD": result = new AutoCADApp(); break; case "CorelDRAW": result = new CorelDRAWApp(); break; case "SolidWorks": result = new SolidWorksApp(vbe); break; default: result = null; break; } } return(result); } } var references = project.References; { foreach (var reference in references.Where(reference => (reference.IsBuiltIn && reference.Name != "VBA") || (reference.Name == "AutoCAD"))) { switch (reference.Name) { case "Excel": return(new ExcelApp(vbe)); case "Access": return(new AccessApp()); case "Word": return(new WordApp(vbe)); case "PowerPoint": return(new PowerPointApp(vbe)); case "Outlook": return(new OutlookApp()); case "MSProject": return(new ProjectApp()); case "Publisher": return(new PublisherApp()); case "Visio": return(new VisioApp()); case "AutoCAD": return(new AutoCADApp()); case "CorelDRAW": return(new CorelDRAWApp(vbe)); case "SolidWorks": return(new SolidWorksApp(vbe)); } } } } return(null); }
protected void InitializeAccessApplication() { Console.WriteLine(Properties.Resources.Conecting); App = AccessApp.AccessAppFactory(DatabaseFile); App.OpenDatabase(); }
/// <summary> /// Constructor /// </summary> /// <param name="fileName">Sets the <see cref="App"/> property and fills the object tree</param> public ObjectTree(string fileName) : base() { App = AccessApp.AccessAppFactory(fileName); }