private async void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            await this.window.RunAsyncOperation(async() =>
            {
                StoreDetailListingModel listingDetails = await ChannelSession.Services.MixItUpService.GetStoreListing(this.currentListing.ID);
                await ChannelSession.Services.MixItUpService.AddStoreListingDownload(this.currentListing);

                List <ActionBase> actions = listingDetails.GetActions();

                StoreCommandUpgrader.PerformUpgrades(actions, listingDetails.AppVersion);

                if (listingDetails.AssetsIncluded && listingDetails.AssetData != null && listingDetails.AssetData.Length > 0)
                {
                    if (await MessageBoxHelper.ShowConfirmationDialog("This command contains included assets." + Environment.NewLine + "Would you like to download them?"))
                    {
                        string folderLocation = ChannelSession.Services.FileService.ShowOpenFolderDialog();
                        if (!string.IsNullOrEmpty(folderLocation))
                        {
                            string zipFilePath = Path.Combine(ChannelSession.Services.FileService.GetTempFolder(), listingDetails.ID.ToString() + ".zip");
                            await ChannelSession.Services.FileService.SaveFileAsBytes(zipFilePath, listingDetails.AssetData);
                            await ChannelSession.Services.FileService.UnzipFiles(zipFilePath, folderLocation);

                            IEnumerable <string> assetFileNames = (await ChannelSession.Services.FileService.GetFilesInDirectory(folderLocation)).Select(s => Path.GetFileName(s));
                            foreach (ActionBase action in actions)
                            {
                                if (action.Type == ActionTypeEnum.Overlay)
                                {
                                    OverlayAction oAction = (OverlayAction)action;
                                    if (oAction.Effect is OverlayImageEffect)
                                    {
                                        OverlayImageEffect iEffect = (OverlayImageEffect)oAction.Effect;
                                        if (assetFileNames.Contains(Path.GetFileName(iEffect.FilePath)))
                                        {
                                            iEffect.FilePath = Path.Combine(folderLocation, Path.GetFileName(iEffect.FilePath));
                                        }
                                    }
                                }
                                else if (action.Type == ActionTypeEnum.Sound)
                                {
                                    SoundAction sAction = (SoundAction)action;
                                    if (assetFileNames.Contains(Path.GetFileName(sAction.FilePath)))
                                    {
                                        sAction.FilePath = Path.Combine(folderLocation, Path.GetFileName(sAction.FilePath));
                                    }
                                }
                            }
                        }
                    }
                }

                this.window.DownloadCommandFromStore(listingDetails.ID, actions);
            });
        }
        internal static void RestructureNewOverlayActions(List <ActionBase> actions)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                ActionBase action = actions[i];
                if (action is OverlayAction)
                {
                    OverlayAction oAction = (OverlayAction)action;
#pragma warning disable CS0612 // Type or member is obsolete
                    if (oAction.Effect != null)
                    {
                        if (oAction.Effect is OverlayTextEffect)
                        {
                            OverlayTextEffect effect = (OverlayTextEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayTextItem(effect.Text, effect.Color, effect.Size, string.Empty, true, false, false, string.Empty);
                        }
                        else if (oAction.Effect is OverlayImageEffect)
                        {
                            OverlayImageEffect effect = (OverlayImageEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayImageItem(effect.FilePath, effect.Width, effect.Height);
                        }
                        else if (oAction.Effect is OverlayVideoEffect)
                        {
                            OverlayVideoEffect effect = (OverlayVideoEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayVideoItem(effect.FilePath, effect.Width, effect.Height, 100);
                        }
                        else if (oAction.Effect is OverlayYoutubeEffect)
                        {
                            OverlayYoutubeEffect effect = (OverlayYoutubeEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayYouTubeItem(effect.ID, effect.StartTime, effect.Width, effect.Height, 100);
                        }
                        else if (oAction.Effect is OverlayWebPageEffect)
                        {
                            OverlayWebPageEffect effect = (OverlayWebPageEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayWebPageItem(effect.URL, effect.Width, effect.Height);
                        }
                        else if (oAction.Effect is OverlayHTMLEffect)
                        {
                            OverlayHTMLEffect effect = (OverlayHTMLEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayHTMLItem(effect.HTMLText);
                        }
                        oAction.Position = new Model.Overlay.OverlayItemPosition(Model.Overlay.OverlayEffectPositionType.Percentage, oAction.Effect.Horizontal, oAction.Effect.Vertical);
                        oAction.Effects  = new Model.Overlay.OverlayItemEffects((Model.Overlay.OverlayEffectEntranceAnimationTypeEnum)oAction.Effect.EntranceAnimation,
                                                                                (Model.Overlay.OverlayEffectVisibleAnimationTypeEnum)oAction.Effect.VisibleAnimation, (Model.Overlay.OverlayEffectExitAnimationTypeEnum)oAction.Effect.ExitAnimation,
                                                                                oAction.Effect.Duration);
                        oAction.Effect = null;
                    }
#pragma warning restore CS0612 // Type or member is obsolete
                }
            }
        }
        public override Task OnLoaded()
        {
            if (ChannelSession.Services.OverlayServer == null)
            {
                this.OverlayNotEnabledWarningTextBlock.Visibility = Visibility.Visible;
            }

            this.TypeComboBox.ItemsSource      = EnumHelper.GetEnumNames <OverlayEffectTypeEnum>();
            this.FontSizeComboBox.ItemsSource  = OverlayActionControl.sampleFontSize.Select(f => f.ToString());
            this.FontColorComboBox.ItemsSource = ColorSchemes.ColorSchemeDictionary.Keys;
            this.YoutubeStartTimeTextBox.Text  = "0";
            this.YoutubeWidthTextBox.Text      = this.VideoWidthTextBox.Text = OverlayVideoEffect.DefaultWidth.ToString();
            this.YoutubeHeightTextBox.Text     = this.VideoHeightTextBox.Text = OverlayVideoEffect.DefaultHeight.ToString();

            this.CenterPositionButton_Click(this, new RoutedEventArgs());

            this.EntranceAnimationComboBox.ItemsSource   = EnumHelper.GetEnumNames <OverlayEffectEntranceAnimationTypeEnum>();
            this.EntranceAnimationComboBox.SelectedIndex = 0;
            this.VisibleAnimationComboBox.ItemsSource    = EnumHelper.GetEnumNames <OverlayEffectVisibleAnimationTypeEnum>();
            this.VisibleAnimationComboBox.SelectedIndex  = 0;
            this.ExitAnimationComboBox.ItemsSource       = EnumHelper.GetEnumNames <OverlayEffectExitAnimationTypeEnum>();
            this.ExitAnimationComboBox.SelectedIndex     = 0;

            if (this.action != null)
            {
                if (this.action.Effect is OverlayImageEffect)
                {
                    OverlayImageEffect imageEffect = (OverlayImageEffect)this.action.Effect;
                    this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayEffectTypeEnum.Image);
                    this.ImageFilePathTextBox.Text = imageEffect.FilePath;
                    this.ImageWidthTextBox.Text    = imageEffect.Width.ToString();
                    this.ImageHeightTextBox.Text   = imageEffect.Height.ToString();
                }
                else if (this.action.Effect is OverlayTextEffect)
                {
                    OverlayTextEffect textEffect = (OverlayTextEffect)this.action.Effect;
                    this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayEffectTypeEnum.Text);
                    this.TextTextBox.Text          = textEffect.Text;
                    this.FontSizeComboBox.Text     = textEffect.Size.ToString();
                    string color = textEffect.Color;
                    if (ColorSchemes.ColorSchemeDictionary.ContainsValue(color))
                    {
                        color = ColorSchemes.ColorSchemeDictionary.FirstOrDefault(c => c.Value.Equals(color)).Key;
                    }
                    this.FontColorComboBox.Text = color;
                }
                else if (this.action.Effect is OverlayYoutubeEffect)
                {
                    OverlayYoutubeEffect youtubeEffect = (OverlayYoutubeEffect)this.action.Effect;
                    this.TypeComboBox.SelectedItem    = EnumHelper.GetEnumName(OverlayEffectTypeEnum.YouTube);
                    this.YoutubeVideoIDTextBox.Text   = youtubeEffect.ID;
                    this.YoutubeStartTimeTextBox.Text = youtubeEffect.StartTime.ToString();
                    this.YoutubeWidthTextBox.Text     = youtubeEffect.Width.ToString();
                    this.YoutubeHeightTextBox.Text    = youtubeEffect.Height.ToString();
                }
                else if (this.action.Effect is OverlayVideoEffect)
                {
                    OverlayVideoEffect videoEffect = (OverlayVideoEffect)this.action.Effect;
                    this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayEffectTypeEnum.Video);
                    this.VideoFilePathTextBox.Text = videoEffect.FilePath;
                    this.VideoWidthTextBox.Text    = videoEffect.Width.ToString();
                    this.VideoHeightTextBox.Text   = videoEffect.Height.ToString();
                }
                else if (this.action.Effect is OverlayWebPageEffect)
                {
                    OverlayWebPageEffect webPageEffect = (OverlayWebPageEffect)this.action.Effect;
                    this.TypeComboBox.SelectedItem   = EnumHelper.GetEnumName(OverlayEffectTypeEnum.WebPage);
                    this.WebPageFilePathTextBox.Text = webPageEffect.URL;
                    this.WebPageWidthTextBox.Text    = webPageEffect.Width.ToString();
                    this.WebPageHeightTextBox.Text   = webPageEffect.Height.ToString();
                }
                else if (this.action.Effect is OverlayHTMLEffect)
                {
                    OverlayHTMLEffect htmlEffect = (OverlayHTMLEffect)this.action.Effect;
                    this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayEffectTypeEnum.HTML);
                    this.HTMLTextBox.Text          = htmlEffect.HTMLText;
                }

                this.HorizontalSlider.Value = this.action.Effect.Horizontal;
                this.VerticalSlider.Value   = this.action.Effect.Vertical;

                if (this.action.Effect.Horizontal == 25 && this.action.Effect.Vertical == 25)
                {
                    this.TopLeftPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 50 && this.action.Effect.Vertical == 25)
                {
                    this.TopPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 75 && this.action.Effect.Vertical == 25)
                {
                    this.TopRightPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 25 && this.action.Effect.Vertical == 50)
                {
                    this.LeftPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 50 && this.action.Effect.Vertical == 50)
                {
                    this.CenterPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 75 && this.action.Effect.Vertical == 50)
                {
                    this.RightPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 25 && this.action.Effect.Vertical == 75)
                {
                    this.BottomLeftPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 50 && this.action.Effect.Vertical == 75)
                {
                    this.BottomPositionButton_Click(this, new RoutedEventArgs());
                }
                else if (this.action.Effect.Horizontal == 75 && this.action.Effect.Vertical == 75)
                {
                    this.BottomRightPositionButton_Click(this, new RoutedEventArgs());
                }
                else
                {
                    this.PositionSimpleAdvancedToggleButton.IsChecked = true;
                }

                this.DurationTextBox.Text = this.action.Effect.Duration.ToString();
                this.EntranceAnimationComboBox.SelectedItem = EnumHelper.GetEnumName(this.action.Effect.EntranceAnimation);
                this.VisibleAnimationComboBox.SelectedItem  = EnumHelper.GetEnumName(this.action.Effect.VisibleAnimation);
                this.ExitAnimationComboBox.SelectedItem     = EnumHelper.GetEnumName(this.action.Effect.ExitAnimation);
            }
            return(Task.FromResult(0));
        }
 public async Task SendImage(OverlayImageEffect effect)
 {
     this.httpListenerServer.SetLocalFile(effect.ID, effect.FilePath);
     await this.SendPacket("image", effect);
 }
