Пример #1
0
        private static string GetUsings()
        {
            HostControl hostControl = null;
            string      result      = "";

            foreach (Control item in _listControls)
            {
                hostControl = item as HostControl;
                if (null != hostControl)
                {
                    List <string> hostApps = hostControl.HostApplications;
                    AddDependenciesToList(hostApps);

                    if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                    {
                        result += "using NetOffice;" + Environment.NewLine;
                    }
                    else
                    {
                        result += "Imports NetOffice" + Environment.NewLine;
                    }

                    foreach (string app in hostApps)
                    {
                        result += CodeTemplates.Using(_projectOptions.Language).Replace("%Alias%", app).Replace("%Name%", app) + Environment.NewLine;
                    }

                    break;
                }
            }

            if (_projectOptions.ProjectType == ProjectType.ToolsAddin)
            {
                if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                {
                    result += "using NetOffice.Tools;" + Environment.NewLine;
                    if (hostControl.HostApplications.Count > 1)
                    {
                        result += "using NetOffice.OfficeApi.Tools;" + Environment.NewLine;
                    }
                    else
                    {
                        result += "using NetOffice." + hostControl.HostApplications[0] + "Api.Tools;" + Environment.NewLine;
                    }
                }
                else
                {
                    result += "Imports NetOffice.Tools" + Environment.NewLine;
                    if (hostControl.HostApplications.Count > 1)
                    {
                        result += "Imports NetOffice.OfficeApi.Tools" + Environment.NewLine;
                    }
                    else
                    {
                        result += "Imports NetOffice." + hostControl.HostApplications[0] + "Api.Tools" + Environment.NewLine;
                    }
                }
            }
            return(result);
        }
Пример #2
0
        static void CreateSolutionFile(string targetFolder, string projectGuid)
        {
            string solutionContent = CodeTemplates.SolutionFile(_projectOptions.Language, (_projectOptions.IDE == IDE.VS2010));

            solutionContent = solutionContent.Replace("%ProjectName%", _projectOptions.AssemblyName);
            solutionContent = solutionContent.Replace("%ProjectGUID%", projectGuid);
            string filePath = Path.Combine(targetFolder, _projectOptions.AssemblyName + ".sln");

            File.AppendAllText(filePath, solutionContent, Encoding.UTF8);
        }
Пример #3
0
        static void CreateTaskPane(string targetFolder)
        {
            if (!_projectOptions.UseTaskPane)
            {
                return;
            }
            string file         = CodeTemplates.TaskPane(_projectOptions.Language).Replace("$namespace$", _projectOptions.AssemblyName);
            string fileDesigner = CodeTemplates.TaskPaneDesigner(_projectOptions.Language).Replace("$namespace$", _projectOptions.AssemblyName);

            if (_projectOptions.Language == ProgrammingLanguage.CSharp)
            {
                File.AppendAllText(Path.Combine(targetFolder, "TaskPaneControl.cs"), file, Encoding.UTF8);
                File.AppendAllText(Path.Combine(targetFolder, "TaskPaneControl.Designer.cs"), fileDesigner, Encoding.UTF8);
            }
            else
            {
                File.AppendAllText(Path.Combine(targetFolder, "TaskPaneControl.vb"), file, Encoding.UTF8);
                File.AppendAllText(Path.Combine(targetFolder, "TaskPaneControl.Designer.vb"), fileDesigner, Encoding.UTF8);
            }
        }
Пример #4
0
        private static string GetUnRegisterCode()
        {
            string result = "";

            foreach (Control item in _listControls)
            {
                HostControl hostControl = item as HostControl;
                if (null != hostControl)
                {
                    List <string> hostApps = ToList(_projectOptions.OfficeApps);
                    foreach (string app in hostApps)
                    {
                        string unRegisterCode = CodeTemplates.UnRegisterCode(_projectOptions.Language);
                        unRegisterCode = unRegisterCode.Replace("%HiveKey%", _projectOptions.RegistryKey).Replace("%OfficAddinKey%", GetOfficeAddinKey(app));
                        result        += unRegisterCode;
                    }
                    return(result);
                }
            }
            throw new ArgumentOutOfRangeException("HostControl");
        }
