-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMetaData.cs
130 lines (119 loc) · 5.35 KB
/
MetaData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using ReportsWebFormsSamples.Models;
namespace ReportsWebFormsSamples.Views
{
public class MetaData : System.Web.UI.Page
{
dynamic getReportSampleData(string controllerName)
{
dynamic samples = SampleData.getSampleData().samples;
dynamic sampleData = null;
foreach (dynamic sample in samples)
{
if ((sample.routerPath == "" && sample.basePath == controllerName) || sample.routerPath == controllerName)
{
sampleData = sample;
break;
}
}
return sampleData;
}
public void updateMetaData(bool isPreviewPage)
{
string sampleName = (string)HttpContext.Current.Items["sampleName"];
bool isReportDesigner = String.IsNullOrEmpty(sampleName);
dynamic sampleData;
MetaDataInfo metaData;
if (isPreviewPage)
{
if (isReportDesigner)
{
string designerType = (string)HttpContext.Current.Items["designerType"];
string reportName = HttpContext.Current.Request.QueryString["report-name"];
if (!string.IsNullOrEmpty(reportName))
{
string formattedName = "";
string[] splittedNames = reportName.Split('.')[0].Split('-');
for (int i = 0; i < splittedNames.Length; i++)
{
formattedName += Char.ToUpper(splittedNames[i][0]) + splittedNames[i].Substring(1);
}
sampleData = getReportSampleData(formattedName.Trim());
}
else
{
sampleData = new { sampleName = designerType + " sample", metaData = new { title = "" } };
}
metaData = this.updateDesignerMetaData(sampleData);
}
else
{
sampleData = getReportSampleData(sampleName);
metaData = this.updatePreviewMetaData(sampleData);
}
}
else
{
sampleData = getReportSampleData(sampleName);
metaData = this.updateSampleMetaData(sampleData);
}
this.Title = metaData.title;
this.MetaDescription = metaData.metaContent;
}
public MetaDataInfo updateSampleMetaData(dynamic sampleData)
{
string title = String.IsNullOrEmpty((string)sampleData.metaData.title) ? sampleData.sampleName : sampleData.metaData.title;
string basePath = new Regex(@"(?<!^)(?=[A-Z])").Replace((string)sampleData.basePath, " ", 1);
title += " | ASP.NET Webforms " + basePath.Trim();
title = title.Length < 45 ? title += " | Bold Reports" : title;
return new MetaDataInfo(title, (string)sampleData.metaData.description);
}
public MetaDataInfo updatePreviewMetaData(dynamic sampleData)
{
string title = String.IsNullOrEmpty((string)sampleData.metaData.title) ? sampleData.sampleName : sampleData.metaData.title;
string metaContent;
switch ((string)sampleData.basePath)
{
case "ReportViewer":
metaContent = "The ASP.NET WebForms Bold Report Viewer allows the end-users to visualize the " + title + " report in browsers.";
title += " | Preview | ASP.NET Webforms Report Viewer";
break;
case "ReportWriter":
title += " | Preview | ASP.NET Webforms Report Writer";
metaContent = "The ASP.NET WebForms Bold Report Writer allows the end-users to download the report in browsers without visualizing the report.";
break;
default:
title = "";
metaContent = "";
break;
}
title = title.Length < 45 ? title += " | Bold Reports" : title;
return new MetaDataInfo(title, metaContent);
}
public MetaDataInfo updateDesignerMetaData(dynamic sampleData)
{
string title = String.IsNullOrEmpty((string)sampleData.metaData.title) ? sampleData.sampleName : sampleData.metaData.title;
string metaContent = "The ASP.NET WebForms bold report designer allows the end-users to arrange/customize the reports appearance in browsers." +
"It helps to edit the " + title + " for customer\"s application needs.";
title += " | ASP.NET Webforms Report Designer";
title = title.Length < 45 ? title += " | Bold Reports" : title;
return new MetaDataInfo(title, metaContent);
}
public class MetaDataInfo
{
public string title { get; set; }
public string metaContent { get; set; }
public MetaDataInfo(string title, string metaContent)
{
this.title = title;
this.metaContent = metaContent;
}
}
}
}