Ejemplo n.º 1
0
        public void AddItem()
        {
            var ret = new SoundItemViewModel();

            Items.Add(ret);
            SelectedItem = ret;
        }
        public SoundItemEditorControl(SoundItemViewModel item)
        {
            this.item = item;

            InitializeComponent();

            this.DataContext = this.item;
        }
        private async Task SaveHTMLFiles()
        {
            string htmlFileContents = string.Empty;

            using (StreamReader reader = new StreamReader(File.OpenRead(CDKProjectViewModel.TemplateIndexHTMLFilePath)))
            {
                htmlFileContents = await reader.ReadToEndAsync();
            }

            using (StreamWriter writer = new StreamWriter(File.Open(this.IndexHTMLFilePath, FileMode.Create)))
            {
                await writer.WriteAsync(htmlFileContents);
            }

            string scriptFileContents = string.Empty;

            using (StreamReader reader = new StreamReader(File.OpenRead(CDKProjectViewModel.TemplateScriptJSFilePath)))
            {
                scriptFileContents = await reader.ReadToEndAsync();
            }

            StringBuilder definedItems = new StringBuilder();

            definedItems.AppendLine();
            definedItems.AppendLine();
            definedItems.AppendLine("function initializeItems()");
            definedItems.AppendLine("{");
            foreach (SceneViewModel scene in this.Scenes)
            {
                foreach (ItemViewModel item in scene.Items)
                {
                    definedItems.Append("\t");
                    if (item is TextItemViewModel)
                    {
                        TextItemViewModel textItem = (TextItemViewModel)item;
                        definedItems.Append("addText(\"" + item.Name + "\", \"" + scene.Name + "\", \"" + textItem.Text + "\", " + textItem.Size + ", \"" + textItem.Color.ToLower() + "\", \"" + textItem.Font + "\", " + item.XPosition + ", " + item.YPosition + ", " + item.IsVisible.ToString().ToLower() + ", " + item.IsInteractive.ToString().ToLower() + ");");
                    }
                    else if (item is ImageItemViewModel)
                    {
                        ImageItemViewModel imageItem = (ImageItemViewModel)item;
                        definedItems.Append("addImage(\"" + item.Name + "\", \"" + scene.Name + "\", \"" + Path.GetFileName(imageItem.SourcePath) + "\", " + imageItem.Width + ", " + imageItem.Height + ", " + item.XPosition + ", " + item.YPosition + ", " + item.IsVisible.ToString().ToLower() + ", " + item.IsInteractive.ToString().ToLower() + ");");
                        if (File.Exists(imageItem.SourcePath))
                        {
                            File.Copy(imageItem.SourcePath, Path.Combine(this.SourceFolderPath, Path.GetFileName(imageItem.SourcePath)), overwrite: true);
                        }
                    }
                    else if (item is SoundItemViewModel)
                    {
                        SoundItemViewModel soundItem = (SoundItemViewModel)item;
                        if (File.Exists(soundItem.SourcePath))
                        {
                            File.Copy(soundItem.SourcePath, Path.Combine(this.SourceFolderPath, Path.GetFileName(soundItem.SourcePath)), overwrite: true);
                        }
                    }
                    else if (item is VideoItemViewModel)
                    {
                        VideoItemViewModel videoItem = (VideoItemViewModel)item;
                        string             filename  = Path.GetFileName(videoItem.SourcePath);
                        definedItems.Append("videoProperties[\"" + filename + "\"] = { x: " + item.XPosition + ", y: " + item.YPosition + ", width: " + videoItem.Width + ", height: " + videoItem.Height + " };");
                        if (File.Exists(videoItem.SourcePath))
                        {
                            File.Copy(videoItem.SourcePath, Path.Combine(this.SourceFolderPath, filename), overwrite: true);
                        }
                    }
                    definedItems.AppendLine();
                }
            }
            definedItems.AppendLine("}");

            using (StreamWriter writer = new StreamWriter(File.Open(this.ScriptJSFilePath, FileMode.Create)))
            {
                await writer.WriteAsync(scriptFileContents);

                await writer.WriteAsync(definedItems.ToString());
            }
        }