Пример #1
0
        public void BuildWebRankingData(List<string> doc, DateTime date)
        {
            Log.n("Web: Lager [Data] ranking..", Color.DarkGoldenrod);
            try
            {
                DateTime dtFra = GetFirstDayOfMonth(date);
                DateTime dtTil = date;
                timewatch.Start();

                var ranking = new RankingData(this, dtFra, dtTil, dtTil);

                GetHtmlStart(doc, true, "Ranking: Data");

                doc.Add("<h1>Avdeling: Data (" + avdeling.Get(appConfig.Avdeling) + ")</h1>");

                doc.Add("<h2>Dagens ranking for " + dtTil.ToString("dddd d. MMMM yyyy", norway) + "</h2>");
                doc.AddRange(ranking.GetTableHtml("dag"));

                doc.Add("<h2>" + StringRankingDato(dtTil) + "</h2>");
                doc.AddRange(ranking.GetTableHtml("måned"));

                if (appConfig.rankingCompareLastyear > 0)
                {
                    doc.Add("<h2>Sammenlignet " + StringRankingDato(dtTil.AddYears(-1)) + "</h2>");
                    doc.AddRange(ranking.GetTableCompareHtml());
                }
                if (appConfig.rankingCompareLastmonth > 0)
                {
                    doc.Add("<h2>Sammenlignet " + StringRankingDato(dtTil.AddMonths(-1)) + "</h2>");
                    doc.AddRange(ranking.GetTableCompareLastMonthHtml());
                }
                if (appConfig.favVis && Favoritter.Count > 0)
                {
                    doc.Add("<h2>Favoritt avdelinger " + StringRankingDato(dtTil) + "</h2>");
                    doc.AddRange(ranking.GetAvdHtml());
                }

                if (appConfig.graphVis && appConfig.graphData)
                {
                    if (appConfig.pdfExpandedGraphs)
                        doc.Add("<div class='Hidegraph'>");

                    doc.Add("<h2>Siste " + appConfig.graphDager + " dager Datamaskiner</h2>");
                    gc.SaveImageChunk("Data", settingsPath + @"\graphDataWeb.png", appConfig.graphResX, appConfig.graphResY, "", dtTil.AddDays(-appConfig.graphDager), dtTil);
                    doc.Add("<a href='#grafData'><img src='graphDataWeb.png' style='width:" + appConfig.graphWidth + "px;height:auto;'></a>");

                    doc.Add("<h2>Siste " + appConfig.graphDager + " dager Nettbrett:</h2>");
                    gc.SaveImageChunk("Nettbrett", settingsPath + @"\graphNettbrettWeb.png", appConfig.graphResX, appConfig.graphResY, "", dtTil.AddDays(-appConfig.graphDager), dtTil, false, null);
                    doc.Add("<a href='#grafNettbrett'><img src='graphNettbrettWeb.png' style='width:" + appConfig.graphWidth + "px;height:auto;'></a>");

                    if (appConfig.pdfExpandedGraphs)
                        doc.Add("</div>");
                }

                doc.Add(Resources.htmlEnd);
                Log.n("Web: Ranking [Data] tok " + timewatch.Stop() + " sekunder.", Color.DarkGoldenrod, true);
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
            }
        }
