示例#1
0
        /// <summary>
        /// Parse Dream XML definition file
        /// </summary>
        private void ParseDreamDefinition()
        {
            // Read data
            var configuration = new DreamConfiguration();

            string buffer = ReplaceDefines(File.ReadAllText(inputFile));

            try
            {
                configuration.Load(buffer);
            } catch (Exception e) {
                OutputError("Error loading configuration file", null, e);
            }

            DreamConfig dream = configuration.Config;

            name        = dream.name;
            description = dream.description;
            author      = dream.author;
            url         = dream.url;
            preview     = LoadPreview(dream.preview);

            copyright   = dream.copyright;
            permissions = dream.permissions;

            // Check that name is valid as a filename
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("Checking dream output name...");
            CheckForInvalidChars(name);
            Console.Write("\t[OK]\n");
            Console.ResetColor();

            Console.WriteLine("");
            switch (configuration.Type)
            {
            case DreamType.Video:
                LoadVideoDream(dream.data.video);
                break;

            case DreamType.Trigger:
                LoadTriggersDream(dream.data.triggers);
                break;

            case DreamType.Dynamic:
                LoadDynamicDream(dream.data.dynamic);
                break;

            case DreamType.Invalid:
                OutputError("Invalid dream!", "The Dream configuration file is invalid", null);
                break;
            }
        }
示例#2
0
        /// <summary>
        /// Load data for a trigger based dream
        /// </summary>
        /// <param name="triggers">a list of Trigger structures</param>
        private void LoadTriggersDream(DreamTriggers triggers)
        {
            Console.WriteLine("Building a trigger-based Dream\n");

            Debug.Assert(triggers.type == "time");

            if (triggers.type == "time")
            {
                Console.WriteLine("Trigger is time-based.\n");
            }

            string triggersDefinition = Path.Combine(buildDir, "DreamTriggers.xml");

            AddContent(triggersDefinition);

            var triggersV1 = new TriggersV1
            {
                version     = 100,
                fileVersion = "1.0",
                triggers    = new TriggerSetV1
                {
                    triggers =
                        new List <TriggerV1>(),
                    type = triggers.type
                }
            };

            // Process the list of triggers
            //   - Check for duplicates
            //		+ triggers that start at the same time
            //		The case where there is only two triggers, but with the same file is not handled
            //   - Check & copy the files
            //   - Build the DreamTriggersV1 structure
            int id       = 1;
            var timeList = new List <DateTime>();
            var fileList = new List <string>();

            foreach (DreamTrigger trigger in triggers.triggers)
            {
                // Check unique time
                if (!timeList.Contains(trigger.time))
                {
                    timeList.Add(trigger.time);
                }
                else
                {
                    OutputError("Another trigger is set to start at the same time", "Time: " + trigger.time + " - file: " + trigger.file, null);
                }

                // Check that video is not already included
                if (!fileList.Contains(trigger.file))
                {
                    fileList.Add(trigger.file);
                    AddContent(LoadAndCheckFile(trigger.file, buildDir, MAX_VIDEOSIZE, FILTER_VIDEO));
                }

                // Add trigger
                var triggerV1 = new TriggerV1
                {
                    id     = id,
                    video  = Path.GetFileName(trigger.file),
                    hour   = trigger.time.Hour,
                    minute = trigger.time.Minute,
                    second = trigger.time.Second
                };

                triggersV1.triggers.triggers.Add(triggerV1);

                Console.WriteLine("  Adding trigger: " + triggerV1.video + " at " + trigger.time.Hour + ":" + trigger.time.Minute + ":" + trigger.time.Second);

                id++;
            }

            // Check that there are at least two unique videos
            if (fileList.Count < 2)
            {
                OutputError("At least two different videos are needed for trigger-based dreams", "Dream configuration uses only one video in the trigger section", null);
            }

            // Output a trigger config file
            DreamConfiguration.Serialize(triggersV1, triggersDefinition);

            // Check that the file is in the correct format
            DreamConfiguration.ValidateConfiguration(new StringReader(File.ReadAllText(Path.Combine(buildDir, "DreamTriggers.xml"))), Resources.TriggersV1XSD);
        }