public static AssetLogMessage From(Package package, IReference assetReference, ILogMessage logMessage, string assetPath, int line = 0, int character = 0)
        {
            // Transform to AssetLogMessage
            var assetLogMessage = logMessage as AssetLogMessage;
            if (assetLogMessage == null)
            {
                assetLogMessage = new AssetLogMessage(null, assetReference, logMessage.Type, AssetMessageCode.CompilationMessage, assetReference?.Location, logMessage.Text)
                {
                    Exception = (logMessage as LogMessage)?.Exception
                };
            }

            // Set file (and location if available)
            assetLogMessage.File = assetPath;
            assetLogMessage.Line = line;
            assetLogMessage.Character = character;

            // Generate location (if it's a Yaml exception)
            var yamlException = (logMessage as LogMessage)?.Exception as YamlException;
            if (yamlException != null)
            {
                assetLogMessage.Line = yamlException.Start.Line;
                assetLogMessage.Character = yamlException.Start.Column;
                // We've already got everything, no need to pollute log with stack trace of exception
                assetLogMessage.Exception = null;
            }

            return assetLogMessage;
        }
示例#2
0
        public static AssetLogMessage From(Package package, IReference assetReference, ILogMessage logMessage, string assetPath, int line = 0, int character = 0)
        {
            // Transform to AssetLogMessage
            var assetLogMessage = logMessage as AssetLogMessage;

            if (assetLogMessage == null)
            {
                assetLogMessage = new AssetLogMessage(null, assetReference, logMessage.Type, AssetMessageCode.CompilationMessage, assetReference?.Location, logMessage.Text)
                {
                    Exception = (logMessage as LogMessage)?.Exception
                };
            }

            // Set file (and location if available)
            assetLogMessage.File      = assetPath;
            assetLogMessage.Line      = line;
            assetLogMessage.Character = character;

            // Generate location (if it's a Yaml exception)
            var yamlException = (logMessage as LogMessage)?.Exception as YamlException;

            if (yamlException != null)
            {
                assetLogMessage.Line      = yamlException.Start.Line;
                assetLogMessage.Character = yamlException.Start.Column;
                // We've already got everything, no need to pollute log with stack trace of exception
                assetLogMessage.Exception = null;
            }

            return(assetLogMessage);
        }
示例#3
0
 public AssetSerializableLogMessage(AssetLogMessage logMessage)
     : base(logMessage)
 {
     if (logMessage.AssetReference != null)
     {
         AssetId  = logMessage.AssetReference.Id;
         AssetUrl = logMessage.AssetReference.Location;
     }
 }
 public static void Warning(this ILogger logger, Package package, IReference assetReference, AssetMessageCode code, IEnumerable<IReference> relatedGuids, params object[] arguments)
 {
     var logMessage = new AssetLogMessage(package, assetReference, LogMessageType.Warning, code, arguments);
     if (relatedGuids != null)
     {
         logMessage.Related.AddRange(relatedGuids);
     }
     logger.Log(logMessage);
 }
 public static void Error(this ILogger logger, Package package, IReference assetReference, AssetMessageCode code, IEnumerable<IReference> relatedGuids, Exception exception = null)
 {
     var logMessage = new AssetLogMessage(package, assetReference, LogMessageType.Error, code) { Exception = exception };
     if (relatedGuids != null)
     {
         logMessage.Related.AddRange(relatedGuids);
     }
     logger.Log(logMessage);
 }
 public AssetSerializableLogMessage(AssetLogMessage logMessage)
     : base(logMessage)
 {
     if (logMessage.AssetReference != null)
     {
         AssetId = logMessage.AssetReference.Id;
         AssetUrl = logMessage.AssetReference.Location;
     }
 }
        public static void Warning(this ILogger logger, Package package, IContentReference assetReference, AssetMessageCode code, IEnumerable <IContentReference> relatedGuids, params object[] arguments)
        {
            var logMessage = new AssetLogMessage(package, assetReference, LogMessageType.Warning, code, arguments);

            if (relatedGuids != null)
            {
                logMessage.Related.AddRange(relatedGuids);
            }
            logger.Log(logMessage);
        }
        public static void Error(this ILogger logger, Package package, IContentReference assetReference, AssetMessageCode code, IEnumerable <IContentReference> relatedGuids, Exception exception = null)
        {
            var logMessage = new AssetLogMessage(package, assetReference, LogMessageType.Error, code)
            {
                Exception = exception
            };

            if (relatedGuids != null)
            {
                logMessage.Related.AddRange(relatedGuids);
            }
            logger.Log(logMessage);
        }
