Exemple #1
0
 private static IComponentScanner GetPipelineScanner(string xnaFrameworkVersion)
 {
     if (string.IsNullOrEmpty(xnaFrameworkVersion))
     {
         XBuilderWindowPane.WriteLine(Resources.PipelineAddInMissingVersionProperty, new object[0]);
     }
     else
     {
         string pipelineAddInRootPath = GetPipelineAddInRootPath();
         if (!string.IsNullOrEmpty(pipelineAddInRootPath))
         {
             try
             {
                 foreach (AddInToken token in AddInStore.FindAddIns(typeof(IComponentScanner), pipelineAddInRootPath, new string[0]))
                 {
                     string addInFrameworkVersion;
                     if (token.QualificationData[AddInSegmentType.AddIn].TryGetValue("XnaFrameworkVersion", out addInFrameworkVersion) &&
                         addInFrameworkVersion != null && addInFrameworkVersion == xnaFrameworkVersion)
                     {
                         try
                         {
                             return(token.Activate <IComponentScanner>(AppDomain.CurrentDomain));
                         }
                         catch (TargetInvocationException exception)
                         {
                             string message = string.Empty;
                             if (exception.InnerException != null)
                             {
                                 message = exception.InnerException.Message;
                             }
                             XBuilderWindowPane.WriteLine(
                                 "An error occurred while instantiating the content pipeline component scanner for version '{0}': {1}",
                                 new object[] { xnaFrameworkVersion, message });
                             continue;
                         }
                     }
                 }
                 XBuilderWindowPane.WriteLine(
                     "XNA Framework version '{0}' is not supported by this installation of XNA Game Studio, or a required component is missing.",
                     new object[] { xnaFrameworkVersion });
             }
             catch (InvalidOperationException ex)
             {
                 XBuilderWindowPane.WriteLine(Resources.PipelineAddInInvalidPipeline, new object[] { ex.Message });
             }
             catch (DirectoryNotFoundException ex)
             {
                 XBuilderWindowPane.WriteLine(Resources.PipelineAddInInvalidPipeline, new object[] { ex.Message });
             }
             catch (InvalidPipelineStoreException ex)
             {
                 XBuilderWindowPane.WriteLine(Resources.PipelineAddInInvalidPipeline, new object[] { ex.Message });
             }
         }
     }
     return(null);
 }
Exemple #2
0
        private void UpdatePipelineComponentScanner()
        {
            if (!_needsRefresh || (_pipelineScanner == null))
            {
                return;
            }

            _pipelineScanner.Scan(_referencedAssemblies, new string[0]);
            foreach (string str in _pipelineScanner.Errors)
            {
                XBuilderWindowPane.WriteLine(str, new object[0]);
            }
            _needsRefresh = false;
        }
        /// <summary>
        /// Loads a new XNA asset file into the ModelViewerControl.
        /// </summary>
        public AssetType LoadFile(string fileName, XnaBuildProperties buildProperties)
        {
            if (!_loaded)
            {
                return(AssetType.None);
            }

            // Unload any existing content.
            graphicsDeviceControl.AssetRenderer = null;
            AssetHandler assetHandler = _assetHandlers.GetAssetHandler(fileName);

            assetHandler.ResetRenderer();

            windowsFormsHost.Visibility = Visibility.Collapsed;
            txtInfo.Text       = "Loading...";
            txtInfo.Visibility = Visibility.Visible;

            // Load asynchronously.
            var           ui       = TaskScheduler.FromCurrentSynchronizationContext();
            Task <string> loadTask = new Task <string>(() =>
            {
                _contentManager.Unload();

                // Tell the ContentBuilder what to build.
                _contentBuilder.Clear();
                _contentBuilder.SetReferences(buildProperties.ProjectReferences);

                string assetName = fileName;
                foreach (char c in Path.GetInvalidFileNameChars())
                {
                    assetName = assetName.Replace(c.ToString(), string.Empty);
                }
                assetName = Path.GetFileNameWithoutExtension(assetName);
                _contentBuilder.Add(fileName, assetName, buildProperties.Importer,
                                    buildProperties.Processor ?? assetHandler.ProcessorName,
                                    buildProperties.ProcessorParameters);

                // Build this new model data.
                string buildErrorInternal = _contentBuilder.Build();

                if (string.IsNullOrEmpty(buildErrorInternal))
                {
                    // If the build succeeded, use the ContentManager to
                    // load the temporary .xnb file that we just created.
                    assetHandler.LoadContent(assetName);

                    graphicsDeviceControl.AssetRenderer = assetHandler.Renderer;
                }

                return(buildErrorInternal);
            });

            loadTask.ContinueWith(t =>
            {
                string buildError = t.Result;
                if (!string.IsNullOrEmpty(buildError))
                {
                    // If the build failed, display an error message.
                    txtInfo.Text = "Uh-oh. Something went wrong. Check the Output window for details.";
                    XBuilderWindowPane.WriteLine(buildError);
                }
                else
                {
                    windowsFormsHost.Visibility = Visibility.Visible;
                    txtInfo.Visibility          = Visibility.Hidden;
                }
            }, ui);

            loadTask.Start();

            return(_assetHandlers.GetAssetType(fileName));
        }