private void FillUserList() { try { if (Context.getCurrentUser.RoleId == (int)Role.Administrator) { List<CodeITDL.User> users = new List<CodeITDL.User>(); using (CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(Context.UserId)) { users = ctx.Users.Where(x => x.CustomerId == Context.CustomerId).ToList(); } users.Insert(0, new CodeITDL.User() { Id = -1, CustomerId = Context.CustomerId, FirstName = "Select All" }); cbName.DisplayMember = "FullName"; cbName.ValueMember = "Id"; cbName.DataSource = users; if (cbName.Items.Count > 0) cbName.SelectedIndex = 0; } } catch (Exception ex) { _logger.Error(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (rbtnCloud.Checked) { Licence.StorageType = StorageType.Cloud; Licence.CloudId = DEFAULT_CLOUD_ACCESS_KEY; Licence.CloudSecret = DEFAULT_CLOUD_SECRET_ACCESS_KEY; Licence.LocalPassword = string.Empty; Licence.LocalPath = string.Empty; Licence.LocalUsername = string.Empty; } else { Licence.StorageType = StorageType.Local; Licence.LocalPath = txtLocalPath.Text; Licence.LocalUsername = txtLocalUsername.Text; Licence.LocalPassword = txtLocalPassword.Text; Licence.CloudId = string.Empty; Licence.CloudSecret = string.Empty; } if (!Licence.IsValid()) { StringBuilder sb = new StringBuilder(); foreach (string message in Licence.ValidationMessagesList) { sb.AppendLine(message); } MessageBox.Show(sb.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string currentLicense = Licence.GenerateKey(); CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(); CodeITDL.License lic = ctx.Licenses.Where(c => c.CustomerId.ToString() == Licence.ClientId).FirstOrDefault(); if (lic != null) { lic.LicenseBytes = Encoding.UTF8.GetBytes(currentLicense); } else { CodeITDL.License newLic = new CodeITDL.License(); newLic.LicenseBytes = Encoding.UTF8.GetBytes(currentLicense); newLic.CustomerId = Guid.Parse(CodeITLicence.Licence.ClientId); ctx.Licenses.Add(newLic); } ctx.SaveChanges(); MessageBox.Show("Storage settings are successfully updated.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { _logger.Error(ex.Message); MessageBox.Show("Storage settings are not updated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void WriteLoginAudit(string status, int userId) { string pcUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; string pcName = Environment.MachineName; string pcIpAddress = LocalIPAddress(); using (CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(Context.UserId)) { CodeITDL.UserLoginAudit ula = new CodeITDL.UserLoginAudit(); ula.Action = status; ula.PcIpAddress = pcIpAddress; ula.PcName = pcName; ula.PcUserName = pcUserName; ula.UserId = userId; ula.Id = Guid.NewGuid(); ula.CreatedOn = DateTime.Now; ctx.UserLoginAudits.Add(ula); ctx.SaveChangesWithoutAudit(); } }
public static string getTempFolderLocation() { if (_tmpLocation != System.IO.Path.GetTempPath()) return _tmpLocation; using (CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(Context.UserId)) { if (ctx.Settings.Where(x => x.CustomerId == Context.CustomerId && x.Name == CodeITConstants.SETTINGS_TEMP_LOCATION).Count() > 0) _tmpLocation = ctx.Settings.Where(x => x.CustomerId == Context.CustomerId && x.Name == CodeITConstants.SETTINGS_TEMP_LOCATION).Select(x => x.Value).FirstOrDefault(); } return _tmpLocation; }
public static void ProcessGoProCameraForUser() { if (IsUploadFromGoProStarted) return; IDeviceManager manager = new DeviceManager(); IEnumerable<IDevice> devices = manager.GetAllDevices(); IDevice gopro = null; CodeITDL.User uploadUser = null; List<IDeviceObject> mp4Files = new List<IDeviceObject>(); List<CodeITBL.FileFromDB> mp4DbFiles = new List<CodeITBL.FileFromDB>(); bool shouldProceed = false; bool shouldDelete = false; #region CHECK FOR DEVICE ID AND USER if (devices.Count() > 0) using (CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(UserId)) { foreach (var device in devices) { string deviceID = string.Format("{0}||{1}", device.Id, device.Serial); //string deviceID = "\\\\?\\usb#vid_2672&pid_000d#c3131124781379#{6ac27878-a6fa-4155-ba85-f98f491d4f33}||C3131124781379"; var item = ctx.Users.Where(x => x.CustomerId == CustomerId && x.DeviceId == device.Id); if (ctx.Users.Where(x => x.CustomerId == CustomerId && x.DeviceId == deviceID) != null) { if (ctx.Users.Where(x => x.CustomerId.ToString().ToUpper() == CustomerId.ToString().ToUpper() && x.DeviceId == deviceID && x.Id == UserId).Count() > 0) { uploadUser = ctx.Users.Where(x => x.CustomerId == CustomerId && x.DeviceId == deviceID && x.Id == UserId).FirstOrDefault(); shouldProceed = true; gopro = device; IsUploadFromGoProStarted = true; break; } else { System.Windows.MessageBox.Show("This camera is not mapped to your user. Please contact the administrator!", "Info", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); } } } } #endregion CHECK FOR DEVICE ID AND USER if (!shouldProceed) return; #region CHECK FOR ACTIVE UPLOAD AND USER if (!progressForm.hasUploadCompleted) if (progressForm.getOwnerOfUploadProcess != uploadUser) { System.Windows.MessageBox.Show("There is active upload in progress, please wait until it is complete", "Info", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); shouldProceed = false; } #endregion CHECK FOR ACTIVE UPLOAD AND USER if (!shouldProceed) return; #region CHECK FOR VIDEO FILES if (gopro != null) { foreach (var rootFolder in gopro.GetDeviceRootStorageObjects()) mp4Files.AddRange(rootFolder.GetFiles("*.mp4")); } if (mp4Files.Count > 0) shouldProceed = true; #endregion CHECK FOR VIDEO FILES if (!shouldProceed) return; #region CONFIRMATION BOX if (!Context.IsUploadMessageBoxVisible) { filesForUpload = new List<IDeviceObject>(); getFilesRecursive(gopro.GetDeviceRootStorageObjects().ToList(), "*.mp4"); frmUploadMessageBox msgBox = new frmUploadMessageBox("message", "GoPro Upload Confirmation", filesForUpload, uploadUser, gopro); msgBox.StartPosition = FormStartPosition.CenterScreen; msgBox.TopMost = true; msgBox.TopLevel = true; msgBox.Show(); //on form closing, check if some file is selected for upload //this is because of posibility to minimize upload form msgBox.FormClosing += (sender, args) => { mp4Files = msgBox.SelectedFiles; mp4DbFiles = msgBox.SelectedDbFiles; Context.IsUploadMessageBoxVisible = false; shouldDelete = msgBox.Response == CustomMessageBoxResult.UploadAndDeleteSuccesfullyCompleted; if (msgBox.Response == CustomMessageBoxResult.Cancel) shouldProceed = false; else if (mp4Files.Count() == 0) { shouldProceed = false; } else shouldProceed = true; if (!shouldProceed) { IsUploadFromGoProStarted = false; return; } progressForm.StartUploadProcessFromGoPro(uploadUser, gopro, mp4Files, mp4DbFiles, shouldDelete); progressForm.Show(); }; } #endregion CONFIRMATION BOX }
private void FillArchivesFromSearch() { List<CodeITDL.User> UsersFromEntity = new List<CodeITDL.User>(); List<CodeITDL.File> FilesFromEntity = new List<CodeITDL.File>(); try { ((frmUserMainScreen)this.ParentForm).performResize(); Cursor.Current = Cursors.WaitCursor; List<int> users = new List<int>(); files = new List<FileFromDB>(); using (CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(Context.UserId)) { UsersFromEntity = ctx.Users.ToList(); FilesFromEntity = ctx.Files.ToList(); } bool isCloud = CodeITLicence.Licence.StorageType == CodeITLicence.StorageType.Cloud ? true : false; if (Context.getCurrentUser.RoleId != (int)Role.Administrator) users.Add(Context.UserId); else { users = UsersFromEntity.Where(x => x.CustomerId == Context.CustomerId && (x.Id == (int)cbName.SelectedValue || (int)cbName.SelectedValue == -1)).Select(x => x.Id).ToList(); } List<CodeITDL.File> tmpList = new List<CodeITDL.File>(); DateTime to = dtpTo.Value.Date.AddHours(23).AddMinutes(59); if (cbSearchBy.SelectedIndex == 0) { tmpList = FilesFromEntity.Where(x => x.OriginalFileDate >= dtpFrom.Value.Date && x.OriginalFileDate <= to && x.IsCloudFileSystem == isCloud && users.Contains(x.UserId)).OrderBy(x => x.NewFileName).ThenBy(x=>x.CreatedOn.Date).ToList(); } else { tmpList = FilesFromEntity.Where(x => x.CreatedOn >= dtpFrom.Value.Date && x.CreatedOn <= to && x.IsCloudFileSystem == isCloud && users.Contains(x.UserId)).OrderBy(x => x.NewFileName).ThenBy(x => x.CreatedOn.Date).ToList(); } if (tmpList != null && tmpList.Count > 0) { for (int i = 0; i < tmpList.Count; i++) { FileFromDB fileDb = new FileFromDB(tmpList[i], i); fileDb.UserName = (fileDb.UserId == Context.UserId ? (Context.getCurrentUser.FirstName + " " + Context.getCurrentUser.LastName) : UsersFromEntity.Where(u => u.Id == fileDb.UserId).Select(u => (u.FirstName + " " + u.LastName)).FirstOrDefault()); files.Add(fileDb); } } } catch (Exception ex) { } }
private void FillArchives() { List<CodeITDL.User> UsersFromEntity = new List<CodeITDL.User>(); List<CodeITDL.File> FilesFromEntity = new List<CodeITDL.File>(); try { using (CodeITDL.CodeITDbContext ctx = new CodeITDL.CodeITDbContext(Context.UserId)) { UsersFromEntity = ctx.Users.ToList(); FilesFromEntity = ctx.Files.ToList(); } if (FilesFromEntity.Count > 0) { DateTime limit = DateTime.Now.AddDays(6).Date; List<CodeITDL.File> uploadedFiles = new List<CodeITDL.File>(); bool isCloud = CodeITLicence.Licence.StorageType == CodeITLicence.StorageType.Cloud ? true : false; if (Context.getCurrentUser.RoleId != (int)Role.Administrator) { uploadedFiles = FilesFromEntity.Where(x => x.UserId == Context.UserId && x.OriginalFileDate <= limit && x.IsCloudFileSystem == isCloud).OrderByDescending(x => x.CreatedOn).ToList(); } else { uploadedFiles = FilesFromEntity.Where(x => x.OriginalFileDate <= limit && x.IsCloudFileSystem == isCloud && UsersFromEntity.Where(y => y.CustomerId == Context.CustomerId).Select(y => y.Id).Contains(x.UserId)).OrderByDescending(x => x.CreatedOn).ToList(); } List<CodeITDL.User> users = UsersFromEntity.Where(x => x.CustomerId == Context.CustomerId).ToList(); if (uploadedFiles != null && uploadedFiles.Count > 0) { for (int i = 0; i < uploadedFiles.Count; i++) { FileFromDB file = new FileFromDB(uploadedFiles[i], i); file.UserName = (file.UserId == Context.UserId ? (Context.getCurrentUser.FirstName + " " + Context.getCurrentUser.LastName) : UsersFromEntity.Where(u => u.Id == file.UserId).Select(u => (u.FirstName + " " + u.LastName)).FirstOrDefault()); files.Add(file); } } } } catch (Exception ex) { _logger.Error(ex.Message); } }