Esempio n. 5
0
        private async void UploadButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            await this.RunAsyncOperation(async() =>
            {
                if (string.IsNullOrEmpty(this.NameTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("A name must be specified");
                    return;
                }

                if (this.NameTextBox.Text.Length >= 50)
                {
                    await MessageBoxHelper.ShowMessageDialog("A name must be 50 characters or less");
                    return;
                }

                if (string.IsNullOrEmpty(this.DescriptionTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("A description must be specified");
                    return;
                }

                if (!string.IsNullOrEmpty(this.DisplayImagePathTextBox.Text))
                {
                    if (!File.Exists(this.DisplayImagePathTextBox.Text))
                    {
                        await MessageBoxHelper.ShowMessageDialog("The specified display image does not exist");
                        return;
                    }

                    FileInfo info = new FileInfo(this.DisplayImagePathTextBox.Text);
                    if (info.Length >= 1000000)
                    {
                        await MessageBoxHelper.ShowMessageDialog("Display image must be smaller than 1 MB");
                        return;
                    }
                }

                HashSet <string> tags = new HashSet <string>();
                if (this.Tag1ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag1ComboBox.Text);
                }
                if (this.Tag2ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag2ComboBox.Text);
                }
                if (this.Tag3ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag3ComboBox.Text);
                }
                if (this.Tag4ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag4ComboBox.Text);
                }
                if (this.Tag5ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag5ComboBox.Text);
                }
                if (this.Tag6ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag6ComboBox.Text);
                }

                if (tags.Count == 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("At least 1 tag must be selected");
                    return;
                }

                JObject metadata = new JObject();

                byte[] displayImageData = null;
                if (!string.IsNullOrEmpty(this.DisplayImagePathTextBox.Text))
                {
                    displayImageData = await ChannelSession.Services.FileService.ReadFileAsBytes(this.DisplayImagePathTextBox.Text);
                }

                byte[] assetData = null;
                if (this.IncludeAssetsToggleButton.IsChecked.GetValueOrDefault())
                {
                    List <string> assetFiles = new List <string>();
                    foreach (ActionBase action in this.command.Actions)
                    {
                        if (action.Type == ActionTypeEnum.Overlay)
                        {
                            OverlayAction oAction = (OverlayAction)action;
                            if (oAction.Effect is OverlayImageEffect)
                            {
                                OverlayImageEffect iEffect = (OverlayImageEffect)oAction.Effect;
                                if (File.Exists(iEffect.FilePath))
                                {
                                    assetFiles.Add(iEffect.FilePath);
                                }
                            }
                        }
                        else if (action.Type == ActionTypeEnum.Sound)
                        {
                            SoundAction sAction = (SoundAction)action;
                            if (File.Exists(sAction.FilePath))
                            {
                                assetFiles.Add(sAction.FilePath);
                            }
                        }
                    }

                    if (assetFiles.Count > 0)
                    {
                        foreach (string assetFile in assetFiles)
                        {
                            FileInfo info = new FileInfo(assetFile);
                            if (info.Length >= 1000000)
                            {
                                await MessageBoxHelper.ShowMessageDialog("All asset files must be smaller than 1 MB");
                                return;
                            }
                        }

                        string zipFilePath = Path.Combine(ChannelSession.Services.FileService.GetTempFolder(), this.command.ID.ToString() + ".zip");
                        if (File.Exists(zipFilePath))
                        {
                            File.Delete(zipFilePath);
                        }
                        await ChannelSession.Services.FileService.ZipFiles(zipFilePath, assetFiles);
                        assetData = await ChannelSession.Services.FileService.ReadFileAsBytes(zipFilePath);
                    }
                }

                await ChannelSession.Services.MixItUpService.AddStoreListing(new StoreDetailListingModel(this.command, this.NameTextBox.Text, this.DescriptionTextBox.Text, tags,
                                                                                                         this.DisplayImagePathTextBox.Text, displayImageData, assetData, metadata));

                this.command.StoreID = this.command.ID;

                this.Close();
            });
        }