private static bool Readfile(ItemizedFile file)
        {
            string text         = File.ReadAllText(file.Path, System.Text.Encoding.UTF8);
            int    newlineIndex = text.IndexOf("\n");

            if (newlineIndex == -1)
            {
                return(false);
            }

            // Header
            string header = text.Substring(0, newlineIndex);

            string[] parts = header.Split(';');
            for (int i = 0; i < parts.Length; i++)
            {
                if (i == 0)
                {
                    file.Version = int.Parse(parts[i]);
                }
                else if (i == 1)
                {
                    file.IsEncrypted = bool.Parse(parts[i]);
                }
            }

            // Body
            string body = text.Substring(newlineIndex + 1).Trim();

            file.Body = body;
            return(true);
        }
        public static List <ItemizedFile> GetFiles()
        {
            if (_files == null)
            {
                _files = new List <ItemizedFile>();
            }

            string[] filePaths = Directory.GetFiles(Directory.GetCurrentDirectory() + "\\Files", "*.itf");
            foreach (string filePath in filePaths)
            {
                if (_files.Any(f => f.Path == filePath))
                {
                    continue;
                }

                ItemizedFile file = new ItemizedFile();
                file.Name = Path.GetFileName(filePath);
                file.Path = filePath;
                if (!Readfile(file))
                {
                    continue;
                }

                _files.Add(file);
            }
            return(_files);
        }
 public static List <TaskItemView> GetFirstLevelItems(ItemizedFile file, bool?closed)
 {
     if (file.Items == null)
     {
         return(null);
     }
     return(file.Items.Where(i => i.ItemType == ItemTypes.Task &&
                             (closed == null || (i.ItemObject as TaskItem).IsClosed == closed.Value) &&
                             (i.ItemObject as TaskItem).ParentID == null)
            .Select(i => new TaskItemView(i.ItemObject as TaskItem))
            .ToList());
 }
 public static void SetChildItems(ItemizedFile file, List <TaskItemView> items, bool?closed)
 {
     if (items == null)
     {
         return;
     }
     foreach (var item in items)
     {
         item.ChildItems = file.Items.Where(i => i.ItemType == ItemTypes.Task &&
                                            (i.ItemObject as TaskItem).ParentID == item.ID &&
                                            (closed == null || (i.ItemObject as TaskItem).IsClosed == closed.Value))
                           .Select(i => new TaskItemView(i.ItemObject as TaskItem))
                           .ToList();
         if (item.ChildItems == null)
         {
             item.ChildItems = new List <TaskItemView>();
         }
     }
 }