コード例 #1
0
ファイル: Program.cs プロジェクト: hafsjold/snvrepos
        private static TblRecoveryPoint setupRecoveryPoint()
        {
            TblRecoveryPoint rec_RceoveryPoint = new TblRecoveryPoint
            {
                Name   = "MHATest",
                Rptime = DateTime.Now
            };

            m_db.TblRecoveryPoint.InsertOnSubmit(rec_RceoveryPoint);

            TblRecoveryPointLine rec_RecoveryPointLine = new TblRecoveryPointLine
            {
                Recoverypath   = @"C:\Documents and Settings\mha\Application Data\SummaSummarum\4",
                Recoveryisfile = false
            };

            rec_RceoveryPoint.TblRecoveryPointLine.Add(rec_RecoveryPointLine);

            rec_RecoveryPointLine = new TblRecoveryPointLine
            {
                Recoverypath   = @"C:\Documents and Settings\mha\Dokumenter\Medlem3060\Databaser\SQLCompact\dbData3060.sdf",
                Recoveryisfile = true
            };
            rec_RceoveryPoint.TblRecoveryPointLine.Add(rec_RecoveryPointLine);
            m_db.SubmitChanges();
            return(rec_RceoveryPoint);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: hafsjold/snvrepos
        private static void restorefile(TblRecoveryPointLine RecoveryPointLine)
        {
            var files = from rc in RecoveryPointLine.TblRecoveryPointContent
                        join c in m_db.TblContent on rc.Contentid equals c.Id
                        join f in m_db.TblDirectory on c.Directoryid equals f.Id
                        select new
            {
                RecoveryIsfile = RecoveryPointLine.Recoveryisfile,
                RestorePath    = RecoveryPointLine.Restorepath,
                fileName       = f.Name,
                parent         = f.Parentid,
                Data           = c.Data,
                Mtime          = c.Mtime,
                Atime          = c.Atime
            };
            int antal = files.Count();

            foreach (var fil in files)
            {
                string RestoreFileName = fil.fileName;
                string RestorePathOnly;
                if (fil.RecoveryIsfile == true)
                {
                    FileInfo fi = new FileInfo(fil.RestorePath);
                    RestorePathOnly = fi.DirectoryName;
                }
                else
                {
                    RestorePathOnly = fil.RestorePath;
                }
                string RestorePathAndName = RestorePathOnly + @"\" + RestoreFileName;
                File.WriteAllBytes(RestorePathAndName, ZipUncompressStream(fil.Data.ToArray()));
                FileInfo nfi = new FileInfo(RestorePathAndName);
                nfi.LastWriteTime  = fil.Mtime;
                nfi.LastAccessTime = fil.Atime;
            }
        }
コード例 #3
0
 private void detach_TblRecoveryPointLine(TblRecoveryPointLine entity)
 {
     this.SendPropertyChanging();
     entity.TblRecoveryPoint = null;
 }
コード例 #4
0
 partial void DeleteTblRecoveryPointLine(TblRecoveryPointLine instance);
コード例 #5
0
 partial void UpdateTblRecoveryPointLine(TblRecoveryPointLine instance);
コード例 #6
0
 partial void InsertTblRecoveryPointLine(TblRecoveryPointLine instance);
コード例 #7
0
ファイル: Program.cs プロジェクト: hafsjold/snvrepos
        private static 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_db.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_db.TblDirectory.InsertOnSubmit(per_rec_Directory);
                m_db.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_db.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_db.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     = ZipCompressStream(bData, fi.Name, fi.LastWriteTime)
                };
                rec_File.TblContent.Add(rec_Content);
                m_db.SubmitChanges();
            }

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

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