internal static List<string> FindLanguages() { string[] a; var LstA = new List<string>(); if (System.IO.Directory.Exists("Languages")) { a = System.IO.Directory.GetFiles("Languages", "*.ulex"); foreach (var i in a) { var u = new System.IO.FileInfo(i).Name; u = u.Remove(u.LastIndexOf('.')); LstA.Add(u); } } try { if (System.IO.Directory.GetFiles(Shared.LocalData("Languages")).Length > 0) { a = System.IO.Directory.GetFiles(Shared.LocalData("Languages\\"), "*.ulex"); foreach (var i in a) { var u = new System.IO.FileInfo(i).Name; u = u.Remove(u.LastIndexOf('.')); if (LstA.Contains(u)) LstA.Remove(u); LstA.Add(u); } } } catch (Exception) { return LstA; } return LstA; }
public AplFile(string file) { byte [] contents = File.ReadAllBytes(file); string data = Encoding.UTF8.GetString(contents); Match m = Regex.Match(data, aplPattern); imageFile_ = m.Groups[1].Value; startSample_ = Convert.ToInt64(m.Groups[2].Value); endSample_ = Convert.ToInt64(m.Groups[3].Value); name_ = new FileInfo(file).Name; name_ = name_.Remove(name_.Length - ".apl".Length); ParseMetadata(data); }
/// <summary>Determines whether this instance this instance can be started.</summary> /// <returns><c>true</c> if this instance can be started; otherwise <c>false</c>.</returns> private static bool CanStartThisInstance() { // check for the "newinstance" argument var forceNewInstance = false; foreach (var arg in Program.Arguments) { if (arg == ValidArgs.NewInstance) { forceNewInstance = true; } else if (arg.StartsWith(ValidArgs.ParentProcId)) { var id = int.Parse(arg.Replace(ValidArgs.ParentProcId, "").Trim()); _parentProc = Process.GetProcessById(id); _isChildProc = true; } } if (forceNewInstance) { return(true); // force starting process } // check for a previous instance var appExeFile = new System.IO.FileInfo(AppPath).Name; appExeFile = appExeFile.Remove(appExeFile.LastIndexOf('.')); // remove the extension var procs = Process.GetProcessesByName(appExeFile); var thisProc = Process.GetCurrentProcess(); debuggerAttached = System.Diagnostics.Debugger.IsAttached; /* * Conditions for starting this instance: * 1. This is the only process * 2. More than one process and one of the existing processes is this one's parent * 3. A debugger is attached to this process */ return((procs.Length == 1 && procs[0].Id == thisProc.Id) || // condition 1 (procs.Length > 1 && _parentProc != null && procs.Select(p => p.Id).Contains(_parentProc.Id)) || // condition 2 debuggerAttached); // condition 3 }
public static void SendFile(string path, HttpListenerContext context) { var ext = new FileInfo(path).Extension; if (ext.StartsWith(".")) ext = ext.Remove(0, 1); context.Response.ContentType = getContentType(ext); byte[] buffer; if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/javascript" || context.Response.ContentType == "text/css") { using (var rdr = File.OpenText(path)) { var send = rdr.ReadToEnd(); if (ext == "php") { Process p = new Process(); p.StartInfo = new ProcessStartInfo("php\\php-cgi.exe", $"-f {path} {GetPhpArgumentQuery(context.Request.QueryString)}") { UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, WindowStyle = ProcessWindowStyle.Hidden }; p.Start(); send = p.StandardOutput.ReadToEnd(); } foreach (var toReplace in replaceVars) { var tmp = String.Empty; if (toReplace.Value.StartsWith("PATH")) { using (var r = File.OpenText(toReplace.Value.Split(':')[1])) tmp = r.ReadToEnd(); send = send.Replace(toReplace.Key, tmp); } else if (toReplace.Value.StartsWith("PROPERTYCALL")) { var property = context.Request.GetType().GetProperty(toReplace.Value.Split(':')[1]); if (property != null) send = send.Replace(toReplace.Key, property.GetValue(context.Request).ToString()); } else send = send.Replace(toReplace.Key, toReplace.Value); } buffer = Encoding.UTF8.GetBytes(send); } } else { using (Stream s = File.OpenRead(path)) { buffer = new byte[s.Length]; var length = s.Read(buffer, 0, (int)s.Length); Array.Resize(ref buffer, length); } } context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; context.Response.ContentLength64 = buffer.Length; context.Response.OutputStream.Write(buffer, 0, buffer.Length); }
public Dictionary<string, Metadados> recuperarMetadados() { try { IFormatter formatter = new BinaryFormatter(); string[] arquivos = Directory.GetFiles(dirBanco + "\\" + dirBaseDados + "\\"); Dictionary<string, Metadados> dados = new Dictionary<string, Metadados>(); foreach (string arquivo in arquivos) { if (arquivo.EndsWith(".meta")) { Stream stream = new FileStream(arquivo, FileMode.Open, FileAccess.Read, FileShare.Read); Metadados meta = (Metadados)formatter.Deserialize(stream); string tabela = new FileInfo(arquivo).Name; tabela = tabela.Remove(tabela.IndexOf('.')); dados.Add(tabela, meta); stream.Close(); } } return dados; } catch { throw new SGDBException("Tabela não existe"); } }
private async void InsertStudents_Click(object sender, RoutedEventArgs e) { if (ValidForm()) { string studentNo = ""; if (departmentsCombobox.SelectedItem == null || eduYearsCombobox.SelectedItem == null) { return; } bool isDuplicate = false; StudentsDataWithErrors.Clear(); try { foreach (StudentDataUserControl student in studentsList.Children) { studentNo = student.number.Text; StudentDataModel model = new StudentDataModel(); model.FirstName = student.firstName.Text; model.LastName = student.lastName.Text; model.RegNo = Int32.Parse(student.regNo.Text); StudentModel s = new StudentModel { FirstName = model.FirstName, LastName = model.LastName, RegNo = model.RegNo, Department = (DepartmentModel)departmentsCombobox.SelectedItem, EduYear = (EducationalYearModel)eduYearsCombobox.SelectedItem, AnswersList = (string)student.Tag }; var duplicate = StudentModels.Find(st => st.RegNo == s.RegNo); if (duplicate != null) { isDuplicate = true; duplicate.ErrorType = "Duplicated Value, Fix RegNo"; s.ErrorType = "Duplicated Value, Fix RegNo"; StudentsDataWithErrors.Add(duplicate); StudentsDataWithErrors.Add(s); StudentModels.Remove(duplicate); continue; } StudentModels.Add(s); } } catch (Exception er) { error.Visibility = Visibility.Visible; errorText.Text = $"Error at {studentNo}th line: {er.Message}"; return; } if (isDuplicate) { FixStudentsData(); return; } bool hasErrors = false; int errorsCount = 0; StringBuilder sb = new StringBuilder(); StringBuilder newStudentsData = new StringBuilder(); sb.Append($"At {DateTime.Now.ToString()} new error log was created{Environment.NewLine}"); foreach (StudentModel s in StudentModels) { string err = GlobalConfig.Connection.CreateStudent(s); if (err != null) { hasErrors = true; errorsCount++; sb.Append(err); } newStudentsData.AppendLine(StudentFixedDataText(s)); } string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (hasErrors) { sb.Append($"==================================================================={Environment.NewLine}"); File.AppendAllText(path + "\\log.txt", sb.ToString()); sb.Clear(); await this.ShowMessageAsync("Error in the Creating Porccess", $"The creating proccess finished with {errorsCount} errors{Environment.NewLine}" + $"Please check Log file on the desktop for more information", MessageDialogStyle.Affirmative, null); } string fileName = new System.IO.FileInfo(StudentListPath).Name; fileName = fileName.Remove(fileName.Length - 4, 4); File.WriteAllText(System.IO.Path.GetDirectoryName(StudentListPath) + $"\\{fileName}-Fixed-Data.txt", newStudentsData.ToString(), encoding: Encoding.Unicode); this.Close(); } }