Exemple #1
0
        static void Main(string[] args)
        {
            ServerDocument sd = null;

            try {
                //Update the documents' internal manifest to point to the new location of
                //the customization library (dll)
                //1. Open the office document/template
                //Console.WriteLine("Enter the fullpath to the Office document or template:");
                //string doc = Console.ReadLine();
                sd = new ServerDocument("c:\\Argix.InvoiceHugoBoss.xltx");

                //2. Get the new path of the .Net dll (local, UNC, http, ftp)
                //Console.WriteLine("Enter the fullpath to the customization library:");
                //string lib = Console.ReadLine();
                string uri = sd.DeploymentManifestUrl.ToString(); // = lib;
                string id  = sd.SolutionId.ToString();            // = lib;

                //3. Save the assembly path into the document/template internal manifest
                sd.DeploymentManifestUrl = new Uri(sd.DeploymentManifestUrl.AbsoluteUri.Replace("rgxweb", "rgxvmweb"));
                sd.Save();
                Console.Read();
            }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.Read(); }
            finally { if (sd != null)
                      {
                          sd.Close();
                      }
            }
        }
        private void UpdateApplicationManifest()
        {
            // Define the parameters passed to the task.
            string targetDir    = this.Context.Parameters["targetDir"];
            string documentName = this.Context.Parameters["documentName"];
            string assemblyName = this.Context.Parameters["assemblyName"];

            if (String.IsNullOrEmpty(targetDir))
            {
                throw new InstallException("Cannot update the application manifest. The specified target directory name is not valid.");
            }
            if (String.IsNullOrEmpty(documentName))
            {
                throw new InstallException("Cannot update the application manifest. The specified document name is not valid.");
            }
            if (String.IsNullOrEmpty(assemblyName))
            {
                throw new InstallException("Cannot update the application manifest. The specified assembly name is not valid.");
            }

            // Get the application manifest from the document.
            string         documentPath   = Path.Combine(targetDir, documentName);
            ServerDocument serverDocument = new ServerDocument(documentPath, FileAccess.ReadWrite);

            try
            {
                AppManifest appManifest = serverDocument.AppManifest;

                string assemblyPath = Path.Combine(targetDir, assemblyName);
                appManifest.Dependency.AssemblyPath = assemblyPath;

                serverDocument.Save();
            }
            finally
            {
                if (serverDocument != null)
                {
                    serverDocument.Close();
                }
            }
        }
        static private void InitializeCachedDataSet()
        {
            //<Snippet2>
            //<Snippet3>
            AdventureWorksDataSet.AdventureWorksLTDataSet productDataSet =
                new AdventureWorksDataSet.AdventureWorksLTDataSet();
            AdventureWorksDataSet.AdventureWorksLTDataSetTableAdapters.ProductTableAdapter productTableAdapter =
                new AdventureWorksDataSet.AdventureWorksLTDataSetTableAdapters.ProductTableAdapter();

            string workbookPath = System.Environment.GetFolderPath(
                Environment.SpecialFolder.MyDocuments) +
                                  @"\AdventureWorksReport\bin\Debug\AdventureWorksReport.xlsx";
            ServerDocument serverDocument1 = null;

            //</Snippet3>

            //<Snippet4>
            try
            {
                productTableAdapter.Fill(productDataSet.Product);
                Console.WriteLine("The local dataset is filled.");

                serverDocument1 = new ServerDocument(workbookPath);
                CachedDataHostItem dataHostItem1 =
                    serverDocument1.CachedData.HostItems["AdventureWorksReport.Sheet1"];
                CachedDataItem dataItem1 = dataHostItem1.CachedData["adventureWorksLTDataSet"];

                // Initialize the worksheet dataset with the local dataset.
                if (dataItem1 != null)
                {
                    dataItem1.SerializeDataInstance(productDataSet);
                    serverDocument1.Save();
                    Console.WriteLine("The data is saved to the data cache.");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("The data object is not found in the data cache.");
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (System.IO.FileNotFoundException)
            {
                Console.WriteLine("The specified workbook does not exist.");
            }
            finally
            {
                if (serverDocument1 != null)
                {
                    serverDocument1.Close();
                }

                Console.WriteLine("\n\nPress Enter to close the application.");
                Console.ReadLine();
            }
            //</Snippet4>
            //</Snippet2>
        }
        static private void ReadCachedDataSet()
        {
            //<Snippet9>
            //<Snippet10>
            AdventureWorksDataSet.AdventureWorksLTDataSet productDataSet =
                new AdventureWorksDataSet.AdventureWorksLTDataSet();
            string workbookPath = System.Environment.GetFolderPath(
                Environment.SpecialFolder.MyDocuments) +
                                  @"\AdventureWorksReport\bin\Debug\AdventureWorksReport.xlsx";
            ServerDocument serverDocument1 = null;

            //</Snippet10>

            //<Snippet11>
            try
            {
                serverDocument1 = new ServerDocument(workbookPath);
                CachedDataHostItem dataHostItem1 =
                    serverDocument1.CachedData.HostItems["AdventureWorksReport.Sheet1"];
                CachedDataItem dataItem1 = dataHostItem1.CachedData["adventureWorksLTDataSet"];

                if (dataItem1 != null)
                {
                    Console.WriteLine("Before reading data from the cache dataset, the local dataset has " +
                                      "{0} rows.", productDataSet.Product.Rows.Count.ToString());

                    // Read the cached data from the worksheet dataset into the local dataset.
                    System.IO.StringReader schemaReader = new System.IO.StringReader(dataItem1.Schema);
                    System.IO.StringReader xmlReader    = new System.IO.StringReader(dataItem1.Xml);
                    productDataSet.ReadXmlSchema(schemaReader);
                    productDataSet.ReadXml(xmlReader);

                    Console.WriteLine("After reading data from the cache dataset, the local dataset has " +
                                      "{0} rows.", productDataSet.Product.Rows.Count.ToString());
                }
                else
                {
                    Console.WriteLine("The data object is not found in the data cache.");
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                Console.WriteLine("The specified workbook does not exist.");
            }
            catch (System.Xml.XmlException)
            {
                Console.WriteLine("The data object has invalid XML information.");
            }
            finally
            {
                if (serverDocument1 != null)
                {
                    serverDocument1.Close();
                }

                Console.WriteLine("\n\nPress Enter to close the application.");
                Console.ReadLine();
            }
            //</Snippet11>
            //</Snippet9>
        }
        static private void ModifyCachedDataSet()
        {
            //<Snippet5>
            //<Snippet6>
            AdventureWorksDataSet.AdventureWorksLTDataSet productDataSet =
                new AdventureWorksDataSet.AdventureWorksLTDataSet();
            string workbookPath = System.Environment.GetFolderPath(
                Environment.SpecialFolder.MyDocuments) +
                                  @"\AdventureWorksReport\bin\Debug\AdventureWorksReport.xlsx";
            ServerDocument serverDocument1 = null;

            //</Snippet6>

            //<Snippet7>
            try
            {
                serverDocument1 = new ServerDocument(workbookPath);
                CachedDataHostItem dataHostItem1 =
                    serverDocument1.CachedData.HostItems["AdventureWorksReport.Sheet1"];
                CachedDataItem dataItem1 = dataHostItem1.CachedData["adventureWorksLTDataSet"];

                if (dataItem1 != null)
                {
                    Console.WriteLine("Before reading data from the cache dataset, the local dataset has " +
                                      "{0} rows.", productDataSet.Product.Rows.Count.ToString());

                    // Read the cached data from the worksheet dataset into the local dataset.
                    System.IO.StringReader schemaReader = new System.IO.StringReader(dataItem1.Schema);
                    System.IO.StringReader xmlReader    = new System.IO.StringReader(dataItem1.Xml);
                    productDataSet.ReadXmlSchema(schemaReader);
                    productDataSet.ReadXml(xmlReader);

                    Console.WriteLine("After reading data from the cache dataset, the local dataset has " +
                                      "{0} rows.", productDataSet.Product.Rows.Count.ToString());

                    // Modify the prices of each product in the local dataset.
                    foreach (AdventureWorksDataSet.AdventureWorksLTDataSet.ProductRow row in
                             productDataSet.Product.Rows)
                    {
                        if (row.ProductCategoryID < 20)
                        {
                            row.ListPrice = row.ListPrice + (row.ListPrice * (Decimal).10);
                        }
                        else
                        {
                            row.ListPrice = row.ListPrice - (row.ListPrice * (Decimal).10);
                        }
                    }

                    // Write the modified local dataset to the worksheet dataset using the DiffGram format.
                    System.Text.StringBuilder stringIn  = new System.Text.StringBuilder();
                    System.IO.StringWriter    stringOut = new System.IO.StringWriter(stringIn);
                    productDataSet.WriteXml(stringOut, System.Data.XmlWriteMode.DiffGram);
                    dataItem1.Xml = stringIn.ToString();

                    serverDocument1.Save();
                    Console.WriteLine("The product prices have been modified.");
                }
                else
                {
                    Console.WriteLine("The data object is not found in the data cache.");
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                Console.WriteLine("The specified workbook does not exist.");
            }
            catch (System.Xml.XmlException)
            {
                Console.WriteLine("The data object has invalid XML information.");
            }
            finally
            {
                if (serverDocument1 != null)
                {
                    serverDocument1.Close();
                }

                Console.WriteLine("\n\nPress Enter to close the application.");
                Console.ReadLine();
            }
            //</Snippet7>
            //</Snippet5>
        }