File size: 4,664 Bytes
e26fba6 |
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using BrightIdeasSoftware;
using System.Drawing;
using System.Security.Cryptography;
using System.IO;
using System.Windows.Forms;
using System.Globalization;
using Newtonsoft.Json;
namespace MovieFinder.Client
{
public class Movie
{
public static string ImgDirectory = "Images";
private static Dictionary<string, string> langauges = new Dictionary<string, string>();
static Movie()
{
langauges.Add("ml", "Malayalam");
langauges.Add("en", "English");
langauges.Add("hi", "Hindi");
langauges.Add("te", "Telugu");
langauges.Add("ta", "Tamil");
}
public Movie()
{
}
[JsonIgnore]
public string ImageID {
get {
if (String.IsNullOrEmpty(ImageUrl))
return String.Empty;
return GenerateShortID(ImageUrl);
} }
public string ImageUrl { get; set; }
public string Name { get; set; }
public DateTime? ReleasedDate { get; set; }
public string Year
{
get
{
if (ReleasedDate != null)
return ReleasedDate.Value.Year.ToString();
return String.Empty;
}
}
[JsonIgnore]
public string Language {
get
{
if (langauges.ContainsKey(LCode))
return langauges[LCode];
return LCode.ToString();
}
}
public string Description { get; set; }
public List<MovieLink> Links { get; set; }
[JsonIgnore]
public MovieLink Link1 {
get
{
return GetLink(1);
}
}
[JsonIgnore]
public MovieLink Link2
{
get
{
return GetLink(2);
}
}
[JsonIgnore]
public MovieLink Link3
{
get
{
return GetLink(3);
}
}
[JsonIgnore]
public MovieLink Link4
{
get
{
return GetLink(4);
}
}
[JsonIgnore]
public MovieLink Link5
{
get
{
return GetLink(5);
}
}
public string LCode { get; set; }
[JsonIgnore]
public string ImagePath
{
get
{
if (String.IsNullOrEmpty(ImageUrl))
return Path.Combine(Application.StartupPath, "no_image.gif");
return Path.Combine(ImgDirectory, ImageID);
}
}
public DateTime CreatedDate { get; set; }
public EntryChange EntryStatus { get; set; }
public int Version { get; set; }
private static string GenerateShortID(string input)
{
// step 1, calculate MD5 hash from input
var md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
// step 2, convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
private MovieLink GetLink(int pos)
{
if (Links.Count < pos)
{
for(int i = Links.Count; i < pos;i++)
Links.Add(new MovieLink());
}
return Links[pos - 1];
}
}
public class MovieLink
{
//public MovieLink (string url, string title)
//{
// Url = url;
// Title = title;
//}
public MovieLink()
{
Url = String.Empty;
Title = String.Empty;
}
public string Url { get; set; }
public string Title { get; set; }
public override string ToString()
{
return Title;
}
}
public enum EntryChange
{
EntryAdded = 0,
EntryUpdated = 1
}
}
|