// <snippet3> public void Execute(AddInPostDeploymentActionArgs args) { string dataDirectory = @"Data\ExcelWorkbook.xlsx"; string file = @"ExcelWorkbook.xlsx"; string sourcePath = args.AddInPath; Uri deploymentManifestUri = args.ManifestLocation; string destPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string sourceFile = System.IO.Path.Combine(sourcePath, dataDirectory); string destFile = System.IO.Path.Combine(destPath, file); switch (args.InstallationStatus) { case AddInInstallationStatus.InitialInstall: case AddInInstallationStatus.Update: File.Copy(sourceFile, destFile); ServerDocument.RemoveCustomization(destFile); ServerDocument.AddCustomization(destFile, deploymentManifestUri); break; case AddInInstallationStatus.Uninstall: if (File.Exists(destFile)) { File.Delete(destFile); } break; } }
SetAssemblyLocationInTemplateFile ( AddInPostDeploymentActionArgs args ) { // Before this method is called, the _AssemblyLocation property in the // template file is set to this: // // Smrf.NodeXL.ExcelTemplate.vsto|aa51c0f3-62b4-4782-83a8-a15dcdd17698|vstolocal // // The "vstolocal" is a marker added by Visual Studio to assist during // development, but it has to be removed during deployment. Also, the // relative path to the Smrf.NodeXL.ExcelTemplate.vsto deployment // manifest needs to be replaced with an absolute path. // // This method changes the _AssemblyLocation property to something like // this: // // http://SomeSite/SomePath/Smrf.NodeXL.ExcelTemplate.vsto|aa51c0f3-62b4-4782-83a8-a15dcdd17698 // // It gets the absolute path to the deployment manifest from the // AddInPostDeploymentActionArgs.ManifestLocation property. // String nodeXLTemplatePath = GetNodeXLTemplatePath(args); ServerDocument.RemoveCustomization(nodeXLTemplatePath); ServerDocument.AddCustomization( nodeXLTemplatePath, args.ManifestLocation); }
public override void Install(IDictionary stateSaver) { string[] nonpublicCachedDataMembers = null; Uri deploymentManifestLocation = null; if (Uri.TryCreate( Context.Parameters["deploymentManifestLocation"], UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false) { throw new InstallException( "The location of the deployment manifest " + "is missing or invalid."); } string documentLocation = Context.Parameters["documentLocation"]; if (String.IsNullOrEmpty(documentLocation)) { throw new InstallException( "The location of the document is missing."); } string assemblyLocation = Context.Parameters["assemblyLocation"]; if (String.IsNullOrEmpty(assemblyLocation)) { throw new InstallException( "The location of the assembly is missing."); } string targetLocation = CreateTargetLocation(documentLocation); File.Copy(documentLocation, targetLocation); if (ServerDocument.IsCustomized(targetLocation)) { ServerDocument.RemoveCustomization(targetLocation); } ServerDocument.AddCustomization( targetLocation, assemblyLocation, SolutionID, deploymentManifestLocation, true, out nonpublicCachedDataMembers); stateSaver.Add("targetLocation", targetLocation); base.Install(stateSaver); }
private static void AddVSTOCustomization() { //<Snippet3> string documentPath = System.Environment.GetFolderPath( Environment.SpecialFolder.Desktop) + @"\WordDocument1.docx"; int runtimeVersion = 0; try { runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath); // Make sure that this document does not yet have any Visual Studio Tools // for Office customizations. if (runtimeVersion == 0) { string deployManifestPath = System.Environment.GetFolderPath( Environment.SpecialFolder.Desktop) + @"\Publish\WordDocument1.vsto"; Uri deploymentManifestUri = new Uri(deployManifestPath); ServerDocument.AddCustomization(documentPath, deploymentManifestUri); System.Windows.Forms.MessageBox.Show("The document was successfully customized."); } else { System.Windows.Forms.MessageBox.Show("The document is already customized."); } } catch (FileNotFoundException) { System.Windows.Forms.MessageBox.Show("The specified document does not exist."); } catch (DocumentNotCustomizedException ex) { System.Windows.Forms.MessageBox.Show("The document could not be customized.\n" + ex.Message); } //</Snippet3> }
//</Snippet6> //<Snippet7> private void AddCustomizationUsingAssemblyPath(string documentPath, string assemblyName, Guid solutionID, string deployManifestPath) { int runtimeVersion = 0; try { runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath); // Make sure that this document does not yet have any Visual Studio Tools // for Office customizations. if (runtimeVersion == 0) { Uri deploymentManifestUri = new Uri(deployManifestPath); ServerDocument.AddCustomization(documentPath, assemblyName, solutionID, deploymentManifestUri); MessageBox.Show("The document was successfully customized."); } else { System.Windows.Forms.MessageBox.Show("The document is already customized."); } } catch (System.IO.FileNotFoundException) { System.Windows.Forms.MessageBox.Show("The specified document does not exist."); } catch (UnknownCustomizationFileException) { System.Windows.Forms.MessageBox.Show("The specified document has a file " + "extension that is not supported by Visual Studio Tools for Office."); } catch (DocumentNotCustomizedException ex) { System.Windows.Forms.MessageBox.Show("The document could not be customized.\n" + ex.Message); } }
static void Main(string[] args) { string assemblyLocation = ""; Guid solutionID = new Guid(); Uri deploymentManifestLocation = null; string documentLocation = ""; string[] nonpublicCachedDataMembers = null; for (int i = 0; i <= args.Count() - 1; i++) { Console.WriteLine(args[i]); string[] oArugment = args[i].Split('='); switch (oArugment[0]) { case "/assemblyLocation": assemblyLocation = oArugment[1]; break; case "/deploymentManifestLocation": if (!Uri.TryCreate(oArugment[1], UriKind.Absolute, out deploymentManifestLocation)) { Console.WriteLine("Error creating URI"); } break; case "/documentLocation": documentLocation = oArugment[1]; break; case "/solutionID": solutionID = Guid.Parse(oArugment[1]); break; } } try { ServerDocument.RemoveCustomization(documentLocation); ServerDocument.AddCustomization(documentLocation, assemblyLocation, solutionID, deploymentManifestLocation, true, out nonpublicCachedDataMembers); } catch (System.IO.FileNotFoundException) { Console.WriteLine("The specified document does not exist."); } catch (System.IO.IOException) { Console.WriteLine("The specified document is read-only."); } catch (InvalidOperationException ex) { Console.WriteLine("The customization could not be removed.\n" + ex.Message); } catch (DocumentNotCustomizedException ex) { Console.WriteLine("The document could not be customized.\n" + ex.Message); } }
public void Execute(AddInPostDeploymentActionArgs args) { XElement parameters = XElement.Parse(args.PostActionManifestXml); //configurabili string dataDirectory = @"Data\"; string file = parameters.Attribute("filename").Value; //statici string sourcePath = args.AddInPath; string destPath = Environment.ExpandEnvironmentVariables(Base.Simboli.LocalBasePath); Uri deploymentManifestUri = args.ManifestLocation; string sourceFile = Path.Combine(sourcePath, dataDirectory, file); string destFile = Path.Combine(destPath, file); switch (args.InstallationStatus) { case AddInInstallationStatus.InitialInstall: if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } System.IO.File.Copy(sourceFile, destFile, true); if (ServerDocument.IsCustomized(destFile)) { ServerDocument.RemoveCustomization(destFile); } ServerDocument.AddCustomization(destFile, deploymentManifestUri); break; case AddInInstallationStatus.Update: string dirUPDATE = Path.Combine(destPath, "UPDATE"); string fileUPDATE = Path.Combine(dirUPDATE, file); if (!Directory.Exists(dirUPDATE)) { Directory.CreateDirectory(dirUPDATE); } System.IO.File.Copy(sourceFile, fileUPDATE, true); if (ServerDocument.IsCustomized(fileUPDATE)) { ServerDocument.RemoveCustomization(fileUPDATE); } ServerDocument.AddCustomization(fileUPDATE, deploymentManifestUri); break; case AddInInstallationStatus.Uninstall: if (System.IO.File.Exists(destFile)) { //rimuovo file di installazione System.IO.File.Delete(destFile); //rimuovo directory di update string update = Path.Combine(destPath, "UPDATE"); if (Directory.Exists(update) && !Directory.EnumerateFileSystemEntries(update).Any()) { Directory.Delete(update); } //rimuovo directory PSO if (!Directory.EnumerateFileSystemEntries(destPath).Any()) { Directory.Delete(destPath); } } break; } }
ConvertNodeXLWorkbook ( String otherWorkbookFile, String convertedWorkbookFile ) { Debug.Assert(!String.IsNullOrEmpty(otherWorkbookFile)); Debug.Assert(File.Exists(otherWorkbookFile)); Debug.Assert(!String.IsNullOrEmpty(convertedWorkbookFile)); // The application's template is needed to get the customization // information. String sTemplatePath; if (!ApplicationUtil.TryGetTemplatePath(out sTemplatePath)) { throw new NodeXLWorkbookConversionException( ApplicationUtil.GetMissingTemplateMessage()); } try { File.Copy(otherWorkbookFile, convertedWorkbookFile, true); } catch (UnauthorizedAccessException) { throw new NodeXLWorkbookConversionException( "The converted copy already exists and is read-only. It can't" + " be overwritten." ); } catch (IOException oIOException) { if (oIOException.Message.Contains( "it is being used by another process")) { throw new NodeXLWorkbookConversionException( "The converted copy already exists and is open in Excel." + " It can't be overwritten." ); } throw (oIOException); } // Remove the other customization. try { if (ServerDocument.GetCustomizationVersion( convertedWorkbookFile) > 0) { ServerDocument.RemoveCustomization(convertedWorkbookFile); } } catch (Microsoft.VisualStudio.Tools.Applications.Runtime. UnknownCustomizationFileException) { throw new NodeXLWorkbookConversionException( "The file doesn't appear to be an Excel workbook." ); } // Create a ServerDocument from the application's template. The // solution ID and deployment manifest name will be obtained from this. using (ServerDocument oTemplateServerDocument = new ServerDocument(sTemplatePath, FileAccess.Read)) { // For some reason, ServerDocument.AddCustomization() also requires // a path to the NodeXL assembly file, even though it doesn't get // embedded in the document. String sAssemblyFile = new Uri( Assembly.GetExecutingAssembly().CodeBase).LocalPath; String [] asNonPublicCachedDataMembers; ServerDocument.AddCustomization(convertedWorkbookFile, sAssemblyFile, oTemplateServerDocument.SolutionId, oTemplateServerDocument.DeploymentManifestUrl, false, out asNonPublicCachedDataMembers); } }
public override void Install(IDictionary stateSaver) { string[] nonpublicCachedDataMembers = null; // Use the following for debugging during the install //string parameters = "Parameters in Context.Paramters:"; //foreach (DictionaryEntry parameter in Context.Parameters) //{ // parameters = parameters + "\n" + parameter.Key + ":" + parameter.Value; //} //MessageBox.Show(parameters); //MessageBox.Show("total items in parameters: " + Context.Parameters.Count); //MessageBox.Show("Document Manifest Location:" + Context.Parameters["deploymentManifestLocation"]); Uri deploymentManifestLocation = null; if (Uri.TryCreate( Context.Parameters["deploymentManifestLocation"], UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false) { throw new InstallException( "The location of the deployment manifest " + "is missing or invalid."); } string documentLocation = Context.Parameters["documentLocation"]; if (String.IsNullOrEmpty(documentLocation)) { throw new InstallException( "The location of the document is missing."); } string assemblyLocation = Context.Parameters["assemblyLocation"]; if (String.IsNullOrEmpty(assemblyLocation)) { throw new InstallException( "The location of the assembly is missing."); } // use the following for debugging MessageBox.Show(documentLocation); if (ServerDocument.IsCustomized(documentLocation)) { ServerDocument.RemoveCustomization(documentLocation); } ServerDocument.AddCustomization( documentLocation, assemblyLocation, SolutionID, deploymentManifestLocation, false, out nonpublicCachedDataMembers); stateSaver.Add("documentlocation", documentLocation); base.Install(stateSaver); }