Пример #2
0
        private void BuildDataRanking(bool bg = false, BackgroundWorker bw = null)
        {
            string katArg = "Data";
            bool abort = HarSisteVersjon(katArg, appConfig.strData);
            try
            {
                if (!bg && !abort) timewatch.Start();
                if (!bg)
                    appConfig.savedPage = katArg;
                if (!abort)
                {
                    Log.n("Oppdaterer [" + katArg + "]..");
                    if (!bg)
                        webRanking.Navigate(htmlLoading);
                    var doc = new List<string>();
                    DateTime dtPick = pickerRankingDate.Value;
                    DateTime dtFra = GetFirstDayOfMonth(dtPick); DateTime dtTil = dtPick;
                    if (datoPeriodeVelger && !bg)
                    {
                        dtFra = datoPeriodeFra;
                        dtTil = datoPeriodeTil;
                    }

                    var ranking = new RankingData(this, dtFra, dtTil, dtPick);

                    openXml.DeleteDocument(katArg, dtPick);

                    GetHtmlStart(doc, true, "Ranking: " + katArg);

                    doc.Add("<h1>Avdeling: Data (" + avdeling.Get(appConfig.Avdeling) + ")</h1>");

                    if (!datoPeriodeVelger || bg)
                        doc.Add("<h3>Dagens ranking for " + dtPick.ToString("dddd d. MMMM yyyy", norway) + "</h3>");
                    else
                        doc.Add("<h3>Ranking for perioden fra " + dtFra.ToString("dddd d. MMMM yyyy", norway) + " til " + dtTil.ToString("dddd d. MMMM yyyy", norway) + "</h3>");
                    doc.Add("<span class='Loading'>Beregner..</span>");
                    if (!bg && timewatch.ReadyForRefresh())
                        webRanking.DocumentText = string.Join(null, doc.ToArray());
                    doc.RemoveAt(doc.Count - 1);
                    doc.AddRange(ranking.GetTableHtml("dag"));

                    if (!datoPeriodeVelger || bg)
                    {
                        doc.Add("<h3>" + StringRankingDato(dtPick) + "</h3>");
                        doc.Add("<span class='Loading'>Beregner..</span>");
                        if (!bg && timewatch.ReadyForRefresh())
                            webRanking.DocumentText = string.Join(null, doc.ToArray());
                        doc.RemoveAt(doc.Count - 1);
                        doc.AddRange(ranking.GetTableHtml("måned"));

                        if (appConfig.rankingCompareLastyear > 0)
                        {
                            doc.Add("<h3>" + StringRankingDato(dtPick.AddYears(-1)) + "</h3>");
                            doc.Add("<span class='Loading'>Beregner..</span>");
                            if (!bg && timewatch.ReadyForRefresh())
                                webRanking.DocumentText = string.Join(null, doc.ToArray());
                            doc.RemoveAt(doc.Count - 1);
                            doc.AddRange(ranking.GetTableCompareHtml());
                        }
                        if (appConfig.rankingCompareLastmonth > 0)
                        {
                            doc.Add("<h3>" + StringRankingDato(dtPick.AddMonths(-1)) + "</h3>");
                            doc.Add("<span class='Loading'>Beregner..</span>");
                            if (!bg && timewatch.ReadyForRefresh())
                                webRanking.DocumentText = string.Join(null, doc.ToArray());
                            doc.RemoveAt(doc.Count - 1);
                            doc.AddRange(ranking.GetTableCompareLastMonthHtml());
                        }
                        if (appConfig.favVis && Favoritter.Count > 0)
                        {
                            doc.Add("<h3>Favoritt avdelinger " + StringRankingDato(dtPick) + "</h3>");
                            doc.Add("<span class='Loading'>Beregner..</span>");
                            if (!bg && timewatch.ReadyForRefresh())
                                webRanking.DocumentText = string.Join(null, doc.ToArray());
                            doc.RemoveAt(doc.Count - 1);
                            doc.AddRange(ranking.GetAvdHtml());
                        }
                    }
                    if (appConfig.graphVis && appConfig.graphData)
                    {
                        doc.Add("<span class='Loading'>Henter graf..</span>");
                        if (!bg && timewatch.ReadyForRefresh())
                            webRanking.DocumentText = string.Join(null, doc.ToArray());
                        doc.RemoveAt(doc.Count - 1);

                        if (appConfig.pdfExpandedGraphs)
                            doc.Add("<div class='Hidegraph'>");

                        if (!datoPeriodeVelger || bg)
                            doc.Add("<h3>Siste " + appConfig.graphDager + " dager Datamaskiner</h3>");
                        else
                            doc.Add("<h3>Viser " + (datoPeriodeTil - datoPeriodeFra).Days + " dager Datamaskiner</h3>");
                        doc.Add("<span class='Loading'>Beregner..</span>");
                        if (!bg && timewatch.ReadyForRefresh())
                            webRanking.DocumentText = string.Join(null, doc.ToArray());
                        doc.RemoveAt(doc.Count - 1);

                        if (datoPeriodeVelger && !bg)
                        {
                            gc.SaveImageChunk("Data", settingsPath + @"\graphDataPeriode.png", appConfig.graphResX, appConfig.graphResY, "", dtFra, dtTil);
                            doc.Add("<a href='#grafData'><img src='graphDataPeriode.png' style='width:" + appConfig.graphWidth + "px;height:auto;'></a>");
                        }
                        else
                        {
                            gc.SaveImageChunk("Data", settingsPath + @"\graphData.png", appConfig.graphResX, appConfig.graphResY, "", dtTil.AddDays(-appConfig.graphDager), dtTil);
                            doc.Add("<a href='#grafData'><img src='graphData.png' style='width:" + appConfig.graphWidth + "px;height:auto;'></a>");
                        }

                        if (!datoPeriodeVelger || bg)
                            doc.Add("<h2>Siste " + appConfig.graphDager + " dager Nettbrett</h3>");
                        else
                            doc.Add("<h2>Viser " + (dtTil - dtFra).Days + " dager Nettbrett</h3>");

                        if (datoPeriodeVelger && !bg)
                        {
                            gc.SaveImageChunk("Nettbrett", settingsPath + @"\graphNettbrettPeriode.png", appConfig.graphResX, appConfig.graphResY, "", dtFra, dtTil, false, bw);
                            doc.Add("<a href='#grafNettbrett'><img src='graphNettbrettPeriode.png' style='width:" + appConfig.graphWidth + "px;height:auto;'></a>");
                        }
                        else
                        {
                            gc.SaveImageChunk("Nettbrett", settingsPath + @"\graphNettbrett.png", appConfig.graphResX, appConfig.graphResY, "", dtTil.AddDays(-appConfig.graphDager), dtTil, false, bw);
                            doc.Add("<a href='#grafNettbrett'><img src='graphNettbrett.png' style='width:" + appConfig.graphWidth + "px;height:auto;'></a>");
                        }

                        if (appConfig.pdfExpandedGraphs)
                            doc.Add("</div>");
                    }

                    doc.Add(Resources.htmlEnd);
                    if (stopRanking)
                    {
                        stopRanking = false;
                        ClearHash(katArg);
                        Log.n("Ranking stoppet.", Color.Red);
                        webRanking.Navigate(htmlStopped);
                    }
                    else
                    {
                        if (datoPeriodeVelger)
                        {
                            File.WriteAllLines(htmlPeriode, doc.ToArray(), Encoding.Unicode);
                            webRanking.Navigate(htmlPeriode);
                        }
                        else
                        {
                            File.WriteAllLines(htmlRankingData, doc.ToArray(), Encoding.Unicode);
                            if (!bg)
                                webRanking.Navigate(htmlRankingData);
                            if (!bg) Log.n("Ranking [" + katArg + "] tok " + timewatch.Stop() + " sekunder.", Color.Black, true);
                        }
                    }
                }
                else if (!bg)
                    webRanking.Navigate(htmlRankingData);
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                if (!bg)
                {
                    webRanking.Navigate(htmlError);
                    FormError errorMsg = new FormError("Feil ved generering av ranking for [" + katArg + "]", ex);
                    errorMsg.ShowDialog();
                }
            }
        }