示例#9
0
 private void BuildStepProcessed(object sender, BuildStepEventArgs e)
 {
     var assetItem = (AssetItem)e.Step.Tag;
     var assetRef = assetItem.ToReference();
     var project = assetItem.Package;
     var stepLogger = e.Logger is BuildStepLogger ? ((BuildStepLogger)e.Logger).StepLogger : null;
     if (stepLogger != null)
     {
         foreach (var message in stepLogger.Messages.Where(x => x.LogMessage.IsAtLeast(LogMessageType.Warning)))
         {
             var assetMessage = new AssetLogMessage(project, assetRef, message.LogMessage.Type, AssetMessageCode.CompilationMessage, assetRef.Location, message.LogMessage.Text)
             {
                 Exception = message.LogMessage is LogMessage ? ((LogMessage)message.LogMessage).Exception : null
             };
             builderOptions.Logger.Log(assetMessage);
         }
     }
     switch (e.Step.Status)
     {
         // This case should never happen
         case ResultStatus.NotProcessed:
             builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Fatal, AssetMessageCode.InternalCompilerError, assetRef.Location));
             break;
         case ResultStatus.Successful:
             builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Verbose, AssetMessageCode.CompilationSucceeded, assetRef.Location));
             break;
         case ResultStatus.Failed:
             builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Error, AssetMessageCode.CompilationFailed, assetRef.Location));
             break;
         case ResultStatus.Cancelled:
             builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Verbose, AssetMessageCode.CompilationCancelled, assetRef.Location));
             break;
         case ResultStatus.NotTriggeredWasSuccessful:
             builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Verbose, AssetMessageCode.AssetUpToDate, assetRef.Location));
             break;
         case ResultStatus.NotTriggeredPrerequisiteFailed:
             builderOptions.Logger.Log(new AssetLogMessage(project, assetRef, LogMessageType.Error, AssetMessageCode.PrerequisiteFailed, assetRef.Location));
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     e.Step.StepProcessed -= BuildStepProcessed;
 }
示例#10
0
        /// <summary>
        /// Compile the required build step necessary to produce the desired output item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="compilationResult">The compilation result.</param>
        /// <param name="assetItem">The asset item.</param>
        protected ListBuildStep CompileItem(CompilerContext context, AssetCompilerResult compilationResult, AssetItem assetItem)
        {
            // First try to find an asset compiler for this particular asset.
            IAssetCompiler compiler;
            try
            {
                compiler = compilerRegistry.GetCompiler(assetItem.Asset.GetType());
            }
            catch (Exception ex)
            {
                compilationResult.Error("Cannot find a compiler for asset [{0}] from path [{1}]", ex, assetItem.Id,
                    assetItem.Location);
                return null;
            }

            if (compiler == null)
            {
                return null;
            }

            // Second we are compiling the asset (generating a build step)
            try
            {
                var resultPerAssetType = compiler.Compile(context, assetItem);

                // Raise the AssetCompiled event.
                var handler = AssetCompiled;
                if (handler != null)
                    handler(this, new AssetCompiledArgs(assetItem, resultPerAssetType));

                // TODO: See if this can be unified with PackageBuilder.BuildStepProcessed
                foreach (var message in resultPerAssetType.Messages)
                {
                    var assetMessage = new AssetLogMessage(null, assetItem.ToReference(), message.Type, AssetMessageCode.CompilationMessage, assetItem.Location, message.Text)
                    {
                        Exception = message is LogMessage ? ((LogMessage)message).Exception : null
                    };
                    // Forward log messages to compilationResult
                    compilationResult.Log(assetMessage);

                    // Forward log messages to build step logger
                    resultPerAssetType.BuildSteps.Logger.Log(assetMessage);
                }

                // Make the build step fail if there was an error during compiling (only when we are compiling the build steps of an asset)
                if (resultPerAssetType.BuildSteps is AssetBuildStep && resultPerAssetType.BuildSteps.Logger.HasErrors)
                    resultPerAssetType.BuildSteps.Add(new CommandBuildStep(new FailedCommand(assetItem.Location)));

                // Build the module string
                var assetAbsolutePath = assetItem.FullPath;
                assetAbsolutePath = Path.GetFullPath(assetAbsolutePath);
                var module = string.Format("{0}(1,1)", assetAbsolutePath);

                // Assign module string to all command build steps
                SetModule(resultPerAssetType.BuildSteps, module);

                // Add a wait command to the build steps if required by the item build
                if (resultPerAssetType.ShouldWaitForPreviousBuilds)
                    compilationResult.BuildSteps.Add(new WaitBuildStep());

                foreach (var buildStep in resultPerAssetType.BuildSteps)
                {
                    buildStep.Priority = latestPriority++;
                }

                // Add the item result build steps the item list result build steps 
                return resultPerAssetType.BuildSteps;
            }
            catch (Exception ex)
            {
                compilationResult.Error("Unexpected exception while compiling asset [{0}] from path [{1}]", ex, assetItem.Id,
                    assetItem.Location);
                return null;
            }
        }
