private void detach_Dirindir(TblDirectory entity)
 {
     this.SendPropertyChanging();
     entity.Parent = null;
 }
 partial void DeleteTblDirectory(TblDirectory instance);
 partial void InsertTblDirectory(TblDirectory instance);
 partial void UpdateTblDirectory(TblDirectory instance);
Esempio n. 5
0
        private void backupfile(TblRecoveryPointLine rec_RceoveryPointLine, string filepath)
        {
            string backupFilepath = filepath;

            FileInfo fi = new FileInfo(backupFilepath);

            //Directories ------------------------------------------------------------
            string[]     strPaths = fi.DirectoryName.Split(new char[] { '\\' });
            TblDirectory per_rec_Directory;
            TblDirectory rec_Directory;
            TblDirectory rec_File;

            try
            {
                per_rec_Directory = (from d in m_dbRecovery.TblDirectory where d.Name == strPaths[0] && d.Parentid == null select d).First();
            }
            catch (InvalidOperationException)
            {
                per_rec_Directory = new TblDirectory
                {
                    Name   = strPaths[0],
                    Isfile = false
                };
                m_dbRecovery.TblDirectory.InsertOnSubmit(per_rec_Directory);
                m_dbRecovery.SubmitChanges();
            }

            for (int i = 1; i < strPaths.Length; i++)
            {
                try
                {
                    rec_Directory = (from d in per_rec_Directory.Dirindir where d.Name == strPaths[i] select d).First();
                }
                catch (InvalidOperationException)
                {
                    rec_Directory = new TblDirectory
                    {
                        Name   = strPaths[i],
                        Isfile = false
                    };
                    per_rec_Directory.Dirindir.Add(rec_Directory);
                    m_dbRecovery.SubmitChanges();
                }
                per_rec_Directory = rec_Directory;
            }

            //File ------------------------------------------------------------------
            try
            {
                rec_File = (from d in per_rec_Directory.Dirindir where d.Name == fi.Name select d).First();
            }
            catch (InvalidOperationException)
            {
                rec_File = new TblDirectory
                {
                    Name   = fi.Name,
                    Isfile = true
                };
                per_rec_Directory.Dirindir.Add(rec_File);
                m_dbRecovery.SubmitChanges();
            }

            //Content ---------------------------------------------------------------

            MD5           md5 = MD5.Create();
            StringBuilder sb  = new StringBuilder();

            byte[] bData = File.ReadAllBytes(fi.FullName);
            foreach (byte b in md5.ComputeHash(bData))
            {
                sb.Append(b.ToString("x2").ToLower());
            }

            TblContent rec_Content;

            try
            {
                rec_Content = (from d in rec_File.TblContent where d.Checksum == sb.ToString() select d).First();
            }
            catch (InvalidOperationException)
            {
                rec_Content = new TblContent
                {
                    Checksum = sb.ToString(),
                    Size     = fi.Length,
                    Mtime    = fi.LastWriteTime,
                    Atime    = fi.LastAccessTime,
                    Data     = ZipCompressStream2(bData, fi.Name, fi.LastWriteTime)
                };
                rec_File.TblContent.Add(rec_Content);
                m_dbRecovery.SubmitChanges();
            }

            //RecoveryPoint_Content -------------------------------------------------
            TblRecoveryPointContent rec_RecoveryPointContent = new TblRecoveryPointContent {
            };

            rec_Content.TblRecoveryPointContent.Add(rec_RecoveryPointContent);
            rec_RceoveryPointLine.TblRecoveryPointContent.Add(rec_RecoveryPointContent);
            m_dbRecovery.SubmitChanges();
        }