Example #1
0
 private void WalkFiles(BlobTestEntities1 ctx, DirectoryInfo di, Datum parent)
 {
     foreach (var f in di.GetFiles())
     {
         SaveData(ctx, parent, f);
     }
 }
Example #2
0
        private void PostIt()
        {
            var dir = lstFiles.SelectedItem.ToString();
            var di  = new DirectoryInfo(dir);
            var p   = di.Name;

            using (var ctx = new BlobTestEntities1())
            {
                var d = ctx.Data.FirstOrDefault(x => x.Name == p && x.IsFolder == true);

                if (d == null)
                {
                    d = new Datum()
                    {
                        Name     = p,
                        IsFolder = true,
                        FileName = di.Name,
                        TestGuid = Guid.NewGuid()
                    };

                    ctx.Data.Add(d);
                    ctx.SaveChanges();
                }

                var parent = d;
                WalkFiles(ctx, di, parent);

                foreach (var pd in di.GetDirectories())
                {
                    d = ctx.Data.FirstOrDefault(x => x.Name == pd.Name && x.IsFolder == true && parent.ParentId == x.ParentId);

                    if (d == null)
                    {
                        d = new Datum()
                        {
                            Name     = pd.Name,
                            IsFolder = true,
                            FileName = pd.Name,
                            TestGuid = Guid.NewGuid(),
                            ParentId = parent.BlobTestId
                        };
                        ctx.Data.Add(d);
                        ctx.SaveChanges();
                    }
                    WalkFiles(ctx, pd, d);
                }
            }

            MessageBox.Show(this, "Data sent to cloud");
        }
Example #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (DataSource == null)
     {
         using (var ctx = new BlobTestEntities1())
         {
             DataSource = ctx.Data.Include(x => x.Data1)
                          .Where(x => x.ParentId == null).ToList();
             RefreshTree();
         }
     }
     else
     {
         RefreshTree();
     }
 }
Example #4
0
        private Datum SaveData(BlobTestEntities1 ctx, Datum parent, FileInfo file)
        {
            var data = ctx.Data.FirstOrDefault(x => x.Name == file.Name && x.ParentId == parent.BlobTestId);

            if (data == null)
            {
                data = new Datum()
                {
                    Name     = file.Name,
                    FileName = file.Name,
                    Data     = File.ReadAllBytes(file.FullName),
                    TestGuid = Guid.NewGuid(),
                    ParentId = parent.BlobTestId
                };
                ctx.Data.Add(data);
            }
            else
            {
                data.Data = File.ReadAllBytes(file.FullName);
            }

            ctx.SaveChanges();
            return(data);
        }