Пример #5
0
        private static string GetRegisterCode()
        {
            string result = "";

            foreach (Control item in _listControls)
            {
                HostControl hostControl = item as HostControl;
                if (null != hostControl)
                {
                    List <string> hostApps = ToList(_projectOptions.OfficeApps);
                    foreach (string app in hostApps)
                    {
                        string registerCode = CodeTemplates.RegisterCode(_projectOptions.Language);
                        registerCode = registerCode.Replace("%OfficeApp%", app).Replace("%HiveKey%", _projectOptions.RegistryKey).Replace("%OfficAddinKey%", GetOfficeAddinKey(app));
                        registerCode = registerCode.Replace("%Name%", _projectOptions.AssemblyName).Replace("%Description%", _projectOptions.AssemblyDescription).Replace("%LoadBehavior%", GetLoadBehaviour());
                        result      += registerCode;
                    }
                    return(result);
                }
            }
            throw new ArgumentOutOfRangeException("HostControl");
        }
Пример #6
0
        private static void DoReplace(string targetFolder)
        {
            string safeRandomGuid = Guid.NewGuid().ToString().ToUpper();

            if (IsAddinProject())
            {
                DeleteNonUsedAddinFiles(targetFolder);
            }

            string[] files = Directory.GetFiles(targetFolder, "*.*", SearchOption.AllDirectories);
            foreach (string file in files)
            {
                string fileContent = File.ReadAllText(file, Encoding.UTF8);
                fileContent = fileContent.Replace("$safeprojectname$", _projectOptions.AssemblyName);

                if (_projectOptions.UseNetRuntimeClient)
                {
                    fileContent = fileContent.Replace("$targetframeworkversion$", _projectOptions.NetRuntime.ToString("0.0").Replace(",", "."));
                    string target = "<TargetFrameworkVersion>v" + _projectOptions.NetRuntime.ToString("0.0").Replace(",", ".") + "</TargetFrameworkVersion>";
                    fileContent = fileContent.Replace(target, target + Environment.NewLine + "    <TargetFrameworkProfile>Client</TargetFrameworkProfile>");
                }
                else
                {
                    fileContent = fileContent.Replace("$targetframeworkversion$", _projectOptions.NetRuntime.ToString("0.0").Replace(",", "."));
                }

                fileContent = fileContent.Replace("$assemblyReferences$", GetAssemblyReferences());
                fileContent = fileContent.Replace("$usingItems$", GetUsings());
                fileContent = fileContent.Replace("$randomGuid$", safeRandomGuid);
                fileContent = fileContent.Replace("$safeitemname$", "Addin");
                fileContent = fileContent.Replace("$assemblyGuid$", Guid.NewGuid().ToString());

                if (_projectOptions.ProjectType == ProjectType.ToolsAddin)
                {
                    fileContent = fileContent.Replace("$name$", GetName());
                    fileContent = fileContent.Replace("$description$", GetDescription());
                    fileContent = fileContent.Replace("$loadbeahviour$", GetLoadBehaviour());

                    if (IsMultiHost())
                    {
                        if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                        {
                            fileContent = fileContent.Replace(" : COMAddin", " : NetOffice.OfficeApi.Tools.COMAddin");
                            fileContent = fileContent.Replace("$multiRegister$", ",MultiRegister(" + GetHostApplications() + ")");
                        }
                        else
                        {
                            fileContent = fileContent.Replace("Inherits COMAddin", "Inherits NetOffice.OfficeApi.Tools.COMAddin");
                            fileContent = fileContent.Replace("$multiRegister$", ",MultiRegister(" + GetHostApplications() + ")");
                        }
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$multiRegister$", "");
                    }

                    //
                    if (UseRibbonUI())
                    {
                        if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                        {
                            fileContent = fileContent.Replace("$ribbon$", ", CustomUI(\"" + _projectOptions.AssemblyName + ".RibbonUI.xml\")");
                        }
                        else
                        {
                            fileContent = fileContent.Replace("$ribbon$", ", CustomUI(\"" + _projectOptions.AssemblyName + ".RibbonUI.xml\")");
                        }
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$ribbon$", "");
                    }

                    string hiveKey = GetHiveKey();
                    if (hiveKey == "LocalMachine")
                    {
                        if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                        {
                            fileContent = fileContent.Replace("$registry$", ", RegistryLocation(RegistrySaveLocation.LocalMachine)");
                        }
                        else
                        {
                            fileContent = fileContent.Replace("$registry$", ", RegistryLocation(RegistrySaveLocation.LocalMachine)");
                        }
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$registry$", "");
                    }

                    if (_projectOptions.UseClassicUI)
                    {
                        fileContent = fileContent.Replace("$classicUICreateCall$", CodeTemplates.ClassicUICall(_projectOptions.Language));
                        fileContent = fileContent.Replace("$classicUIRemoveCall$", CodeTemplates.ClassicUIRemoveCall(_projectOptions.Language).Replace("\r\n", ""));
                        string uiMethods = "\r\n" + CodeTemplates.ClassicUIMethod(_projectOptions.Language) + CodeTemplates.ClassicUIRemoveMethod(_projectOptions.Language);
                        uiMethods   = uiMethods.Substring(0, uiMethods.Length - 2);
                        fileContent = fileContent.Replace("$classicUICreateRemoveMethod$", uiMethods);
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$classicUICreateCall$", "");
                        fileContent = fileContent.Replace("$classicUIRemoveCall$", "");
                        fileContent = fileContent.Replace("$classicUICreateRemoveMethod$", "");
                    }
                }

                if (IsAddinProject())
                {
                    if (_projectOptions.UseRibbonUI)
                    {
                        fileContent = fileContent.Replace("$ribbonFileReference$", CodeTemplates.RibbonReference);
                        fileContent = fileContent.Replace("$ribbonImplement$", CodeTemplates.RibbonImplement(_projectOptions.Language));

                        if (_projectOptions.ProjectType == ProjectType.ToolsAddin)
                        {
                            fileContent = fileContent.Replace("$ribbonUIImplementMethod$", CodeTemplates.RibbonImplementToolsCode(_projectOptions.Language));
                        }
                        else
                        {
                            fileContent = fileContent.Replace("$ribbonUIImplementMethod$", CodeTemplates.RibbonImplementCode(_projectOptions.Language) + "\r\n");
                        }

                        fileContent = fileContent.Replace("$helperCode$", CodeTemplates.HelperCode(_projectOptions.Language));
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$ribbonFileReference$", "");
                        fileContent = fileContent.Replace("$ribbonImplement$", "");
                        fileContent = fileContent.Replace("$ribbonUIImplementMethod$", "");
                        fileContent = fileContent.Replace("$helperCode$", "");
                    }

                    if (_projectOptions.UseClassicUI && _projectOptions.ProjectType != ProjectType.ToolsAddin)
                    {
                        fileContent = fileContent.Replace("$classicUICreateCall$", CodeTemplates.ClassicUICall(_projectOptions.Language));
                        fileContent = fileContent.Replace("$classicUIRemoveCall$", CodeTemplates.ClassicUIRemoveCall(_projectOptions.Language));
                        fileContent = fileContent.Replace("$classicUICreateRemoveMethod$", CodeTemplates.ClassicUIMethod(_projectOptions.Language) + CodeTemplates.ClassicUIRemoveMethod(_projectOptions.Language));
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$classicUICreateCall$", "");
                        fileContent = fileContent.Replace("$classicUIRemoveCall$", "");
                        fileContent = fileContent.Replace("$classicUICreateRemoveMethod$", "");
                    }

                    if (_projectOptions.UseTaskPane)
                    {
                        if (_projectOptions.ProjectType == ProjectType.ToolsAddin)
                        {
                            fileContent = fileContent.Replace("$TaskPaneImplement$", CodeTemplates.TaskPaneToolsMethod(_projectOptions.Language));
                        }
                        else
                        {
                            fileContent = fileContent.Replace("$TaskPaneImplement$", _projectOptions.Language == ProgrammingLanguage.CSharp ? ", Office.ICustomTaskPaneConsumer" : ", Office.ICustomTaskPaneConsumer");
                            fileContent = fileContent.Replace("$TaskPaneField$", _projectOptions.Language == ProgrammingLanguage.CSharp ? "        private TaskPaneControl _taskPaneControl;\r\n" : "\r\n    Shared _taskPaneControl As TaskPaneControl");
                            fileContent = fileContent.Replace("$TaskPaneMethod$", CodeTemplates.TaskPaneMethod(_projectOptions.Language));
                        }
                        if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                        {
                            fileContent = fileContent.Replace("<Compile Include=\"Addin.cs\" />\r\n", "<Compile Include=\"Addin.cs\" />" + "\r\n" + CodeTemplates.TaskPaneCompile(_projectOptions.Language));
                        }
                        else
                        {
                            fileContent = fileContent.Replace("<Compile Include=\"Addin.vb\" />\r\n", "<Compile Include=\"Addin.vb\" />" + "\r\n" + CodeTemplates.TaskPaneCompile(_projectOptions.Language));
                        }
                    }
                    else
                    {
                        fileContent = fileContent.Replace("$TaskPaneImplement$", "");
                        fileContent = fileContent.Replace("$TaskPaneField$", "");
                        fileContent = fileContent.Replace("$TaskPaneMethod$", "");
                    }

                    fileContent = fileContent.Replace("$registerCode$", GetRegisterCode());
                    fileContent = fileContent.Replace("$unregisterCode$", GetUnRegisterCode());

                    if (_projectOptions.OfficeApps.Length == 1)
                    {
                        fileContent = fileContent.Replace("$ApplicationField$", CodeTemplates.AppFieldCode(_projectOptions.Language).Replace("%OfficeApp%", _projectOptions.OfficeApps[0]));
                    }
                    else
                    {
                        if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                        {
                            fileContent = fileContent.Replace("$ApplicationField$", "\t\tCOMObject _application;\r\n");
                        }
                        else
                        {
                            fileContent = fileContent.Replace("$ApplicationField$", "\tDim _application As COMObject\r\n");
                        }
                    }

                    if (_projectOptions.OfficeApps.Length == 1)
                    {
                        fileContent = fileContent.Replace("$ApplicationConstruction$", CodeTemplates.AppConstructionCode(_projectOptions.Language).Replace("%OfficeApp%", _projectOptions.OfficeApps[0]));
                    }
                    else
                    {
                        if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                        {
                            fileContent = fileContent.Replace("$ApplicationConstruction$", "\t\t\t_application = Factory.CreateObjectFromComProxy(null, Application);");
                        }
                        else
                        {
                            fileContent = fileContent.Replace("$ApplicationConstruction$", "\t\t_application = Factory.CreateObjectFromComProxy(Nothing, Application)");
                        }
                    }
                    fileContent = fileContent.Replace("$ApplicationDestroy$", CodeTemplates.AppDestroyCode(_projectOptions.Language));

                    if (_projectOptions.Language == ProgrammingLanguage.CSharp)
                    {
                        fileContent = fileContent.Replace("void IDTExtensibility2.OnStartupComplete(ref Array custom)", "\tvoid IDTExtensibility2.OnStartupComplete(ref Array custom)");
                    }
                }

                File.Delete(file);
                File.AppendAllText(file, fileContent, Encoding.UTF8);
            }
        }