示例#11
0
        /// <summary>
        /// Validates the inheritance of an asset by checking base accessibility up to the root base.
        /// </summary>
        /// <param name="assetItem">The asset item.</param>
        /// <param name="log">The log to output the result of the analysis.</param>
        /// <returns>A list of all the base in bottom-up order.</returns>
        /// <exception cref="System.ArgumentNullException">asset
        /// or
        /// log</exception>
        public List<Asset> ValidateAssetBase(AssetItem assetItem, ILogger log)
        {
            if (assetItem == null) throw new ArgumentNullException("asset");
            if (log == null) throw new ArgumentNullException("log");

            var baseItems = new List<Asset>();

            // 1) Check that item is actually in the package and is the same instance
            var assetItemFound = Session.FindAsset(assetItem.Id);
            if (!ReferenceEquals(assetItem.Asset, assetItemFound.Asset))
            {
                var assetReference = assetItem.ToReference();
                log.Error(assetItem.Package, assetReference, AssetMessageCode.AssetNotFound, assetReference);
                return baseItems;
            }

            // 2) Iterate on each base and perform validation
            var currentAsset = assetItem;
            while (currentAsset.Asset.Base != null)
            {
                // 2.1) Check that asset has not been already processed
                if (baseItems.Contains(currentAsset.Asset))
                {
                    // Else this is a circular reference
                    log.Error(assetItem.Package, currentAsset.ToReference(), AssetMessageCode.InvalidCircularReferences, baseItems.Select(item => item.Id));
                    break;
                }

                // TODO: here we need to add a deep-scan of each base (including the root) for any embedded assets that are 
                // 

                // 2.2) Check that base asset is existing
                var baseAssetItem = Session.FindAsset(currentAsset.Asset.Base.Id);
                if (baseAssetItem == null)
                {
                    AssetLogMessage error;

                    // If an asset with the same location is registered
                    // Add this asset as a reference in the error message
                    var newBaseAsset = Session.FindAsset(currentAsset.Asset.Base.Location);
                    if (newBaseAsset != null)
                    {
                        // If asset location exist, log a message with the new location, but don't perform any automatic fix
                        error = new AssetLogMessage(currentAsset.Package, currentAsset.ToReference(), LogMessageType.Error, AssetMessageCode.BaseChanged, currentAsset.Asset.Base.Location);
                        error.Related.Add(newBaseAsset.ToReference());
                    }
                    else
                    {
                        // Base was not found. The base asset has been removed.
                        error = new AssetLogMessage(currentAsset.Package, currentAsset.ToReference(), LogMessageType.Error, AssetMessageCode.BaseNotFound);
                    }

                    // Set the member to Base.
                    error.Member = TypeDescriptorFactory.Default.Find(typeof(Asset))["Base"];

                    // Log the error
                    log.Log(error);
                    break;
                }
                else
                {
                    if (baseAssetItem.GetType() != assetItem.Asset.GetType())
                    {
                        log.Error(currentAsset.Package, currentAsset.ToReference(), AssetMessageCode.BaseInvalidType, baseAssetItem.GetType(), assetItem.Asset.GetType());
                    }
                }

                currentAsset = baseAssetItem;
                baseItems.Add(currentAsset.Asset);
            }
            return baseItems;
        }