public void Upload(string filename, string sourcePath) { try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(string.Format("{0}/{1}", "ftp://" + Server, filename))); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(Username, Password); Stream ftpStream = request.GetRequestStream(); FileStream fs = File.OpenRead(sourcePath); byte[] buffer = new byte[1024]; double total = (double)fs.Length; int byteRead = 0; double read = 0; do { byteRead = fs.Read(buffer, 0, 1024); ftpStream.Write(buffer, 0, byteRead); read += (double)byteRead; } while (byteRead != 0); fs.Close(); ftpStream.Close(); } catch (WebException) { EventLogViewModel.AddNewRegistry("An error has occured during file uploading", DateTime.Now, this.GetType().Name, "ERROR"); } }
public void GetFileList() { try { FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://" + Server); ftpRequest.Credentials = new NetworkCredential(Username, Password); ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory; FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream()); directories = new List <string>(); string line = streamReader.ReadLine(); while (!string.IsNullOrEmpty(line)) { directories.Add(line); line = streamReader.ReadLine(); } streamReader.Close(); } catch (WebException) { EventLogViewModel.AddNewRegistry("An error has occured during file listing", DateTime.Now, this.GetType().Name, "ERROR"); } }
public async static void LoadAES_KeyIV_FromFile() { string resultReturn; string fullPath; string[] result = null; if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime) { OpenFileDialog dialog = new OpenFileDialog(); result = await dialog.ShowAsync(desktopLifetime.MainWindow); } try { if (result != null && result.Length != 0) { resultReturn = result[0]; fullPath = string.Join(" ", resultReturn); Debug.WriteLine(fullPath); byte[] buffer = File.ReadAllBytes(fullPath); Debug.WriteLine(buffer.Length); AES256Key = buffer.Take(32).ToArray(); AES256IV = buffer.Skip(32).Take(16).ToArray(); IsKeyLoaded = true; IsKeySet = true; IsIVSet = true; EventLogViewModel.AddNewRegistry("AES Key and IV has been loaded from external file", DateTime.Now, "Encryption", "HIGH"); } } catch (IOException ex) { EventLogViewModel.AddNewRegistry("File that stores a key can not be opened", DateTime.Now, "Encryption", "ERROR"); } }
public async Task <IActionResult> EventLog(int current = 0) { var hasPermission = await _accessManager.HasPermission(User.Identity.Name, _adminSubsystemName); if (hasPermission) { var pathToLogs = Path.Combine(_hostEnvironment.ContentRootPath, "Logs"); var dates = _eventLogService.GetAllLogDates(pathToLogs); dates.Sort((time1, time2) => - time1.CompareTo(time2)); var logs = _eventLogService.GetLogs(pathToLogs, dates[current]); var model = new EventLogViewModel() { CurrentDate = current, Dates = dates, Logs = logs }; return(View(model)); } return(Forbid(CookieAuthenticationDefaults.AuthenticationScheme)); }
public async static void SaveAES_KeyIV_ToFile() { string resultReturn = null; if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime) { SaveFileDialog saveFileDialog1 = new SaveFileDialog { Title = "Save AES key to file", InitialFileName = "core.key", DefaultExtension = "key" }; string result = await saveFileDialog1.ShowAsync(desktopLifetime.MainWindow); resultReturn = result; Debug.WriteLine(resultReturn); } if (!String.IsNullOrEmpty(resultReturn)) { byte[] concat = new byte[48]; AES256Key.CopyTo(concat, 0); AES256IV.CopyTo(concat, 32); File.WriteAllBytes(resultReturn, concat); EventLogViewModel.AddNewRegistry("AES Key and IV has been saved to external file", DateTime.Now, "Encryption", "HIGH"); } }
public static void GetAllInformationsAboutFiles(string ip, string username, string password, ref List <FileInformation> listFiles) { ListFilesAndDirectories(ip, username, password); try { foreach (var entry in files) { FileInformation fileInfo = new FileInformation(); string[] entrySplitted = entry.Split("/"); string filename = entrySplitted[entrySplitted.Length - 1]; string[] filenameSplitted = filename.Split("."); fileInfo.FullPath = entry; fileInfo.RelativePath = filenameSplitted[0]; fileInfo.Extension = filenameSplitted[1]; fileInfo.ModificationTime = GetDateTimestamp(entry, username, password); fileInfo.Size = GetFileSize(entry, username, password); fileInfo.LocalPath = entry; listFiles.Add(fileInfo); } } catch (Exception e) { EventLogViewModel.AddNewRegistry("An error has occured during collecting files' infos", DateTime.Now, "FTP", "ERROR"); } }
public static void ListFilesAndDirectories(string ip, string username, string password) { try { files = new List <string>(); Queue <String> folders = new Queue <String>(); folders.Enqueue("ftp://" + ip + "/"); while (folders.Count > 0) { String fld = folders.Dequeue(); List <String> newFiles = new List <String>(); FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(fld); ftp.Credentials = new NetworkCredential(username, password); ftp.UsePassive = false; ftp.Method = WebRequestMethods.Ftp.ListDirectory; using (StreamReader resp = new StreamReader(ftp.GetResponse().GetResponseStream())) { String line = resp.ReadLine(); while (line != null) { newFiles.Add(line.Trim()); line = resp.ReadLine(); } } ftp = (FtpWebRequest)FtpWebRequest.Create(fld); ftp.Credentials = new NetworkCredential(username, password); ftp.UsePassive = false; ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails; using (StreamReader resp = new StreamReader(ftp.GetResponse().GetResponseStream())) { String line = resp.ReadLine(); while (line != null) { if (line.Trim().ToLower().StartsWith("d") || line.Contains(" <DIR> ")) { String dir = newFiles.First(x => line.EndsWith(x)); newFiles.Remove(dir); folders.Enqueue(fld + dir + "/"); } line = resp.ReadLine(); } } files.AddRange(from f in newFiles select fld + f); } foreach (var entry in files) { Debug.WriteLine(entry.ToString()); } } catch (Exception e) { EventLogViewModel.AddNewRegistry("An error has occured during files listing", DateTime.Now, "FTP", "ERROR"); } }
//private ICompanyChartService _companyChartService; //public ExceptionLogApiController(ICompanyChartService CompanyService) // //: base(CompanyService) //{ // _companyChartService = CompanyService; //} public HttpResponseMessage GetAllLogs([System.Web.Http.ModelBinding.ModelBinder(typeof(Core.Mvc.ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest request) { var exceptionLogService = new LogService(); var qdtos = exceptionLogService.GetAllLogDTOs(); DataSourceResult result = qdtos.ToDataSourceResult(request, (dto) => EventLogViewModel.GetViewModel <EventLogViewModel>(dto)); return(Request.CreateResponse <DataSourceResult>(HttpStatusCode.OK, result)); }
public void Download(string filename, string destinationPath) { try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(string.Format("{0}/{1}", "ftp://" + Server, filename))); request.Credentials = new NetworkCredential(Username, Password); request.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebRequest request1 = (FtpWebRequest)WebRequest.Create(new Uri(string.Format("{0}/{1}", "ftp://" + Server, filename))); request1.Credentials = new NetworkCredential(Username, Password); request1.Method = WebRequestMethods.Ftp.GetFileSize; FtpWebResponse response = (FtpWebResponse)request1.GetResponse(); double total = response.ContentLength; response.Close(); FtpWebRequest request2 = (FtpWebRequest)WebRequest.Create(new Uri(string.Format("{0}/{1}", "ftp://" + Server, filename))); request2.Credentials = new NetworkCredential(Username, Password); request2.Method = WebRequestMethods.Ftp.GetDateTimestamp; FtpWebResponse response2 = (FtpWebResponse)request2.GetResponse(); DateTime modify = response2.LastModified; response2.Close(); Stream ftpstream = request.GetResponse().GetResponseStream(); // Dodać rozwiązanie gdy wybrana scieżka to np. C:\ FileStream fs = new FileStream(destinationPath + "\\" + filename, FileMode.Create); // Method to calculate and show the progress. byte[] buffer = new byte[1024]; int byteRead = 0; double read = 0; do { byteRead = ftpstream.Read(buffer, 0, 1024); fs.Write(buffer, 0, byteRead); read += (double)byteRead; }while (byteRead != 0); ftpstream.Close(); fs.Close(); } catch (Exception e) { EventLogViewModel.AddNewRegistry("An error has occured during file downloading", DateTime.Now, this.GetType().Name, "ERROR"); } }
public void SetUp() { var registry = new ServiceRegistry(); this.jobServiceMock = new JobServiceMock(); registry.AddSingleton <IJobService>(this.jobServiceMock); this.auditLogAdapter = new AuditLogAdapterMock(); registry.AddSingleton <IAuditLogAdapter>(this.auditLogAdapter); viewModel = new EventLogViewModel( null, registry); }
public override List <FileInformation> GetFiles() { try { var filesList = new List <FileInformation>(); FTP.GetAllInformationsAboutFiles(Credentials["server"], Credentials["username"], Credentials["password"], ref filesList); return(filesList); } catch (Exception e) { EventLogViewModel.AddNewRegistry("An error has occured during remote file listing", DateTime.Now, "FTP" + Credentials["server"], "ERROR"); throw; } }
public static bool UpdateTasksList(string name, bool status) { try { tasksList[name].IsActive = status; EventLogViewModel.AddNewRegistry("Updated " + name + " activity status", DateTime.Now, typeof(CoreTask).Name, "MEDIUM"); return(true); } catch (Exception e) { EventLogViewModel.AddNewRegistry("Error during updating " + name + " activity status", DateTime.Now, typeof(CoreTask).Name, "ERROR"); return(false); } }
public static bool UpdateTasksList(string oldName, string newName) { try { ConfigHub confValue = tasksList[oldName]; tasksList.Remove(oldName); AddTaskEntry(newName, confValue); EventLogViewModel.AddNewRegistry("Updated " + oldName + " name", DateTime.Now, typeof(CoreTask).Name, "MEDIUM"); return(true); } catch (Exception e) { EventLogViewModel.AddNewRegistry("Error during updating " + oldName + " name", DateTime.Now, typeof(CoreTask).Name, "ERROR"); return(false); } }
public static void AddTaskEntry(string taskName, ConfigHub configuration) { try { tasksList.Add(taskName, configuration); EventLogViewModel.AddNewRegistry("Custom Configuration " + taskName + " has been Saved", DateTime.Now, "Config", "MEDIUM"); } catch (ArgumentException) { EventLogViewModel.AddNewRegistry("Config " + taskName + " already exists", DateTime.Now, "Config", "HIGH"); } catch (Exception) { EventLogViewModel.AddNewRegistry(taskName + " config can not be added ", DateTime.Now, "Config", "HIGH"); } }
public void WhenNodeIsCloudNode_ThenCommandStateIsUnavailable() { var node = new Mock <IProjectExplorerCloudNode>().Object; Assert.AreEqual(CommandState.Unavailable, EventLogViewModel.GetCommandState(node)); }
public EventLogView(EventLogViewModel viewModel) { InitializeComponent(); this.DataContext = viewModel; }
public async Task <IEnumerable <EventLogViewModel> > GetEvents(int numEvents) { ICollection <EventLogViewModel> events = new List <EventLogViewModel>(); const string sql = @" SELECT TOP(@NumEvents) e.Id, e.Date, e.ModifiedBy, e.StudentId, e.UserId, e.Type, e.Action, u.FirstName, u.LastName, s.FirstName AS StudentFirstName, s.LastName AS StudentLastName, us.FirstName AS UserFirstName, us.LastName AS UserLastName, IPAddress FROM [dbo].[EventLog] e INNER JOIN [dbo].[Users] u ON [ModifiedBy] = u.id LEFT OUTER JOIN [dbo].[Students] s ON e.StudentId = s.id LEFT OUTER JOIN [dbo].[Users] us ON e.UserId = us.id ORDER BY [Date] DESC"; try { IEnumerable <dynamic> rows = await UnitOfWork.Context().QueryAsync <dynamic>(sql, new { NumEvents = numEvents }); foreach (IDictionary <string, object> row in rows) { StudentModel student = null; // TODO: Check for key or does key always exist and value is null? if (row.ContainsKey("StudentId") && row["StudentId"] != null) { student = new StudentModel() { Id = (int)row["StudentId"], FirstName = (string)row["StudentFirstName"], LastName = (string)row["StudentLastName"] }; } EventLogViewModel eventLog = new EventLogViewModel() { Id = (int)row["Id"], EventDate = DateTimeFilter.UtcToLocal((DateTime)row["Date"]), ModifiedById = (int)row["ModifiedBy"], ModifiedByFirstName = (string)row["FirstName"], ModifiedByLastName = (string)row["LastName"], Student = student, Type = (int)row["Type"], Action = (string)row["Action"] }; if (row.ContainsKey("UserId") && row["UserId"] != null) { eventLog.UserId = (int)row["UserId"]; eventLog.UserFirstName = (string)row["UserFirstName"]; eventLog.UserLastName = (string)row["UserLastName"]; } eventLog.RelativeDate = DateTimeFilter.CalculateRelativeDate(eventLog.EventDate.ToUniversalTime()); events.Add(eventLog); } } catch (Exception e) { e.Data["SQL"] = sql; ErrorStore.LogException(e, HttpContext.Current); throw e; } return(events); }