private void ResolveTypes() { PipelineTypes.Load(_project); foreach (var i in _project.ContentItems) { i.Observer = this; i.ResolveTypes(); } View.UpdateProperties(); LoadTemplates(Path.Combine(_project.Location, "MGTemplates")); }
private void ResolveTypes() { PipelineTypes.Load(_project); foreach (var i in _project.ContentItems) { i.Observer = this; i.ResolveTypes(); View.UpdateProperties(i); } LoadTemplates(_project.Location); }
public void NewProject() { // Make sure we give the user a chance to // save the project if they need too. if (!AskSaveProject()) { return; } // A project needs a root directory or it is impossible to resolve relative paths. // So we need the user to choose that location even though the project has not // yet actually been saved to disk. var projectFilePath = Environment.CurrentDirectory; if (!View.AskSaveName(ref projectFilePath, "New Project")) { return; } CloseProject(); if (OnProjectLoading != null) { OnProjectLoading(); } // Clear existing project data, initialize to a new blank project. _actionStack.Clear(); _project = new PipelineProject(); PipelineTypes.Load(_project); // Save the new project. _project.OriginalPath = projectFilePath; ProjectOpen = true; ProjectDirty = true; UpdateTree(); if (OnProjectLoaded != null) { OnProjectLoaded(); } UpdateMenu(); }
public void ResolveTypes() { if (BuildAction == BuildAction.Copy) { // Copy items do not have importers or processors. _importer = PipelineTypes.NullImporter; _processor = PipelineTypes.NullProcessor; } else { _importer = PipelineTypes.FindImporter(ImporterName, System.IO.Path.GetExtension(OriginalPath)); if (_importer != null && (string.IsNullOrEmpty(ImporterName) || ImporterName != _importer.TypeName)) { ImporterName = _importer.TypeName; } if (_importer == null) { _importer = PipelineTypes.MissingImporter; } _processor = PipelineTypes.FindProcessor(ProcessorName, _importer); if (_processor != null && (string.IsNullOrEmpty(ProcessorName) || ProcessorName != _processor.TypeName)) { ProcessorName = _processor.TypeName; } if (_processor == null) { _processor = PipelineTypes.MissingProcessor; } // ProcessorParams get deserialized as strings // this code converts them to object(s) of their actual type // so that the correct editor appears within the property grid. foreach (var p in _processor.Properties) { if (!ProcessorParams.ContainsKey(p.Name)) { ProcessorParams[p.Name] = p.DefaultValue; } else { var src = ProcessorParams[p.Name]; if (src != null) { var srcType = src.GetType(); var converter = PipelineTypes.FindConverter(p.Type); // Should we throw an exception here? // This property will actually not be editable in the property grid // since we do not have a type converter for it. if (converter.CanConvertFrom(srcType)) { var dst = converter.ConvertFrom(null, CultureInfo.InvariantCulture, src); ProcessorParams[p.Name] = dst; } } } } } }
public void SaveProject(TextWriter io, Func <ContentItem, bool> filterItem) { const string lineFormat = "/{0}:{1}"; const string processorParamFormat = "{0}={1}"; string line; line = FormatDivider("Global Properties"); io.WriteLine(line); line = string.Format(lineFormat, "outputDir", _project.OutputDir); io.WriteLine(line); line = string.Format(lineFormat, "intermediateDir", _project.IntermediateDir); io.WriteLine(line); line = string.Format(lineFormat, "platform", _project.Platform); io.WriteLine(line); line = string.Format(lineFormat, "config", _project.Config); io.WriteLine(line); line = string.Format(lineFormat, "profile", _project.Profile); io.WriteLine(line); line = string.Format(lineFormat, "compress", _project.Compress); io.WriteLine(line); if (_project.LaunchDebugger) { io.WriteLine("/launchdebugger"); } line = FormatDivider("References"); io.WriteLine(line); foreach (var i in _project.References) { line = string.Format(lineFormat, "reference", i); io.WriteLine(line); } line = FormatDivider("Content"); io.WriteLine(line); // Sort the items alphabetically to ensure a consistent output // and better mergability of the resulting MGCB file. var sortedItems = _project.ContentItems.OrderBy(c => c.OriginalPath, StringComparer.InvariantCulture); foreach (var i in sortedItems) { // Reject any items that don't pass the filter. if (filterItem != null && filterItem(i)) { continue; } // Wrap content item lines with a begin comment line // to make them more cohesive (for version control). line = string.Format("#begin {0}", i.OriginalPath); io.WriteLine(line); if (i.BuildAction == BuildAction.Copy) { string path = i.OriginalPath; if (i.OriginalPath != i.DestinationPath) { path += ";" + i.DestinationPath; } line = string.Format(lineFormat, "copy", path); io.WriteLine(line); io.WriteLine(); } else { // Write importer. { line = string.Format(lineFormat, "importer", i.ImporterName); io.WriteLine(line); } // Write processor. { line = string.Format(lineFormat, "processor", i.ProcessorName); io.WriteLine(line); } // Write processor parameters. { if (i.Processor == PipelineTypes.MissingProcessor) { // Could still be missing the real processor. // If so, write the string parameters from import. foreach (var j in i.ProcessorParams) { line = string.Format(lineFormat, "processorParam", string.Format(processorParamFormat, j.Key, j.Value)); io.WriteLine(line); } } else { // Otherwise, write only values which are defined by the real processor. foreach (var j in i.Processor.Properties) { object value = null; if (i.ProcessorParams.ContainsKey(j.Name)) { value = i.ProcessorParams[j.Name]; } // JCF: I 'think' writting an empty string for null would be appropriate but to be on the safe side // im just not writting the value at all. if (value != null) { var converter = PipelineTypes.FindConverter(value.GetType()); var valueStr = converter.ConvertTo(null, CultureInfo.InvariantCulture, value, typeof(string)); line = string.Format(lineFormat, "processorParam", string.Format(processorParamFormat, j.Name, valueStr)); io.WriteLine(line); } } } } string buildValue = i.OriginalPath; if (i.OriginalPath != i.DestinationPath) { buildValue += ";" + i.DestinationPath; } line = string.Format(lineFormat, "build", buildValue); io.WriteLine(line); io.WriteLine(); } } }