예제 #1
0
        /// <summary>
        /// Loads the package builder data from disk.
        /// </summary>
        /// <param name="path">Path to load the builder information from.</param>
        public override void Open(string path)
        {
            Assembly[]        assemblies = new Assembly[] { Assembly.GetExecutingAssembly() };
            Wix.CodeDomReader reader     = new Wix.CodeDomReader(assemblies);

            OA.OfficeAddin officeAddin = reader.Load(path) as OA.OfficeAddin;
            if (null == officeAddin)
            {
                throw new ApplicationException("Failed to load office addin data file.");
            }

            foreach (Wix.ISchemaElement child in officeAddin.Children)
            {
                if (child is OA.Package)
                {
                    foreach (Wix.ISchemaElement grandchild in ((OA.Package)child).Children)
                    {
                        if (grandchild is OA.Description)
                        {
                            this.description = ((OA.Description)grandchild).Content;
                        }
                        else if (grandchild is OA.Feed)
                        {
                            if (((OA.Feed)grandchild).Content != null)
                            {
                                this.updateUrl = new Uri(((OA.Feed)grandchild).Content);
                            }
                        }
                        else if (grandchild is OA.UpdateRate)
                        {
                            if (((OA.UpdateRate)grandchild).Content != 0)
                            {
                                this.updateRate = Convert.ToInt32(((OA.UpdateRate)grandchild).Content);
                            }
                        }
                        else if (grandchild is OA.Icon)
                        {
                        }
                        else if (grandchild is OA.Id)
                        {
                            if (((OA.Id)grandchild).Content != null)
                            {
                                this.packageId = new Guid(((OA.Id)grandchild).Content);
                            }
                        }
                        else if (grandchild is OA.Manufacturer)
                        {
                            this.manufacturer = ((OA.Manufacturer)grandchild).Content;
                        }
                        else if (grandchild is OA.Version)
                        {
                            if (((OA.Version)grandchild).Content != null)
                            {
                                this.appVersion = new Version(((OA.Version)grandchild).Content);
                            }
                        }
                    }
                }
                else if (child is OA.Application)
                {
                    foreach (Wix.ISchemaElement grandchild in ((OA.Application)child).Children)
                    {
                        if (grandchild is OA.Details)
                        {
                            this.details = ((OA.Details)grandchild).Content;
                        }
                        else if (grandchild is OA.EntryPoint)
                        {
                            this.entryPoint = ((OA.EntryPoint)grandchild).Content;
                        }
                        else if (grandchild is OA.ExtendsApplication)
                        {
                            OfficeApplications extendedApp;
                            switch (((OA.ExtendsApplication)grandchild).Content)
                            {
                            case OA.SupportedOfficeApplications.Excel2003:
                                extendedApp = OfficeApplications.Excel2003;
                                break;

                            case OA.SupportedOfficeApplications.Outlook2003:
                                extendedApp = OfficeApplications.Outlook2003;
                                break;

                            case OA.SupportedOfficeApplications.PowerPoint2003:
                                extendedApp = OfficeApplications.PowerPoint2003;
                                break;

                            case OA.SupportedOfficeApplications.Word2003:
                                extendedApp = OfficeApplications.Word2003;
                                break;

                            default:
                                throw new ArgumentException("Unexpected application in data file.", "ExtendsApplication");
                            }

                            if (!this.extendedOfficeApplications.Contains(extendedApp))
                            {
                                this.extendedOfficeApplications.Add(extendedApp);
                            }
                        }
                        else if (grandchild is OA.Icon)
                        {
                            this.iconPath = ((OA.Icon)grandchild).Content;
                        }
                        else if (grandchild is OA.Id)
                        {
                            this.appId = new Guid(((OA.Id)grandchild).Content);
                        }
                        else if (grandchild is OA.Name)
                        {
                            this.name = ((OA.Name)grandchild).Content;
                        }
                        else if (grandchild is OA.Source)
                        {
                            if (((OA.Source)grandchild).Content != null)
                            {
                                string expandedSource = System.Environment.ExpandEnvironmentVariables(((OA.Source)grandchild).Content);
                                this.source = Path.GetFullPath(expandedSource);
                            }
                        }
                    }
                }
                else if (child is OA.PreviousFeed)
                {
                    if (((OA.PreviousFeed)child).Content != null)
                    {
                        string expandedUrl = System.Environment.ExpandEnvironmentVariables(((OA.PreviousFeed)child).Content);
                        this.previousFeedUrl = new Uri(expandedUrl);
                    }
                }
            }

            if (this.entryPoint != null)
            {
                if (this.source != null)
                {
                    string fullPath = Path.Combine(this.source, this.entryPoint);
                    this.entryPointVersionInfo = FileVersionInfo.GetVersionInfo(fullPath);
                }
            }

            if (this.Opened != null)
            {
                this.Opened(this, new EventArgs());
            }
        }
예제 #2
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();
                    }
                }
            }
        }
예제 #3
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();
                    }
                }
            }
        }