2010-09-01 03:24:03 +04:00
|
|
|
//
|
|
|
|
// HtmlOut.cs: Grabs data from the template and formats the user output.
|
|
|
|
//
|
|
|
|
// Author:
|
|
|
|
// David Mulder (dmulder@novell.com)
|
|
|
|
//
|
2011-02-19 01:30:36 +03:00
|
|
|
// Copyright (C) 2011 Novell, Inc (www.novell.com)
|
2010-09-01 03:24:03 +04:00
|
|
|
//
|
|
|
|
|
2010-09-01 02:51:13 +04:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
2011-03-05 01:31:23 +03:00
|
|
|
using Rankdblib;
|
|
|
|
using Gravatarlib;
|
2010-09-01 02:51:13 +04:00
|
|
|
|
|
|
|
namespace getRank
|
|
|
|
{
|
|
|
|
public class HtmlOut
|
|
|
|
{
|
2010-11-30 03:09:26 +03:00
|
|
|
private static string directory = "";
|
2010-09-01 02:51:13 +04:00
|
|
|
internal static string header = "";
|
2010-11-30 03:09:26 +03:00
|
|
|
private static string userData = "";
|
2010-09-01 02:51:13 +04:00
|
|
|
internal static string footer = "";
|
2010-11-30 03:09:26 +03:00
|
|
|
private static string userHeader = "";
|
|
|
|
private static string projData = "";
|
|
|
|
private static string userFooter = "";
|
|
|
|
|
|
|
|
internal static string TemplateDirectory
|
2010-09-01 02:51:13 +04:00
|
|
|
{
|
2010-11-30 03:09:26 +03:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return directory;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == "")
|
|
|
|
{
|
|
|
|
directory = Directory.GetCurrentDirectory() + "/htdocs/";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
directory = value;
|
|
|
|
}
|
|
|
|
}
|
2010-09-01 02:51:13 +04:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:24:03 +04:00
|
|
|
/// <summary>
|
|
|
|
/// Reads the template and sections of the template to header, footer, and user strings.
|
|
|
|
/// </summary>
|
2010-09-01 02:51:13 +04:00
|
|
|
internal static void Template()
|
|
|
|
{
|
2010-11-30 03:09:26 +03:00
|
|
|
StreamReader read = File.OpenText(directory + "/template.html");
|
2010-09-01 02:51:13 +04:00
|
|
|
string template = "";
|
|
|
|
while (!read.EndOfStream)
|
|
|
|
{
|
|
|
|
template += read.ReadLine() + Environment.NewLine;
|
|
|
|
}
|
|
|
|
int front_user = template.IndexOf("<!-- Begin User -->");
|
|
|
|
int aft_front_user = front_user + 19;
|
|
|
|
int end_user = template.IndexOf("<!-- End User -->");
|
|
|
|
int aft_end_user = end_user + 17;
|
|
|
|
header = template.Substring(0, front_user);
|
2010-10-28 01:05:56 +04:00
|
|
|
userData = template.Substring(front_user + 19, end_user - aft_front_user);
|
2010-09-01 02:51:13 +04:00
|
|
|
footer = template.Substring(aft_end_user, template.Length - aft_end_user);
|
2010-10-28 01:05:56 +04:00
|
|
|
UserTemplate(userData);
|
2010-09-01 02:51:13 +04:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:24:03 +04:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an html instance of a user.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">
|
|
|
|
/// User's name <see cref="System.String"/>
|
|
|
|
/// </param>
|
|
|
|
/// <param name="email">
|
|
|
|
/// User's e-mail address <see cref="System.String"/>
|
|
|
|
/// </param>
|
|
|
|
/// <param name="rank">
|
|
|
|
/// User's rank <see cref="System.Int32"/>
|
|
|
|
/// </param>
|
|
|
|
/// <param name="code">
|
|
|
|
/// User's contributed lines of code <see cref="System.Int32"/>
|
|
|
|
/// </param>
|
|
|
|
/// <returns>
|
|
|
|
/// The html string representing the user <see cref="System.String"/>
|
|
|
|
/// </returns>
|
2011-01-05 19:54:21 +03:00
|
|
|
internal static string UserRank(Users user, int rank)
|
2010-09-01 02:51:13 +04:00
|
|
|
{
|
2010-10-30 20:13:54 +04:00
|
|
|
string data = ReplaceKeywords(userHeader, user, rank);
|
2011-01-05 19:54:21 +03:00
|
|
|
foreach (Projects proj in user.projects)
|
2010-10-28 01:05:56 +04:00
|
|
|
{
|
2010-10-30 20:13:54 +04:00
|
|
|
data += ReplaceKeywords(projData, user, rank)
|
|
|
|
.Replace("<!-- Project -->", proj.name)
|
2010-12-02 01:54:44 +03:00
|
|
|
.Replace("<!-- projCode -->", "+" + proj.CodeAdded.ToString() + " -" + proj.CodeRemoved.ToString())
|
2010-12-24 02:30:59 +03:00
|
|
|
.Replace("<!-- BluePercent -->", proj.BluePercent().ToString());
|
2010-10-28 01:05:56 +04:00
|
|
|
}
|
2010-12-23 02:33:39 +03:00
|
|
|
|
2010-12-23 02:36:26 +03:00
|
|
|
for (int i = 0; i < (4 - user.projects.Count); i++)
|
2010-12-23 02:33:39 +03:00
|
|
|
{
|
|
|
|
data += "<td></td>";
|
|
|
|
}
|
2010-12-02 01:54:44 +03:00
|
|
|
|
2010-10-30 20:13:54 +04:00
|
|
|
data += ReplaceKeywords(userFooter, user, rank);
|
2010-10-28 01:05:56 +04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2011-01-05 19:54:21 +03:00
|
|
|
private static string ReplaceKeywords(string html, Users user, int rank)
|
2010-10-30 20:13:54 +04:00
|
|
|
{
|
2010-12-24 01:57:19 +03:00
|
|
|
Gravatar img = new Gravatar(user.email[0], Gravatar.IconSets.identicon, Gravatar.Ratings.g, 50);
|
2010-12-23 21:02:05 +03:00
|
|
|
string gravatar = img.GravatarURL();
|
2010-10-30 20:13:54 +04:00
|
|
|
return html.Replace("<!-- rank -->", rank.ToString())
|
2011-01-29 02:15:16 +03:00
|
|
|
.Replace("<!-- name -->", user.Name)
|
2010-10-30 20:13:54 +04:00
|
|
|
.Replace("<!-- code -->", user.CodeAdded().ToString())
|
|
|
|
.Replace("<!-- email -->", user.email[0])
|
2010-12-23 21:02:05 +03:00
|
|
|
.Replace("<!-- Gravatar -->", gravatar)
|
2010-12-16 23:15:31 +03:00
|
|
|
.Replace("<!-- Image -->", ReplaceImageName(user))
|
2010-11-30 03:09:26 +03:00
|
|
|
.Replace("<!-- score -->", user.Score().ToString())
|
|
|
|
.Replace("<!-- commits -->", user.CommitCount().ToString());
|
2010-10-30 20:13:54 +04:00
|
|
|
}
|
|
|
|
|
2011-01-05 19:54:21 +03:00
|
|
|
private static string ReplaceImageName(Users user)
|
2010-12-16 23:15:31 +03:00
|
|
|
{
|
2010-12-19 01:52:46 +03:00
|
|
|
int GROVE = 50000;
|
|
|
|
int TREE = 5000;
|
|
|
|
int CRATE = 500;
|
2010-12-16 23:15:31 +03:00
|
|
|
int BUNCHES = 50;
|
|
|
|
int BUNCH = 0;
|
|
|
|
int PEEL = 0;
|
|
|
|
|
2010-12-17 23:45:15 +03:00
|
|
|
if (user.Score() > GROVE)
|
2010-12-16 23:15:31 +03:00
|
|
|
{
|
2010-12-17 23:45:15 +03:00
|
|
|
return "grove.png";
|
2010-12-16 23:15:31 +03:00
|
|
|
}
|
|
|
|
else if (user.Score() > TREE)
|
|
|
|
{
|
|
|
|
return "banana_tree.png";
|
|
|
|
}
|
|
|
|
else if (user.Score() > CRATE)
|
|
|
|
{
|
2010-12-17 19:33:47 +03:00
|
|
|
return "crate.png";
|
2010-12-16 23:15:31 +03:00
|
|
|
}
|
|
|
|
else if (user.Score() > BUNCHES)
|
|
|
|
{
|
|
|
|
return "banana_bunches.png";
|
|
|
|
}
|
|
|
|
else if (user.Score() > BUNCH)
|
|
|
|
{
|
|
|
|
return "3_bananas.png";
|
|
|
|
}
|
|
|
|
else if (user.Score() == PEEL)
|
|
|
|
{
|
|
|
|
return "peel.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2010-10-28 01:05:56 +04:00
|
|
|
private static void UserTemplate(string template)
|
|
|
|
{
|
|
|
|
int front_user = template.IndexOf("<!-- Data -->");
|
|
|
|
int aft_front_user = front_user + 13;
|
|
|
|
int end_user = template.IndexOf("<!-- End Data -->");
|
|
|
|
int aft_end_user = end_user + 17;
|
|
|
|
userHeader = template.Substring(0, front_user);
|
|
|
|
projData = template.Substring(front_user + 13, end_user - aft_front_user);
|
|
|
|
userFooter = template.Substring(aft_end_user, template.Length - aft_end_user);
|
2010-09-01 02:51:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|