Resultinfo.cs

00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 
00005 namespace Shared
00006 {
00010     [Serializable]
00011     public class SearchResult : ISearchable
00012     {
00013         private float relevance;
00014         private ISearchable item;
00015 
00019         public float Relevance
00020         {
00021             get { return relevance; }
00022             set { relevance = value; }
00023         }
00027         public ISearchable Item
00028         {
00029             get { return item; }
00030             set { item = value; }
00031         }
00032         
00038         public SearchResult(float relevance, ISearchable searchable)
00039         {
00040             this.relevance = relevance;
00041             this.item = searchable;
00042         }
00043 
00044         #region ISearchable Members
00045 
00049         public string Title
00050         {
00051             get { return item.Title; }
00052         }
00056         public string Description
00057         {
00058             get { return item.Description; }
00059         }
00063         public ResultType SearchType
00064         {
00065             get { return item.SearchType; }
00066         }
00067 
00068         public string Type
00069         {
00070             get { return item.Type; }
00071         }
00072 
00073         public DateTime Date
00074         {
00075             get { return item.Date; }
00076         }
00077 
00078         #endregion
00079     }
00080     
00084     public interface ISearchable
00085     {
00089         string Title { get;}
00093         string Description { get; }
00097         ResultType SearchType { get; }
00098         string Type { get; }
00099         DateTime Date { get; }
00100     }
00101 
00105     [Flags]
00106     public enum ResultType
00107     {
00108         Project = 1,
00109         Literature = 2,
00110         Review = 4,
00111         Tag = 8,
00112         Comment = 16,
00113         Person = 32,
00117         All = 63
00118     }
00119 
00120     
00124     [Serializable]
00125     public struct ProjectInfo : ISearchable
00126     {
00127         public int id;
00128         public DateTime startDate;
00129         public DateTime endDate;
00130         public string subject;
00131         public string title;
00132         public string department;
00133         public string synopsis;
00134         public bool submitted;
00135         
00136         public ProjectInfo(int id, DateTime start, DateTime endDate, string subject, string title, string department, string synopsis, bool submitted)
00137         {
00138             this.id = id;
00139             this.startDate = start;
00140             this.endDate = endDate;
00141             this.subject = subject;
00142             this.title = title;
00143             this.department = department;
00144             this.synopsis = synopsis;
00145             this.submitted = submitted;
00146         }
00147 
00148         #region ISearchable Members
00149 
00150         public string Title
00151         {
00152             get { return title; }
00153         }
00154 
00155         public string Description
00156         {
00157             get {
00158                 string st = "";
00159                 st += !String.IsNullOrEmpty(department) ? "Department: " + department + "; " : "";
00160                 st += !String.IsNullOrEmpty(subject) ? "Subject: " + subject + "; " : "";
00161                 return st;
00162             }
00163         }
00164 
00165         public ResultType SearchType
00166         {
00167             get { return ResultType.Project; }
00168         }
00169 
00170         public string Type
00171         {
00172             get { return "Project"; }
00173         }
00174 
00175         public DateTime Date
00176         {
00177             get { return submitted ? endDate : startDate; }
00178         }
00179 
00180         #endregion
00181     }
00182 
00186     [Serializable]
00187     public struct LiteratureInfo : ISearchable
00188     {
00189         public  int id;
00190         public  string author;
00191         public  string title;
00192         public  LiteratureType type;
00193         public  string summary;
00194         public  string source;
00195         public  string isbn;
00196         public string creator;
00197         public DateTime date;
00198 
00199         public LiteratureInfo(int id, string creator, string isbn, string title, string author, string summary, string source, DateTime date, LiteratureType type)
00200         {
00201             this.id = id;
00202             this.isbn = isbn;
00203             this.title = title;
00204             this.author = author;
00205             this.summary = summary;
00206             this.source = source;
00207             this.type = type;
00208             this.creator = creator;
00209             this.date = date;
00210         }
00211 
00212         #region ISearchable Members
00213 
00214         public string Title
00215         {
00216             get { return title; }
00217         }
00218 
00219         public string Description
00220         {
00221             get {
00222                 string st = "";
00223                 st += !String.IsNullOrEmpty(author) ? "Author: " + author + "; " : "";
00224                 st += !String.IsNullOrEmpty(source) ? "Source: " + source + "; " : "";
00225                 st += !String.IsNullOrEmpty(isbn) ? "ISBN: " + isbn + "; " : "";
00226                 return st;
00227             }
00228         }
00229 
00230         public ResultType SearchType
00231         {
00232             get { return ResultType.Literature; }
00233         }
00234 
00235         public string Type
00236         {
00237             get { return type.ToString(); }
00238         }
00239 
00240         public DateTime Date
00241         {
00242             get { return date; }
00243         }
00244 
00245         #endregion
00246     }
00250     [Serializable]
00251     public struct PersonInfo : ISearchable
00252     {
00253         public string department;
00254         public string name;
00255         public string username;
00256         public bool moderator;
00257         public string password;
00258         public string email;
00259         public PersonInfo(string username, string password, string name, string department, string email, bool moderator)
00260         {
00261             this.username = username;
00262             this.password = password;
00263             this.name = name;
00264             this.department = department;
00265             this.moderator = moderator;
00266             this.email = email;
00267         }
00268 
00269         #region ISearchable Members
00270 
00271         public string Title
00272         {
00273             get { return name; }
00274         }
00275 
00276         public string Description
00277         {
00278             get {
00279                 string st = "";
00280                 st += !String.IsNullOrEmpty(username) ? "Username: " + username + "; " : "";
00281                 st += !String.IsNullOrEmpty(department) ? "Department: " + department + "; " : "";
00282                 return st;
00283             }
00284         }
00285 
00286         public ResultType SearchType
00287         {
00288             get { return ResultType.Person; }
00289         }
00290 
00291         public string Type
00292         {
00293             get { return "Person"; }
00294         }
00295 
00296         public DateTime Date
00297         {
00298             get { return DateTime.MinValue; }
00299         }
00300 
00301         #endregion
00302     }
00303 
00307     [Serializable]
00308     public struct ReferenceInfo
00309     {
00310         public int project;
00311         public int literature;
00312         public DateTime date;
00313         public bool used;
00314         public string status;
00315 
00316         public ReferenceInfo(int project, int literature, DateTime date, bool used, string status)
00317         {
00318             this.project = project;
00319             this.literature = literature;
00320             this.date = date;
00321             this.used = used;
00322             this.status = status;
00323         }
00324     }
00325 
00329     [Serializable]
00330     public struct ReviewInfo : ISearchable
00331     {
00332         public int project;
00333         public int literature;
00334         public DateTime date;
00335         public bool used;
00336         public string status;
00337         
00338         public string title;
00339         public string text;
00340         public int rating;
00341         public string person;
00342 
00343         public ReviewInfo(int project, int literature, DateTime date, bool used, string status, string person, string title, string text, int rating)
00344         {
00345             this.rating = rating;
00346             this.person = person;
00347             this.text = text;
00348             this.title = title;
00349             this.project = project;
00350             this.literature = literature;
00351             this.date = date;
00352             this.used = used;
00353             this.status = status;
00354         }
00355 
00356         #region ISearchable Members
00357 
00358         public string Title
00359         {
00360             get { return title; }
00361         }
00362 
00363         public string Description
00364         {
00365             get {
00366                 string st = "";
00367                 st += rating > 0 ? "Rating: "+rating +"; " : "";
00368                 st += !String.IsNullOrEmpty(text) ? "Text: " + text + "; " : "";
00369                 return st;
00370             }
00371         }
00372 
00373         public ResultType SearchType
00374         {
00375             get { return ResultType.Review; }
00376         }
00377 
00378         public string Type
00379         {
00380             get { return "Review"; }
00381         }
00382 
00383         public DateTime Date
00384         {
00385             get { return date; }
00386         }
00387 
00388         #endregion
00389     }
00390 
00394     [Serializable]
00395     public struct SuggestionInfo
00396     {
00397         public int project;
00398         public int literature;
00399         public DateTime date;
00400         public bool used;
00401         public string status;
00402         public string reason;
00403 
00404         public string person;
00405 
00406         public SuggestionInfo(int project, int literature, DateTime date, bool used, string status, string person, string reason)
00407         {
00408             this.person = person;
00409             this.project = project;
00410             this.literature = literature;
00411             this.date = date;
00412             this.used = used;
00413             this.status = status;
00414             this.reason = reason;
00415         }
00416     }
00417 
00421     public enum CommentType { Reference, Literature, Comment }    
00422 
00426     [Serializable]
00427     public struct CommentInfo : ISearchable
00428     {
00429         public int id;
00430         public int parent;
00431         public int project; // only used for Reference Comments
00432         public string poster;
00433         public string title;
00434         public string text;
00435         public DateTime date;
00436         public CommentType type;
00437         public CommentInfo(int id, int literature, int project, string poster, string title, string text, DateTime date, CommentType type)
00438         {
00439             this.id = id;
00440             this.project = project;
00441             this.parent = literature;
00442             this.poster = poster;
00443             this.title = title;
00444             this.text = text;
00445             this.date = date;
00446             this.type = type;
00447         }
00448 
00449         #region ISearchable Members
00450 
00451         public string Title
00452         {
00453             get { return title; }
00454         }
00455 
00456         public string Description
00457         {
00458             get { return text; }
00459         }
00460 
00461         public ResultType SearchType
00462         {
00463             get { return ResultType.Comment; }
00464         }
00465 
00466         public string Type
00467         {
00468             get { return "Comment"; }
00469         }
00470 
00471         public DateTime Date
00472         {
00473             get { return date; }
00474         }
00475 
00476         #endregion
00477     }
00478 
00482     [Serializable]
00483     public struct TagInfo
00484     {
00485         public string Name;
00486         public int ID;
00487         public string UserName;
00488         public int Count;
00489         
00490         public TagInfo(string name, int id, string username)
00491         {
00492             this.Name = name;
00493             this.ID = id;
00494             this.UserName = username;
00495             this.Count = 1;
00496         }
00497 
00498         public TagInfo(string name, int id, string username, int count)
00499         {
00500             this.Name = name;
00501             this.ID = id;
00502             this.UserName = username;
00503             this.Count = count;
00504         }
00505 
00511         public static TagInfo[] Group(TagInfo[] infos)
00512         {
00513             Dictionary<string, Dictionary<int, int>> tags = new Dictionary<string, Dictionary<int, int>>();
00514             
00515             foreach (TagInfo ti in infos)
00516             {
00517                 if (!tags.ContainsKey(ti.Name))
00518                     tags.Add(ti.Name, new Dictionary<int, int>());
00519 
00520                 if (!tags[ti.Name].ContainsKey(ti.ID))
00521                     tags[ti.Name].Add(ti.ID, 0);
00522 
00523                 tags[ti.Name][ti.ID]++;
00524             }
00525             List<TagInfo> newInfos = new List<TagInfo>();
00526             foreach(KeyValuePair<string, Dictionary<int,int>> kvp in tags)
00527                 foreach (KeyValuePair<int, int> kvp2 in kvp.Value)
00528                 {
00529                     newInfos.Add(new TagInfo(kvp.Key, kvp2.Key, "", kvp2.Value));
00530                 }
00531 
00532 
00533             return newInfos.ToArray();
00534         }
00535     
00536     }
00537 
00541     [Serializable]
00542     public struct RoleInfo
00543     {
00544         public string UserName;
00545         public int Project;
00546         public RoleType Type;
00547 
00548         public RoleInfo(string username, int project, RoleType type)
00549         {
00550             this.UserName = username;
00551             this.Project = project;
00552             this.Type = type;
00553         }
00554     }
00555 
00559     public enum RoleType
00560     {
00564         Member,
00568         Supervisor,
00572         Creator
00573     }
00574     
00578     [Serializable]
00579     public struct StatisticsInfo
00580     {
00581         public int ProjectCount;
00582         public int TagCount;
00583         public int TagAssignments;
00584         public int LiteratureCount;
00585         public int UserCount;
00586         public StatisticsInfo(int projects, int tags, int tagClicks, int literature, int users)
00587         {
00588             this.ProjectCount = projects;
00589             this.TagAssignments = tagClicks;
00590             this.TagCount = tags;
00591             this.LiteratureCount = literature;
00592             this.UserCount = users;
00593         }
00594     }
00595 
00596 }

Generated on Thu Dec 21 06:21:56 2006 for SCRAML by  doxygen 1.5.1-p1