public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { enOnlineResultsLogItemType Type = enOnlineResultsLogItemType.None; if (value is enOnlineResultsLogItemType) { Type = (enOnlineResultsLogItemType)value; } else if (value is int) { Type = (enOnlineResultsLogItemType)((int)value); } switch (Type) { case enOnlineResultsLogItemType.Error: return(Imaging.CreateBitmapSourceFromHIcon(SystemIcons.Error.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())); case enOnlineResultsLogItemType.OK: return(Imaging.CreateBitmapSourceFromHIcon(SystemIcons.Information.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())); case enOnlineResultsLogItemType.None: default: return(null); } } else { return(null); } }
private bool HandleFile(string FullFilePath) { CGroupItem GroupChanged = null; CCompItem Comp = null; long id = -1; string FileDir = System.IO.Path.GetDirectoryName(FullFilePath); int LastSlash = FileDir.LastIndexOf('\\'); if (long.TryParse(FileDir.Right(FileDir.Length - LastSlash - 1), out id)) { Comp = Comps.FirstOrDefault(arg => arg.id == id); if (Comp == null) { // Такого соревнования нет => его нужно добавить Comp = new CCompItem(id) { FolderName = id.ToString() + "\\" }; descriptions desc = DBManagerApp.m_Entities.descriptions.FirstOrDefault(arg => arg.id_desc == id); if (desc == null) { return(false); } else { Comp.CompName = desc.name; } if (long.TryParse(System.IO.Path.GetFileNameWithoutExtension(FullFilePath), out id)) { GroupChanged = AddNewGroup(Comp, id); if (GroupChanged == null) { return(false); } } else { // неверное название файла return(false); } Comps.Add(Comp); } else { if (long.TryParse(System.IO.Path.GetFileNameWithoutExtension(FullFilePath), out id)) { GroupChanged = Comp.Groups.FirstOrDefault(arg => arg.id == id); if (GroupChanged == null) { // Группы нет => добавляем GroupChanged = AddNewGroup(Comp, id); if (GroupChanged == null) { return(false); } } } } } else { // неверное название файла return(false); } GroupChanged.Items.Clear(); GlobalDefines.CheckPublishingDirExists(); List <CLogItem> lstItems = new List <CLogItem>(); try { using (TextReader tr = new StreamReader(string.Format("{0}{1}\\{2}{3}", GlobalDefines.STD_PUBLISHING_LOG_DIR, Comp.id, GroupChanged.id, GlobalDefines.PUBLISHING_LOG_FILE_EXTENSION))) { string line = null; CLogItem CurLogItem = null; DateTime ItemDateTime = DateTime.Now; enOnlineResultsLogItemType ItemType = enOnlineResultsLogItemType.None; do { line = tr.ReadLine(); if (line == null) { // Файл закончился break; } else { string[] Fields = line.Split(GlobalDefines.PUBLISHING_LOG_FIELDS_SEPARATOR); // Переносы строк не используем в логе для удобства, поэтому добавляем их там, где они нужны for (int i = 0; i < Fields.Length; i++) { Fields[i] = Fields[i].Replace(GlobalDefines.PUBLISHING_LOG_LFCR_SYMBOL, '\n'); } int Index = 0; if (Enum.TryParse <enOnlineResultsLogItemType>(Fields[Index++], out ItemType) && DateTime.TryParse(Fields[Index++], out ItemDateTime)) { CurLogItem = new CLogItem() { Type = ItemType, CreationDate = ItemDateTime, }; if (Fields.Length > Index) { CurLogItem.PCWbkName = Fields[Index].Trim(); } Index++; if (Fields.Length > Index) { CurLogItem.Text = Fields[Index].Trim(); } Index++; lstItems.Add(CurLogItem); } } }while (line != null); } } catch { } lstItems.Sort((lhs, rhs) => - lhs.CreationDate.CompareTo(rhs.CreationDate)); GroupChanged.Items.AddRange(lstItems); return(true); }