/// <summary> /// Saves the package builder data to disk. /// </summary> /// <param name="path">Path to save the fabricator information.</param> public override void Save(string path) { IA.IsolatedApp isolatedApp = new IA.IsolatedApp(); // Serialize out the package information. IA.Package package = new IA.Package(); isolatedApp.AddChild(package); if (this.description != null && this.description.Length > 0) { IA.Description description = new IA.Description(); description.Content = this.description; package.AddChild(description); } if (this.updateUrl != null) { IA.Feed feed = new IA.Feed(); feed.Content = this.updateUrl.ToString(); package.AddChild(feed); } if (this.updateRate > 0) { IA.UpdateRate updateRate = new IA.UpdateRate(); updateRate.Content = this.updateRate; package.AddChild(updateRate); } if (this.packageId != Guid.Empty) { IA.Id id = new IA.Id(); id.Content = this.packageId.ToString(); package.AddChild(id); } if (this.manufacturer != null && this.manufacturer.Length > 0) { IA.Manufacturer manufacturer = new IA.Manufacturer(); manufacturer.Content = this.manufacturer; package.AddChild(manufacturer); } if (this.appVersion != null) { IA.Version version = new IA.Version(); version.Content = this.appVersion.ToString(); package.AddChild(version); } // Serialize out the application information. IA.Application application = new IA.Application(); isolatedApp.AddChild(application); if (this.details != null && this.details.Length > 0) { IA.Details details = new IA.Details(); details.Content = this.details; application.AddChild(details); } if (this.entryPoint != null && this.entryPoint.Length > 0) { IA.EntryPoint entryPoint = new IA.EntryPoint(); entryPoint.Content = this.entryPoint; application.AddChild(entryPoint); } if (this.iconPath != null && this.iconPath.Length > 0) { IA.Icon icon = new IA.Icon(); icon.Content = this.iconPath; application.AddChild(icon); } if (this.appId != Guid.Empty) { IA.Id id = new IA.Id(); id.Content = this.appId.ToString(); application.AddChild(id); } if (this.name != null && this.name.Length > 0) { IA.Name name = new IA.Name(); name.Content = this.name; application.AddChild(name); } if (this.source != null && this.source.Length > 0) { IA.Source source = new IA.Source(); source.Content = this.source; application.AddChild(source); } // Serialize out the previous package path if there is one. if (this.previousFeedUrl != null) { IA.PreviousFeed previousFeed = new IA.PreviousFeed(); previousFeed.Content = this.previousFeedUrl.AbsoluteUri; isolatedApp.AddChild(previousFeed); } // Serialize the data to disk. using (StreamWriter sw = new StreamWriter(path)) { XmlTextWriter writer = null; try { writer = new XmlTextWriter(sw); writer.Formatting = Formatting.Indented; writer.Indentation = 4; isolatedApp.OutputXml(writer); } finally { if (writer != null) { writer.Close(); } } } }
/// <summary> /// Loads the fabricator data from disk. /// </summary> /// <param name="path">Path to load the facbricator information from.</param> public override void Open(string path) { Assembly[] assemblies = new Assembly[] { Assembly.GetExecutingAssembly() }; Wix.CodeDomReader reader = new Wix.CodeDomReader(assemblies); IA.IsolatedApp isolatedApp = reader.Load(path) as IA.IsolatedApp; if (null == isolatedApp) { throw new ApplicationException("Failed to load isolated app data file."); } this.description = null; this.packageId = Guid.Empty; this.manufacturer = null; this.appId = Guid.Empty; this.appVersion = null; this.updateUrl = null; this.details = null; this.name = null; this.source = null; this.entryPoint = null; this.iconPath = null; this.previousFeedUrl = null; foreach (Wix.ISchemaElement child in isolatedApp.Children) { if (child is IA.Package) { foreach (Wix.ISchemaElement grandchild in ((IA.Package)child).Children) { if (grandchild is IA.Description) { this.description = ((IA.Description)grandchild).Content; } else if (grandchild is IA.Feed) { if (((IA.Feed)grandchild).Content != null) { this.updateUrl = new Uri(((IA.Feed)grandchild).Content); } } else if (grandchild is IA.UpdateRate) { if (((IA.UpdateRate)grandchild).Content != 0) { this.updateRate = Convert.ToInt32(((IA.UpdateRate)grandchild).Content); } } else if (grandchild is IA.Icon) { } else if (grandchild is IA.Id) { if (((IA.Id)grandchild).Content != null) { this.packageId = new Guid(((IA.Id)grandchild).Content); } } else if (grandchild is IA.Manufacturer) { this.manufacturer = ((IA.Manufacturer)grandchild).Content; } else if (grandchild is IA.Version) { if (((IA.Version)grandchild).Content != null) { this.appVersion = new Version(((IA.Version)grandchild).Content); } } } } else if (child is IA.Application) { foreach (Wix.ISchemaElement grandchild in ((IA.Application)child).Children) { if (grandchild is IA.Details) { this.details = ((IA.Details)grandchild).Content; } else if (grandchild is IA.EntryPoint) { this.entryPoint = ((IA.EntryPoint)grandchild).Content; } else if (grandchild is IA.Icon) { this.iconPath = ((IA.Icon)grandchild).Content; } else if (grandchild is IA.Id) { this.appId = new Guid(((IA.Id)grandchild).Content); } else if (grandchild is IA.Name) { this.name = ((IA.Name)grandchild).Content; } else if (grandchild is IA.Source) { if (((IA.Source)grandchild).Content != null) { string expandedSource = System.Environment.ExpandEnvironmentVariables(((IA.Source)grandchild).Content); this.source = Path.GetFullPath(expandedSource); } } } } else if (child is IA.PreviousFeed) { if (((IA.PreviousFeed)child).Content != null) { string expandedUrl = System.Environment.ExpandEnvironmentVariables(((IA.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()); } }