public static bool BackupBranch(List <string> nodePath, string zipFilePath, IProcessingCallback callback)
        {
            // remove zip path if it already exists
            if (System.IO.File.Exists(zipFilePath))
            {
                System.IO.File.Delete(zipFilePath);
            }

            // instantiate data context of current database
            PPDataContext dbFrom = new PPDataContext();
            // get node from
            TreeNode nodeFrom = TreeNode.GetNodeByPath(dbFrom, null, nodePath, 0);
            // build list of profiles referred by branch components
            List <string> profileNames = new List <string>();

            BuildListOfUsedCardboardProfiles(dbFrom, nodeFrom, ref profileNames);

            // build destination database path
            DBDescriptor dbDescTo = DBDescriptor.CreateTemp();

            {
                // build data context
                using (PPDataContext dbTo = new PPDataContext(dbDescTo))
                {
                    // copy cardboard profiles
                    MergeCardboardProfiles(dbFrom, dbTo, profileNames, callback);
                    // copy document types
                    CopyDocumentTypes(dbFrom, dbTo);
                    // copy branch nodes recursively
                    TreeNode nodeTo = TreeNode.GetNodeByPath(dbTo, null, nodePath, 0);;
                    CopyTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
                }
                GC.Collect();
            }
            Thread.Sleep(1000);
            // archive temp database
            dbDescTo.Archive(zipFilePath, callback);
            return(true);
        }
Example #2
0
 /// <summary>
 /// create in temp directory with empty database file
 /// </summary>
 /// <returns>Ready to use descriptor</returns>
 public static DBDescriptor CreateTemp()
 {
     return(DBDescriptor.CreateTemp(true));
 }
Example #3
0
        private static void FillFromArchive(DBDescriptor desc, string zipFilePath, IProcessingCallback callback)
        {        
            FileStream fileStreamIn = new FileStream(zipFilePath, FileMode.Open, FileAccess.Read);
            using (ZipInputStream zipInStream = new ZipInputStream(fileStreamIn))
            {
                ZipEntry entry;
                while ((entry = zipInStream.GetNextEntry()) != null)
                {
                    bool isDB = string.Equals("PicParam.db", entry.Name, StringComparison.CurrentCultureIgnoreCase);

                    if (null != callback)
                        callback.Info(string.Format("Extracting zip entry {0}", entry.Name));

                    string destFilePath = isDB ? desc.DBFilePath : Path.Combine(desc.RepositoryPath, entry.Name);
                    if (!ExtractZipEntry(entry, zipInStream, destFilePath, callback))
                        break;
                }
            }
            fileStreamIn.Close();
        }