protected override object Present(object countObj, NameSwitcher nameSwitcher)
        {
            var         countResult        = countObj as ICountResult;
            CountResult defaultCountResult = new CountResult();

            defaultCountResult.Platform  = countResult.Platform;
            defaultCountResult.Series    = countResult.Series;
            defaultCountResult.CountList = countResult.CountList;

            Assembly assembly = null;

            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (asm.GetName().Name == "Present")
                {
                    assembly = asm;
                }
            }
            Type   helperType     = assembly.GetType("Present.TextPresentHelper");
            object helperInstance = helperType.GetMethod("GetInstance").Invoke(null, null);

            return((bool)helperType.GetMethod("GetPresent").Invoke(helperInstance, new object[2] {
                defaultCountResult, nameSwitcher
            }));
        }
        protected override object Present(string[] platforms, string[] seriesList,
                                          string countHelperTypeStringSuffix, string countHelperTypeNameSpaceString,
                                          string[] countHelperDependences, NameSwitcher nameSwitcher,
                                          string countHelperGetInstance,
                                          string getSeriesSeeds,
                                          string getCount,
                                          object[] countHelperGetInstanceParameters,
                                          object[] getCountParametersNoSeeds)
        {
            StringBuilder            log = new StringBuilder();
            string                   upperPlatform;
            IEnumerable <ICountItem> countList;
            string                   fileName = System.Environment.CurrentDirectory + @"\html\" + "PlayCount_" + DateTime.Now.ToLongDateString() + "_" + DateTime.Now.ToShortTimeString().Replace(":", "时") + ".html";

            using (StreamWriter sw = File.CreateText(fileName))
            {
                try
                {
                    sw.WriteLine("<html>");
                    sw.WriteLine("<head>");
                    sw.WriteLine(@"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
                    sw.WriteLine(@"<meta name='description' content='playCount Data!'>");
                    sw.WriteLine(@"<link rel='stylesheet' type='text/css' href='https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css'>");
                    sw.WriteLine(@"<script type='text/javascript' src='https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js'></script>");
                    sw.WriteLine(@"<script type='text/javascript' src='https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>");
                    sw.WriteLine(@"<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/clipboard@1/dist/clipboard.min.js'></script>");
                    sw.WriteLine("<style>.notextflow{overflow: hidden;text-overflow:ellipsis;}.nav{z-index:999;top:0;width:100%;position:fixed;}</style>");
                    sw.WriteLine("</head>");
                    sw.WriteLine("<body>");
                    sw.WriteLine("<div class='nav'><div class='row'>&nbsp;</div><div class='row'>&nbsp;</div><div class='container'></div></div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");

                    int count = 0;
                    foreach (var series in seriesList)
                    {
                        sw.WriteLine("<div class='container series " + "series" + count + "'>");
                        foreach (var platform in platforms)
                        {
                            upperPlatform = platform.Substring(0, 1).ToUpper() + platform.Substring(1);
                            countList     = (IEnumerable <ICountItem>)SeekResult(platform, series, countHelperTypeNameSpaceString + "." + upperPlatform + countHelperTypeStringSuffix, countHelperDependences, nameSwitcher, countHelperGetInstance, getSeriesSeeds, getCount, countHelperGetInstanceParameters, getCountParametersNoSeeds);
                            StringBuilder html = new StringBuilder();
                            if (countList.Count() == 0)
                            {
                                //We werent able to get the playcount result, because the platform didnt have the resource. so it return "". Exception comes when we dont get the data from the response.
                                Console.WriteLine("{0} {1} 播放量数据搜索完毕!", nameSwitcher.NameSwitch(platform), series);
                                Console.WriteLine();
                                continue;
                            }
                            html.AppendLine(@"<div class='row'>&nbsp;</div>");
                            html.AppendLine(@"<div class='row'>&nbsp;</div>");
                            html.AppendLine(@"<div class='row'>&nbsp;</div>");
                            html.AppendLine(@"<div class='row'>");
                            html.AppendLine(@"<div class='col-xs-1'></div>");
                            html.AppendLine(@"<button class='col-xs-10 btn btn-success btn-lg active'>");
                            html.AppendLine(nameSwitcher.NameSwitch(platform) + "&nbsp;&nbsp;&nbsp;&nbsp;" + series + "&nbsp;&nbsp;&nbsp;&nbsp;播放量(亿)</button>");
                            html.AppendLine(@"<div class='col-xs-1'></div>");
                            html.AppendLine(" </div>");

                            foreach (var countItem in countList)
                            {
                                html.AppendLine(@"<div class='row'>");
                                html.AppendLine(@"<div class='col-xs-1'></div>");
                                html.AppendLine(@"<button class='col-xs-4 btn btn-default btn-lg' >");
                                html.AppendLine(countItem.Title + "</button>");
                                html.AppendLine(@"<button class='col-xs-1 btn btn-default btn-lg singal' >&nbsp</button>");
                                html.AppendLine(@"<button class='col-xs-5 btn btn-info btn-lg' data-clipboard-text=");
                                //count unit format
                                string viewCount = (Math.Round((double.Parse(countItem.Count) / 1000000), MidpointRounding.AwayFromZero) / 100).ToString();
                                html.AppendLine("'" + viewCount + "'>" + viewCount + "</button>");
                                html.AppendLine(@"<div class='col-xs-1'></div>");
                                html.AppendLine(" </div>");
                            }
                            html.AppendLine("<div class='clearfix'></div>");
                            Console.WriteLine("{0} {1} 播放量数据搜索完毕!", nameSwitcher.NameSwitch(platform), series);
                            Console.WriteLine();
                            sw.WriteLine(html.ToString());
                        }
                        sw.WriteLine("</div>");
                        string navButton          = "<button class='col-xs-2 btn btn-warning btn-lg' data-series='" + "series" + count + "'>" + series + "</button>";
                        string addNavButtonScript = "<script>$('.nav .container').append(\"" + navButton + "\")</script>";
                        sw.WriteLine(addNavButtonScript);
                        count++;
                    }
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");
                    sw.WriteLine(@"<div class='row'>&nbsp;</div>");

                    sw.WriteLine("</body>");
                    string clipboard         = "var clipboard = new Clipboard('.btn-info');";
                    string clipboardSingal   = "$('.btn-info').click(function(){$(this).prev().addClass('btn-danger');$(this).prev().click(function(){$(this).removeClass('btn-danger');});});";
                    string ButtonClass       = "$('button').addClass('notextflow');";
                    string navButtonClick    = "$('.nav .container button').click(function(){ var seriesToken = $(this).get(0).dataset.series;$('.series').addClass('hidden');$('.' + seriesToken).addClass('show');$('.' + seriesToken).removeClass('hidden');$('body').animate({scrollTop:'0'},500);});";
                    string initSeriesVisible = "$('.series').addClass('hidden');$('.series0').removeClass('hidden');$('.series0').addClass('show');";
                    sw.WriteLine("<script>" + clipboard + clipboardSingal + ButtonClass + initSeriesVisible + navButtonClick + "</script>");
                    sw.WriteLine("</html>");
                    sw.Write(System.Environment.NewLine);
                    sw.Write(System.Environment.NewLine);
                    sw.Close();
                }
                catch (Exception ex)
                {
                    log.AppendLine("error: " + ex.Message);
                    log.AppendLine("streamWriter error");
                }
            }
            return(log);
        }
예제 #3
0
        protected override object Present(string[] platforms, string[] seriesList,
                                          string countHelperTypeStringSuffix, string countHelperTypeNameSpaceString,
                                          string[] countHelperDependences, NameSwitcher nameSwitcher,
                                          string countHelperGetInstance,
                                          string getSeriesSeeds,
                                          string getCount,
                                          object[] countHelperGetInstanceParameters,
                                          object[] getCountParametersNoSeeds)
        {
            StringBuilder log  = new StringBuilder();
            int           mode = 0;

            while (mode == 0)
            {
                Console.WriteLine("已选择xlsx类型的操作,请选择模式");
                Console.WriteLine("1 PlayCount.xlsx内容追加 2 创建新的xlsx文件 3 自定义xlsx文件内容追加 9 退出");
                var input = Console.ReadKey();
                Console.WriteLine();
                Console.WriteLine();
                switch (input.KeyChar.ToString())
                {
                case "1":
                    mode = 1;
                    break;

                case "2":
                    mode = 2;
                    break;

                case "3":
                    mode = 3;
                    break;

                case "9":
                    log.AppendLine("未进行操作");
                    return(log);

                default:
                    Console.WriteLine("请输入正确的操作!");
                    break;
                }
            }

            string upperPlatform;
            IEnumerable <ICountItem>      countList;
            Dictionary <string, string[]> dict = GetTitles();
            string xlsxFileName  = "PlayCount";
            string tempXlsxPath  = System.Environment.CurrentDirectory + @"\xlsx\temp" + new Random().Next().GetHashCode() + new Random().Next() + ".xlsx";
            string xlsxInputPath = string.Empty;

            IWorkbook workbook;

            if (mode == 2)
            {
                //when create a xlsx file. you just create a XSSFWorkbook object then write it into a filestream.
                workbook = new XSSFWorkbook();
            }
            else
            {
                if (mode == 1)
                {
                    //add content to exist .xlsx file by default file path: ./xlsx/PlayCount.xlsx
                    xlsxInputPath = System.Environment.CurrentDirectory + @"\xlsx\" + xlsxFileName + ".xlsx";
                }
                else
                {
                    while (true)
                    {
                        Console.WriteLine("请输入要追加内容的文件名(不包括.xlsx),回车确认输入,输入#退出");
                        xlsxFileName = Console.ReadLine();
                        Console.WriteLine();

                        if (xlsxFileName == "#")
                        {
                            log.AppendLine("未进行操作");
                            return(log);
                        }
                        xlsxInputPath = System.Environment.CurrentDirectory + @"\xlsx\" + xlsxFileName + ".xlsx";
                        if (File.Exists(xlsxInputPath))
                        {
                            break;
                        }
                        Console.WriteLine("未能找到文件:{0}", xlsxInputPath);
                    }
                }
                File.Copy(xlsxInputPath, tempXlsxPath);
                workbook = new XSSFWorkbook(tempXlsxPath);
            }

            foreach (var series in seriesList)
            {
                string[] titles;
                if (!dict.TryGetValue(series, out titles))
                {
                    log.AppendLine("there is no titles for " + series);
                    continue;
                }

                int rowCount;

                ISheet sheet;
                if (mode == 2)
                {
                    sheet    = workbook.CreateSheet(series);
                    rowCount = 0;
                }
                else
                {
                    sheet = workbook.GetSheet(series);
                    if (sheet == null)
                    {
                        Console.WriteLine("不存在名为{0}的sheet", series);
                        continue;
                    }
                    //the count in NPOI is start from 0 but excel from 1. the row after the last row is where we begin to fill the data
                    rowCount = sheet.LastRowNum + 1;
                }

                int column = 1;

                if (mode == 2)
                {
                    sheet.CreateRow(rowCount).CreateCell(column).SetCellValue(series + "播放量: 亿");
                    rowCount++;
                    sheet.CreateRow(rowCount).CreateCell(column).SetCellValue("日期|平台");
                    rowCount++;
                }
                sheet.CreateRow(rowCount).CreateCell(column).SetCellValue(DateTime.Now.ToLongDateString());
                rowCount++;
                Dictionary <string, int> titleDict = new Dictionary <string, int>();
                foreach (var title in titles)
                {
                    sheet.CreateRow(rowCount).CreateCell(column).SetCellValue(title);
                    titleDict.Add(title, rowCount);
                    rowCount++;
                }

                foreach (var platform in platforms)
                {
                    column++;
                    if (mode == 2)
                    {
                        sheet.GetRow(1).CreateCell(column).SetCellValue(platform);
                    }
                    upperPlatform = platform.Substring(0, 1).ToUpper() + platform.Substring(1);
                    countList     = (IEnumerable <ICountItem>)SeekResult(platform, series, countHelperTypeNameSpaceString + "." + upperPlatform + countHelperTypeStringSuffix, countHelperDependences, nameSwitcher, countHelperGetInstance, getSeriesSeeds, getCount, countHelperGetInstanceParameters, getCountParametersNoSeeds);
                    if (countList.Count() == 0)
                    {
                        //We werent able to get the playcount result, because the platform didnt have the resource. so it return "". Exception comes when we dont get the data from the response.
                        Console.WriteLine("{0} {1} 播放量数据搜索完毕!", nameSwitcher.NameSwitch(platform), series);
                        Console.WriteLine();
                        continue;
                    }
                    foreach (var countItem in countList)
                    {
                        int rowNum;
                        if (!titleDict.ContainsKey(countItem.Title))
                        {
                            rowNum = sheet.LastRowNum + 1;
                            titleDict.Add(countItem.Title, rowNum);
                        }
                        titleDict.TryGetValue(countItem.Title, out rowNum);
                        double viewCount = Math.Round((double.Parse(countItem.Count) / 1000000), MidpointRounding.AwayFromZero) / 100;
                        sheet.GetRow(rowNum).CreateCell(column).SetCellValue(viewCount);
                    }
                    Console.WriteLine("{0} {1} 播放量数据搜索完毕!", nameSwitcher.NameSwitch(platform), series);
                    Console.WriteLine();
                }
                column++;
                if (mode == 2)
                {
                    sheet.GetRow(1).CreateCell(column).SetCellValue("总计");
                }
            }

            if (mode == 2)
            {
                string xlsxOutputFilePath = System.Environment.CurrentDirectory + @"\xlsx\" + "PlayCount_" + DateTime.Now.ToLongDateString() + "_" + DateTime.Now.ToShortTimeString().Replace(":", "时") + ".xlsx";
                //when create a xlsx, you have to save the XSSFWorkbook object from memory into a file
                try
                {
                    using (FileStream fs = File.Open(xlsxOutputFilePath, FileMode.OpenOrCreate))
                    {
                        workbook.Write(fs);
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    log.AppendLine("error: " + ex.Message);
                    log.AppendLine("无法创建文件");
                }
            }
            else
            {
                File.Delete(xlsxInputPath);
                string xlsxOutputFilePath = System.Environment.CurrentDirectory + @"\xlsx\" + xlsxFileName + ".xlsx";
                try
                {
                    using (FileStream fs = File.Open(xlsxOutputFilePath, FileMode.OpenOrCreate))
                    {
                        workbook.Write(fs);
                        workbook.Close();
                        //File.Delete(tempXlsxPath);
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    log.AppendLine("error: " + ex.Message);
                    log.AppendLine("");
                }
            }
            return(log);
        }
예제 #4
0
        protected override object Present(string[] platforms, string[] seriesList,
                                          string countHelperTypeStringSuffix, string countHelperTypeNameSpaceString,
                                          string[] countHelperDependences, NameSwitcher nameSwitcher,
                                          string countHelperGetInstance,
                                          string getSeriesSeeds,
                                          string getCount,
                                          object[] countHelperGetInstanceParameters,
                                          object[] getCountParametersNoSeeds)
        {
            StringBuilder            log = new StringBuilder();
            string                   upperPlatform;
            IEnumerable <ICountItem> countList;

            foreach (var series in seriesList)
            {
                foreach (var platform in platforms)
                {
                    upperPlatform = platform.Substring(0, 1).ToUpper() + platform.Substring(1);
                    countList     = (IEnumerable <ICountItem>)SeekResult(platform, series, countHelperTypeNameSpaceString + "." + upperPlatform + countHelperTypeStringSuffix, countHelperDependences, nameSwitcher, countHelperGetInstance, getSeriesSeeds, getCount, countHelperGetInstanceParameters, getCountParametersNoSeeds);
                    if (countList.Count() == 0)
                    {
                        //there is no series on that platform.
                        Console.WriteLine("{0} {1} 播放量数据搜索完毕!", nameSwitcher.NameSwitch(platform), series);
                        Console.WriteLine();
                        continue;
                    }
                    string fileName = System.Environment.CurrentDirectory + @"\txt\" + series + "_" + nameSwitcher.NameSwitch(platform) + "_" + DateTime.Now.ToLongDateString() + "_" + DateTime.Now.ToShortTimeString().Replace(":", "时") + ".txt";
                    using (StreamWriter sw = File.CreateText(fileName))
                    {
                        try
                        {
                            sw.Write(nameSwitcher.NameSwitch(platform) + "  ");
                            sw.WriteLine(series + "  播放量(亿):");

                            foreach (var countItem in countList)
                            {
                                sw.Write(System.Environment.NewLine);
                                string title = countItem.Title != "" ? countItem.Title : "全集";
                                sw.Write(title + " : ");
                                if (countItem.Count != "0" | countItem.Count != "" | countItem.Count != null)
                                {
                                    string viewCount = (Math.Round((double.Parse(countItem.Count) / 1000000), MidpointRounding.AwayFromZero) / 100).ToString();
                                    sw.Write(viewCount);
                                }
                                else
                                {
                                    sw.Write(0);
                                }
                                sw.WriteLine("          key: " + countItem.Key);
                            }
                            sw.Write(System.Environment.NewLine);
                            sw.Write(System.Environment.NewLine);
                            sw.Close();
                            Console.WriteLine("{0} {1} 播放量数据搜索成功,已记录在文件中!", nameSwitcher.NameSwitch(platform), series);
                            Console.WriteLine();
                        }
                        catch (Exception ex)
                        {
                            log.AppendLine("error: " + ex.Message);
                            log.AppendLine(platform + "  " + series + "  streamWriter error");
                        }
                    }
                }
            }
            return(log);
        }