Exemple #1
0
        /// <summary>
        /// Saves the package builder data to disk.
        /// </summary>
        /// <param name="filePath">Path to save the output builder to.</param>
        public override void Save(string filePath)
        {
            OA.OfficeAddin officeAddin = new OA.OfficeAddin();

            // Serialize out the package information.
            OA.Package package = new OA.Package();
            officeAddin.AddChild(package);

            if (this.description != null && this.description.Length > 0)
            {
                OA.Description description = new OA.Description();
                description.Content = this.description;
                package.AddChild(description);
            }

            if (this.updateUrl != null)
            {
                OA.Feed feed = new OA.Feed();
                feed.Content = this.updateUrl.ToString();
                package.AddChild(feed);
            }

            if (this.updateRate > 0)
            {
                OA.UpdateRate updateRate = new OA.UpdateRate();
                updateRate.Content = this.updateRate;
                package.AddChild(updateRate);
            }

            if (this.packageId != Guid.Empty)
            {
                OA.Id id = new OA.Id();
                id.Content = this.packageId.ToString();
                package.AddChild(id);
            }

            if (this.manufacturer != null && this.manufacturer.Length > 0)
            {
                OA.Manufacturer manufacturer = new OA.Manufacturer();
                manufacturer.Content = this.manufacturer;
                package.AddChild(manufacturer);
            }

            if (this.appVersion != null)
            {
                OA.Version version = new OA.Version();
                version.Content = this.appVersion.ToString();
                package.AddChild(version);
            }

            // Serialize out the application information.
            OA.Application application = new OA.Application();
            officeAddin.AddChild(application);

            if (this.details != null && this.details.Length > 0)
            {
                OA.Details details = new OA.Details();
                details.Content = this.details;
                application.AddChild(details);
            }

            if (this.entryPoint != null && this.entryPoint.Length > 0)
            {
                OA.EntryPoint entryPoint = new OA.EntryPoint();
                entryPoint.Content = this.entryPoint;
                application.AddChild(entryPoint);
            }

            foreach (OfficeApplications extendedApp in this.extendedOfficeApplications)
            {
                OA.ExtendsApplication extendsApplication = new OA.ExtendsApplication();
                switch (extendedApp)
                {
                case OfficeApplications.Excel2003:
                    extendsApplication.Content = OA.SupportedOfficeApplications.Excel2003;
                    break;

                case OfficeApplications.Outlook2003:
                    extendsApplication.Content = OA.SupportedOfficeApplications.Outlook2003;
                    break;

                case OfficeApplications.PowerPoint2003:
                    extendsApplication.Content = OA.SupportedOfficeApplications.PowerPoint2003;
                    break;

                case OfficeApplications.Word2003:
                    extendsApplication.Content = OA.SupportedOfficeApplications.Word2003;
                    break;
                }

                application.AddChild(extendsApplication);
            }

            if (this.iconPath != null && this.iconPath.Length > 0)
            {
                OA.Icon icon = new OA.Icon();
                icon.Content = this.iconPath;
                application.AddChild(icon);
            }

            if (this.appId != Guid.Empty)
            {
                OA.Id id = new OA.Id();
                id.Content = this.appId.ToString();
                application.AddChild(id);
            }

            if (this.name != null && this.name.Length > 0)
            {
                OA.Name name = new OA.Name();
                name.Content = this.name;
                application.AddChild(name);
            }

            if (this.source != null && this.source.Length > 0)
            {
                OA.Source source = new OA.Source();
                source.Content = this.source;
                application.AddChild(source);
            }

            // Serialize out the previous package path if there is one.
            if (this.previousFeedUrl != null)
            {
                OA.PreviousFeed previousFeed = new OA.PreviousFeed();
                previousFeed.Content = this.previousFeedUrl.AbsoluteUri;
                officeAddin.AddChild(previousFeed);
            }

            // Serialize the data to disk.
            using (StreamWriter sw = new StreamWriter(filePath))
            {
                XmlTextWriter writer = null;
                try
                {
                    writer             = new XmlTextWriter(sw);
                    writer.Formatting  = Formatting.Indented;
                    writer.Indentation = 4;

                    officeAddin.OutputXml(writer);
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }
        }
        /// <summary>
        /// Saves the package builder data to disk.
        /// </summary>
        /// <param name="filePath">Path to save the output builder to.</param>
        public override void Save(string filePath)
        {
            OA.OfficeAddin officeAddin = new OA.OfficeAddin();

            // Serialize out the package information.
            OA.Package package = new OA.Package();
            officeAddin.AddChild(package);

            if (this.description != null && this.description.Length > 0)
            {
                OA.Description description = new OA.Description();
                description.Content = this.description;
                package.AddChild(description);
            }

            if (this.updateUrl != null)
            {
                OA.Feed feed = new OA.Feed();
                feed.Content = this.updateUrl.ToString();
                package.AddChild(feed);
            }

            if (this.updateRate > 0)
            {
                OA.UpdateRate updateRate = new OA.UpdateRate();
                updateRate.Content = this.updateRate;
                package.AddChild(updateRate);
            }

            if (this.packageId != Guid.Empty)
            {
                OA.Id id = new OA.Id();
                id.Content = this.packageId.ToString();
                package.AddChild(id);
            }

            if (this.manufacturer != null && this.manufacturer.Length > 0)
            {
                OA.Manufacturer manufacturer = new OA.Manufacturer();
                manufacturer.Content = this.manufacturer;
                package.AddChild(manufacturer);
            }

            if (this.appVersion != null)
            {
                OA.Version version = new OA.Version();
                version.Content = this.appVersion.ToString();
                package.AddChild(version);
            }

            // Serialize out the application information.
            OA.Application application = new OA.Application();
            officeAddin.AddChild(application);

            if (this.details != null && this.details.Length > 0)
            {
                OA.Details details = new OA.Details();
                details.Content = this.details;
                application.AddChild(details);
            }

            if (this.entryPoint != null && this.entryPoint.Length > 0)
            {
                OA.EntryPoint entryPoint = new OA.EntryPoint();
                entryPoint.Content = this.entryPoint;
                application.AddChild(entryPoint);
            }

            foreach (OfficeApplications extendedApp in this.extendedOfficeApplications)
            {
                OA.ExtendsApplication extendsApplication = new OA.ExtendsApplication();
                switch (extendedApp)
                {
                    case OfficeApplications.Excel2003:
                        extendsApplication.Content = OA.SupportedOfficeApplications.Excel2003;
                        break;
                    case OfficeApplications.Outlook2003:
                        extendsApplication.Content = OA.SupportedOfficeApplications.Outlook2003;
                        break;
                    case OfficeApplications.PowerPoint2003:
                        extendsApplication.Content = OA.SupportedOfficeApplications.PowerPoint2003;
                        break;
                    case OfficeApplications.Word2003:
                        extendsApplication.Content = OA.SupportedOfficeApplications.Word2003;
                        break;
                }

                application.AddChild(extendsApplication);
            }

            if (this.iconPath != null && this.iconPath.Length > 0)
            {
                OA.Icon icon = new OA.Icon();
                icon.Content = this.iconPath;
                application.AddChild(icon);
            }

            if (this.appId != Guid.Empty)
            {
                OA.Id id = new OA.Id();
                id.Content = this.appId.ToString();
                application.AddChild(id);
            }

            if (this.name != null && this.name.Length > 0)
            {
                OA.Name name = new OA.Name();
                name.Content = this.name;
                application.AddChild(name);
            }

            if (this.source != null && this.source.Length > 0)
            {
                OA.Source source = new OA.Source();
                source.Content = this.source;
                application.AddChild(source);
            }

            // Serialize out the previous package path if there is one.
            if (this.previousFeedUrl != null)
            {
                OA.PreviousFeed previousFeed = new OA.PreviousFeed();
                previousFeed.Content = this.previousFeedUrl.AbsoluteUri;
                officeAddin.AddChild(previousFeed);
            }

            // Serialize the data to disk.
            using (StreamWriter sw = new StreamWriter(filePath))
            {
                XmlTextWriter writer = null;
                try
                {
                    writer = new XmlTextWriter(sw);
                    writer.Formatting = Formatting.Indented;
                    writer.Indentation = 4;

                    officeAddin.OutputXml(writer);
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }
        }