using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Model.UnitsOfWork;
using Model.Entities.Files;
using Model.Entities.Files.FS_Entities;
using BLL.Services;
using BLL.Services.FS;
using BLL.Services.System;

using System.IO;
using System.Data.Entity;

namespace Console
{
    class Program
    {
        static void test1()
        {
            //using (Context context = new Context(true))
            //{
            //    SRootDirectory rootDirectory = new SRootDirectory(@"D:\", "Root");
            //    context.FS_Items.Add(rootDirectory);


            //    SDirectory directory1 = new SDirectory()
            //    {
            //        Parent = rootDirectory,
            //        Name = "Dir1"
            //    };
            //    context.FS_Items.Add(directory1);

            //    SDirectory directory2 = new SDirectory()
            //    {
            //        Parent = rootDirectory,
            //        Name = "Dir2"
            //    };
            //    context.FS_Items.Add(directory2);



            //    SFile file1 = new SFile()
            //    {
            //        Parent = rootDirectory,
            //        Name = "file1.file",
            //        _Size = 10,
            //    };
            //    context.FS_Items.Add(file1);


            //    SFile file12 = new SFile()
            //    {
            //        Parent = directory1,
            //        Name = "file12.file",
            //        _Size = 10,
            //    };
            //    context.FS_Items.Add(file12);
            //    SFile file13 = new SFile()
            //    {
            //        Parent = directory1,
            //        Name = "file13.file",
            //        _Size = 123,
            //    };
            //    context.FS_Items.Add(file13);

            //    context.SaveChanges();
            //}


            //using (Context context = new Context())
            //{
            //    //var data = context.FS_Items.ToList();//.Include("_Items").Include(e => e.Parent).AsNoTracking().ToList();
            //    //var d = data[0].Size;

            //    var root = context.FS_Items.FirstOrDefault(e => e.Type == Enum_BaseDirectoryEntity.RootDirectory);
            //    var size = root.Size;
            //}

            UOW UOW = new UOW();


            ConfigurationServices configurationServices = new ConfigurationServices(UOW);
            configurationServices.ReadConfiguration();


            //var files = UOW.context.FS_Items.ToList();
        }

        static void Test2()
        {
            var UploadFile = new FileInfo(@"D:\Links.txt");

            using (var context = new Context(true)) { }


            UOW UOW = new UOW();

            new ConfigurationServices(UOW).ReadConfiguration();


            UploadServices uploadServices = new UploadServices(UOW);


            //var upload = uploadServices.StartUpload(
            //    UOW.Repo_rootDirectory.All.First(), UploadFile.Name, UploadFile.Length);

            //using (var stream = new FileStream(UploadFile.FullName, FileMode.Open, FileAccess.Read))
            //{
            //    byte[] data = new byte[upload.NextChunkSize];

            //    do
            //    {
            //        stream.Read(data, (int)upload.UploadedSize, upload.NextChunkSize);
            //    } while (uploadServices.UploadChunk(upload, data));
            //}
        }

        static void Main(string[] args)
        {
            //new Context(true);

            //var UOW = new UOW();
            //new ConfigurationServices(UOW).ReadConfiguration();
            //Task.WaitAll(new ScanServices(UOW).ScanAllDirs());

            //var dirs = UOW.Repo_SDirectory.All_List;


            var ts = new TokenServices();
            var token = ts.CreateTocken(10, new TimeSpan(5, 0,0));
            var data = ts.GetData(token);
        }
    }
}
