예제 #1
0
        private async Task <StreamlabsChatBotData> GatherStreamlabsChatBotSettings(string filePath)
        {
            try
            {
                StreamlabsChatBotData data = new StreamlabsChatBotData();
                await Task.Run(() =>
                {
                    using (NetOffice.ExcelApi.Application application = new NetOffice.ExcelApi.Application())
                    {
                        application.DisplayAlerts = false;

                        NetOffice.ExcelApi.Workbook workbook = application.Workbooks.Open(filePath);
                        if (workbook != null)
                        {
                            foreach (NetOffice.ExcelApi.Worksheet worksheet in workbook.Worksheets.AsEnumerable())
                            {
                                if (worksheet != null)
                                {
                                    List <List <string> > dataValues = new List <List <string> >();

                                    int totalColumns = 0;
                                    bool hasValue    = false;
                                    do
                                    {
                                        hasValue = false;
                                        NetOffice.ExcelApi.Range range = worksheet.Cells[1, totalColumns + 1];
                                        if (range.Value != null)
                                        {
                                            totalColumns++;
                                            hasValue = true;
                                        }
                                    } while (hasValue);

                                    int currentRow       = 2;
                                    List <string> values = new List <string>();
                                    do
                                    {
                                        values = new List <string>();
                                        for (int i = 1; i <= totalColumns; i++)
                                        {
                                            NetOffice.ExcelApi.Range range = worksheet.Cells[currentRow, i];
                                            if (range.Value != null)
                                            {
                                                values.Add(range.Value.ToString());
                                            }
                                            else
                                            {
                                                values.Add(string.Empty);
                                            }
                                        }

                                        if (!values.All(v => string.IsNullOrEmpty(v)))
                                        {
                                            dataValues.Add(values);
                                        }
                                        currentRow++;
                                    } while (!values.All(v => string.IsNullOrEmpty(v)));

                                    if (worksheet.Name.Equals("Commands"))
                                    {
                                        data.AddCommands(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Timers"))
                                    {
                                        data.AddTimers(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Quotes") || worksheet.Name.Equals("Extra Quotes"))
                                    {
                                        data.AddQuotes(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Ranks"))
                                    {
                                        data.AddRanks(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Currency"))
                                    {
                                        data.AddViewers(dataValues);
                                    }
                                    else if (worksheet.Name.Equals("Events"))
                                    {
                                        data.AddEvents(dataValues);
                                    }
                                }
                            }
                        }
                        application.Quit();
                    }
                });

                return(data);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            return(null);
        }
예제 #2
0
        private async void NextButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            await this.RunAsyncOperation(async() =>
            {
                if (this.IntroPageGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    this.BackButton.IsEnabled        = true;
                    this.IntroPageGrid.Visibility    = System.Windows.Visibility.Collapsed;
                    this.BotLoginPageGrid.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.BotLoginPageGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    this.BotLoginPageGrid.Visibility         = System.Windows.Visibility.Collapsed;
                    this.ExternalServicesPageGrid.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.ExternalServicesPageGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    this.ExternalServicesPageGrid.Visibility       = System.Windows.Visibility.Collapsed;
                    this.ImportScorpBotSettingsPageGrid.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.ImportScorpBotSettingsPageGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    this.StatusMessageTextBlock.Text = "Gathering ScorpBot Data...";
                    if (!string.IsNullOrEmpty(this.ScorpBotDirectoryTextBox.Text))
                    {
                        this.scorpBotData = await this.GatherScorpBotData(this.ScorpBotDirectoryTextBox.Text);
                        if (this.scorpBotData == null)
                        {
                            await MessageBoxHelper.ShowMessageDialog("Failed to import ScorpBot data, please ensure that you have selected the correct directory. If this continues to fail, please contact Mix it Up support for assitance.");
                            return;
                        }
                    }

                    this.ImportScorpBotSettingsPageGrid.Visibility          = System.Windows.Visibility.Collapsed;
                    this.ImportStreamlabsChatBotSettingsPageGrid.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.ImportStreamlabsChatBotSettingsPageGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    this.StatusMessageTextBlock.Text = "Gathering Streamlabs Chat Bot Data...";
                    if (!string.IsNullOrEmpty(this.StreamlabsChatBotDataFilePathTextBox.Text))
                    {
                        this.streamlabsChatBotData = await this.GatherStreamlabsChatBotSettings(this.StreamlabsChatBotDataFilePathTextBox.Text);
                        if (this.streamlabsChatBotData == null)
                        {
                            await MessageBoxHelper.ShowMessageDialog("Failed to import Streamlabs Chat Bot data, please ensure that you have selected the correct data file & have Microsoft Excel installed. If this continues to fail, please contact Mix it Up support for assitance.");
                            return;
                        }
                    }

                    this.ImportStreamlabsChatBotSettingsPageGrid.Visibility = System.Windows.Visibility.Collapsed;
                    if (this.soundwaveData != null)
                    {
                        this.ImportSoundwaveInteractiveSettingsGrid.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        this.SetupCompletePageGrid.Visibility = System.Windows.Visibility.Visible;
                    }
                }
                else if (this.ImportSoundwaveInteractiveSettingsGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    this.ImportSoundwaveInteractiveSettingsGrid.Visibility = System.Windows.Visibility.Collapsed;
                    this.SetupCompletePageGrid.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.SetupCompletePageGrid.Visibility == System.Windows.Visibility.Visible)
                {
                    await this.RunAsyncOperation(async() =>
                    {
                        this.StatusMessageTextBlock.Text = "Importing data, this may take a few moments...";
                        await this.FinalizeNewUser();
                        this.Close();
                    });
                }
            });

            this.StatusMessageTextBlock.Text = string.Empty;
        }