protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { Response.Write(Constants.ERROR_XML); return; FileNameHash_Rep repHash = new FileNameHash_Rep(); StreamReader reader = new StreamReader(this.Request.InputStream); String xmlData = reader.ReadToEnd(); XmlDocument docFile = new XmlDocument(); docFile.LoadXml(xmlData); string hash = Utils.TryGetProperty("FileHashRequest", docFile, "Hash").Trim().ToUpper(); string fname = Utils.TryGetProperty("FileHashRequest", docFile, "Fname"); string uname = Utils.TryGetProperty("FileHashRequest", docFile, "Uname"); string sfsize = Utils.TryGetProperty("FileHashRequest", docFile, "Fsize"); long fsize = 0; long.TryParse(sfsize, out fsize); if (string.IsNullOrEmpty(hash) || string.IsNullOrEmpty(fname) || string.IsNullOrEmpty(uname) || fsize <= 0) { Response.Write(Constants.ERROR_XML); return; } FileNameHash fnh = null; List<FileNameHash> recs = repHash.SearchForUser(uname, fsize, fname); if (recs.Count == 1) fnh = recs[0]; if (recs.Count == 0) fnh = new FileNameHash(); if (recs.Count > 1) { foreach (FileNameHash rec in recs) { repHash.Delete(rec.FileNameHashID); } fnh = new FileNameHash(); } fnh.DateTimeUpdated = DateTime.Now; fnh.FileName = fname; fnh.FileSize = fsize; fnh.Hash = hash; fnh.Username = uname; repHash.Save(fnh); } catch (Exception ex) { Response.Write(Constants.ERROR_XML); } }
public void Save(FileNameHash obj) { using (var session = WebCache.SessionFactory.OpenSession()) { // populate the database using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(obj); transaction.Commit(); } } }