Exemplo n.º 1
0
        public ContentImporterContext(ContentProjectContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            this.context = context;
        }
        internal void Build(ContentProjectContext context)
        {
            string fileName = context.ReplaceVariables(this.FileName);
            bool exists = false;

            context.Logger.LogInfo(string.Format("Loading assembly {0}...", fileName));

            if (File.Exists(fileName))
            {
                exists = true;
            }
            else
            {
                string globalPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName);
                if (File.Exists(globalPath))
                {
                    fileName = globalPath;
                    exists = true;
                }
            }

            if (exists)
            {
                Assembly assembly = Assembly.LoadFile(Path.GetFullPath(fileName));
                context.RegisterAssembly(assembly);
            }
            else
            {
                throw new ContentProjectException(string.Format("Unable to load referenced assembly {0}.", fileName));
            }
        }
Exemplo n.º 3
0
        public void Build(ContentProjectContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            foreach (ContentProjectReferenceNode reference in this.References)
                reference.Build(context);

            foreach (ContentProjectItemNode item in this.Items)
                item.Build(context);
        }
Exemplo n.º 4
0
        internal object Build(ContentProjectContext context)
        {
            string fileName = context.ReplaceVariables(this.FileName);

            context.Logger.BeginSection(string.Format("Import: {0}", fileName));

            var importer = context.GetContentImporter(fileName);
            object content = importer.Import(fileName, new ContentImporterContext(context));

            context.Logger.EndSection();

            return content;
        }
        internal void Build(ContentProjectContext context, object content)
        {
            string name = context.ReplaceVariables(this.Name);
            Dictionary<string, string> parameters = context.ReplaceVariables(this.Parameters);

            context.Logger.BeginSection(string.Format("Processor: {0}", name));

            var processor = context.GetContentProcessor(name);

            ReflectionHelper.ApplyParameters(context, processor, parameters);

            processor.Process(content, new ContentProcessorContext(context));

            context.Logger.EndSection();
        }
Exemplo n.º 6
0
        internal void Build(ContentProjectContext context)
        {
            context.Logger.BeginSection(this.Name);

            object content = null;

            if (this.Import != null)
                content = this.Import.Build(context);

            foreach (var processor in this.Processors)
                processor.Build(context, content);

            if (this.Serialize != null)
                content = this.Serialize.Build(context, content);

            context.Logger.EndSection();
        }
Exemplo n.º 7
0
        public static void ApplyParameters(ContentProjectContext context, object obj, Dictionary<string, string> parameters)
        {
            Type objType = obj.GetType();

            foreach (var pair in parameters)
            {
                var property = objType.GetProperty(pair.Key);

                if (property != null)
                {
                    var parser = context.GetTypeParser(property.PropertyType);
                    property.SetValue(obj, parser(pair.Value));
                }
                else
                {
                    // TODO: Property doesn't exist.
                }
            }
        }
        internal object Build(ContentProjectContext context, object content)
        {
            string fileName = context.ReplaceVariables(this.FileName);
            Dictionary<string, string> parameters = context.ReplaceVariables(this.Parameters);

            context.Logger.BeginSection(string.Format("Serialize: {0}", fileName));

            var serializer = context.GetContentSerializer(content.GetType());

            ReflectionHelper.ApplyParameters(context, serializer, parameters);

            using (FileStream file = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                serializer.Serialize(content, file, new ContentSerializerContext(context));
            }

            context.Logger.EndSection();

            return content;
        }