public ActionResult _RecentScreenShots() { //Check Authorization if (!cls_Authorization.isAllowedURL("Dashboard_TopScreenShots")) { return(null); } List <FileList> objfilelist = new List <FileList>(); try { using (var db = new DBContext()) { string screenShotFolderPath = Server.MapPath(appKeyReader.ReadKey("ScreenShotFolder")); if (Directory.Exists(screenShotFolderPath)) { DateTime dFrom = Utility.GetStartDate(); DateTime dTo = Utility.GetEndDate(); int count = 0; var Folder = new DirectoryInfo(screenShotFolderPath); var Images = Folder.GetFiles("*.png", SearchOption.AllDirectories).OrderByDescending(p => p.LastWriteTime).ToArray(); foreach (FileInfo img in Images) { string GetCustomerPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetFullPath(img.DirectoryName))); int customerId = Convert.ToInt16(Path.GetFileName(GetCustomerPath)); if (customerId == Utility.GetCustomerId()) { string machineName = new DirectoryInfo(Convert.ToString(Directory.GetParent(img.DirectoryName))).Name; int MachineDetailId = Convert.ToInt16(machineName.Substring(0, machineName.IndexOf('_'))); var MachineName = db.MachineDetails.Where(a => a.MachineDetailId == MachineDetailId).Select(b => b.MachineName).FirstOrDefault(); var UserName = db.MachineDetails.Where(a => a.MachineDetailId == MachineDetailId).Select(b => b.UserName).FirstOrDefault(); String[] FileName = img.ToString().Split('_'); //DateTime FileDate = Convert.ToDateTime(FileName[1] + "/" + FileName[2] + "/" + FileName[0]); DateTime FileDate = DateTime.ParseExact((FileName[1] + "-" + FileName[2] + "-" + FileName[0]), "MM-dd-yyyy", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None); if (FileDate >= dFrom && FileDate <= dTo && count < 14) { count++; objfilelist.Add(new FileList { FileURL = img.FullName.Replace(Server.MapPath("~/"), string.Empty).Replace("\\", "/"), MachineName = MachineName, UserName = UserName }); } } } } return(PartialView(objfilelist)); } } catch (Exception e) { ExceptionHandler handler = new ExceptionHandler(); handler.HandleException(e); } return(PartialView(objfilelist)); }
public static HttpClient GetHttpClient() { AppSettingReader asr = new AppSettingReader(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(asr.ReadKey("RemoteUrl")); return(client); }
public ActionResult Index(string sMachineDetailId) { //Check Authorization if (!cls_Authorization.isAllowedURL("Report_ScreenShots")) { return(RedirectToAction("login", "account")); } var model = new ScreenShot(); //Populate Tree View List <Tree> objTree = new List <Tree>(); //Populate File List List <FileList> objfilelist = new List <FileList>(); using (var db = new DBContext()) { int CustomerId = Utility.GetCustomerId(); ViewBag.CustomerId = CustomerId; try { string UserName = string.Empty; string MachineName = string.Empty; if (sMachineDetailId != "") { Int32 MachineDetailId = Convert.ToInt32(sMachineDetailId); MachineName = db.MachineDetails.Where(a => a.MachineDetailId == MachineDetailId).Select(b => b.MachineName).FirstOrDefault(); UserName = db.MachineDetails.Where(a => a.MachineDetailId == MachineDetailId).Select(b => b.UserName).FirstOrDefault(); } ViewBag.MachineName = MachineName; ViewBag.UserName = UserName; DataTable dt = new DataTable(); DataRow dtrow; dt.Columns.Add("Id", typeof(Int32)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("ParentId", typeof(Int32)); dt.Columns.Add("MacAddress", typeof(string)); var machinedetaillst = db.MachineDetails.Where(a => a.CustomerId == CustomerId).Select(a => a.MachineName).Distinct().ToList(); int Id = 0, PId = 0; foreach (var machinename in machinedetaillst) { PId = Id; var userdetaillst = db.MachineDetails.Where(a => a.MachineName == machinename && a.CustomerId == CustomerId).ToList(); dtrow = dt.NewRow(); dtrow["Id"] = Id + 1; dtrow["Name"] = machinename; dtrow["ParentId"] = 0; dt.Rows.Add(dtrow); Id = Id + 1; foreach (var userdetail in userdetaillst) { dtrow = dt.NewRow(); dtrow["Id"] = Id + 1; dtrow["Name"] = userdetail.UserName; dtrow["ParentId"] = PId + 1; dtrow["MacAddress"] = userdetail.MachineMacAddress; dt.Rows.Add(dtrow); Id = Id + 1; } } if (dt.Rows.Count > 0) { ViewBag.MachineCount = dt.Rows.Count.ToString(); } for (int i = 0; i < dt.Rows.Count; i++) { objTree.Add(new Tree { Id = Convert.ToInt32(dt.Rows[i]["Id"]), Name = Convert.ToString(dt.Rows[i]["Name"]), ParentId = Convert.ToInt32(dt.Rows[i]["ParentId"]), MachineMacAddress = Convert.ToString(dt.Rows[i]["MacAddress"]) }); } objTree = objTree.OrderBy(a => a.ParentId).ToList(); string screenShotFolderPath = Server.MapPath(appKeyReader.ReadKey("ScreenShotFolder")); string customerId = Utility.GetCustomerId().ToString(); string machineName = string.Empty; if (!string.IsNullOrWhiteSpace(MachineName)) { machineName = sMachineDetailId.Trim().ToString() + "_" + MachineName.Trim().ToString(); } screenShotFolderPath = Path.Combine(screenShotFolderPath, customerId); screenShotFolderPath = Path.Combine(screenShotFolderPath, machineName); screenShotFolderPath = Path.Combine(screenShotFolderPath, UserName.Trim().ToString()); if (Directory.Exists(screenShotFolderPath)) { DateTime dFrom = Utility.GetStartDate(); DateTime dTo = Utility.GetEndDate(); var Folder = new DirectoryInfo(screenShotFolderPath); var Images = Folder.GetFiles("*.png").OrderByDescending(p => p.LastWriteTime).ToArray(); foreach (FileInfo img in Images) { String[] FileName = img.ToString().Split('_'); // DateTime FileDate = Convert.ToDateTime(FileName[1] + "/" + FileName[2] + "/" + FileName[0]); DateTime FileDate = DateTime.ParseExact((FileName[1] + "-" + FileName[2] + "-" + FileName[0]), "MM-dd-yyyy", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None); if (FileDate >= dFrom && FileDate <= dTo) { objfilelist.Add(new FileList { FileURL = img.FullName.Replace(Server.MapPath("~/"), string.Empty).Replace("\\", "/"), MachineName = MachineName, UserName = UserName }); } } } } catch (Exception e) { ExceptionHandler handler = new ExceptionHandler(); handler.HandleException(e); } model.tree = objTree; model.filelist = objfilelist; return(Json(model, JsonRequestBehavior.AllowGet)); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { bool isEmail = Regex.IsMatch(model.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); if (isEmail) { using (var db = new DBContext()) { var cp = db.Customers.Where(a => a.Email.Trim() == model.Email.Trim()).FirstOrDefault(); if (cp != null) { ModelState.AddModelError("", "Email Address already exists.."); } else { WebSecurity.CreateUserAndAccount(model.Email, model.Password); Roles.AddUserToRoles(model.Email, new[] { "Customer" }); int currentUserId = WebSecurity.GetUserId(model.Email); //WebSecurity.Login(model.Email, model.Password); Customer customer = new Customer(); customer.MembershipId = currentUserId; customer.Email = model.Email.Trim(); customer.FirstName = string.Empty; customer.LastName = string.Empty; customer.OrganizationName = string.Empty; customer.CreateDate = DateTime.Now; db.Customers.Add(customer); db.SaveChanges(); string strFreeUsers = appKeyReader.ReadKey("FreeUsers"); string strPaidUsers = appKeyReader.ReadKey("PaidUsers"); Subscriber subscriber = new Subscriber(); subscriber.CustomerId = customer.CustomerId; subscriber.FreeUsers = string.IsNullOrEmpty(strFreeUsers) == true ? 0 : Convert.ToInt32(strFreeUsers); subscriber.PaidUsers = string.IsNullOrEmpty(strPaidUsers) == true ? 0 : Convert.ToInt32(strPaidUsers); subscriber.IsActive = true; subscriber.CreatedDate = DateTime.Now; subscriber.CreatedBy = currentUserId; db.Subscribers.Add(subscriber); db.SaveChanges(); try { //Successfully Register Mail Send to the User string toemail = Convert.ToString(model.Email); string subject = "Your free LiveMonitoring.com account has been created!"; string messageBody = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/App_Data/EmailTemplates/CustomerRegistration.html"))) { messageBody = reader.ReadToEnd(); } messageBody = messageBody.Replace("##Login##", model.Email); messageBody = messageBody.Replace("##Password##", model.Password); EmailUtils eu = new EmailUtils(toemail, subject, messageBody); if (eu.SendMail()) { } WebSecurity.Login(model.Email, model.Password, false); return(RedirectToAction("Index", "Home")); } catch (Exception ex) { ModelState.AddModelError("", "Error occured while sending email." + ex.Message); } } } } else { ModelState.AddModelError("", "Invalid Email Address"); } } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <HttpResponseMessage> UploadFiles() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string fileSaveLocation = HttpContext.Current.Server.MapPath(appKeyReader.ReadKey("ScreenShotFolder")); var provider = new MultipartFormDataStreamProvider(fileSaveLocation); string fileName = ""; try { await Request.Content.ReadAsMultipartAsync(provider); int machineID = Convert.ToInt16(provider.FormData["MachineId"].ToString()); string userName = provider.FormData["UserName"]; using (var db = new DBContext()) { var machineData = db.MachineDetails.Where(x => x.MachineDetailId == machineID).Select((y => new { CustomerId = y.CustomerId, y.MachineName })).FirstOrDefault(); string customerId = machineData.CustomerId.ToString(); string machineName = machineID.ToString() + "_" + machineData.MachineName; if (!string.IsNullOrEmpty(machineName) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(customerId)) { //Create CustomerId Folder if not exists fileSaveLocation = Path.Combine(fileSaveLocation, customerId); if (!Directory.Exists(fileSaveLocation)) { Directory.CreateDirectory(fileSaveLocation); } //Create Machine Folder if not exists fileSaveLocation = Path.Combine(fileSaveLocation, machineName); if (!Directory.Exists(fileSaveLocation)) { Directory.CreateDirectory(fileSaveLocation); } //Create User Folder if not exists fileSaveLocation = Path.Combine(fileSaveLocation, userName); if (!Directory.Exists(fileSaveLocation)) { Directory.CreateDirectory(fileSaveLocation); } foreach (MultipartFileData fileData in provider.FileData) { if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) { fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".png"; } else { fileName = fileData.Headers.ContentDisposition.FileName; fileName = fileName.Replace("\"", string.Empty); } //Three Attempt if getting error for (int i = 0; i < 3; i++) { try { //File Move if (File.Exists(fileData.LocalFileName)) { File.Move(fileData.LocalFileName, Path.Combine(fileSaveLocation, fileName)); break; } } catch (Exception) { System.Threading.Thread.Sleep(3000); } } } } return(Request.CreateResponse(HttpStatusCode.OK, fileName)); } } catch (System.Exception e) { ExceptionHandler handler = new ExceptionHandler(); handler.HandleException(e); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } }