Ejemplo n.º 1
0
        public void Import(Stream zipStream, bool @override)
        {
            var tempPath   = Path.Combine(Path.GetDirectoryName(_dataFile), "TMEP");
            var exportFile = Path.Combine(tempPath, Path.GetFileName(_dataFile));

            //ensure the old file was removed.
            if (File.Exists(exportFile))
            {
                File.Delete(exportFile);
            }
            //extract the zip file.
            using (ZipFile zipFile = ZipFile.Read(zipStream))
            {
                zipFile.ExtractAll(tempPath);
            }
            //get the items in the temp file.
            if (File.Exists(exportFile))
            {
                var xmlListFileStorage = new XmlListFileStorage <T>(exportFile, new System.Threading.ReaderWriterLockSlim());
                foreach (var item in xmlListFileStorage.GetList())
                {
                    this.Add(item);
                }
            }

            System.IO.File.Delete(exportFile);
        }
Ejemplo n.º 2
0
        public void Export(IEnumerable <T> items, Stream outputStream)
        {
            if (items != null && items.Count() > 0)
            {
                var tempPath   = Path.Combine(Path.GetDirectoryName(_dataFile), "TMEP");
                var exportFile = Path.Combine(tempPath, Path.GetFileName(_dataFile));

                var xmlListFileStorage = new XmlListFileStorage <T>(exportFile, new System.Threading.ReaderWriterLockSlim());

                foreach (var item in items)
                {
                    var data = Get(item);
                    xmlListFileStorage.Add(data, true);
                }

                using (ZipFile zipFile = new ZipFile(Encoding.UTF8))
                {
                    zipFile.AddFile(exportFile, "");
                    zipFile.Save(outputStream);
                }

                try
                {
                    System.IO.File.Delete(exportFile);
                }
                catch (Exception e)
                {
                    Kooboo.HealthMonitoring.Log.LogException(e);
                }
            }
            else
            {
                using (ZipFile zipFile = new ZipFile(Encoding.UTF8))
                {
                    zipFile.AddFile(_dataFile, "");
                    zipFile.Save(outputStream);
                }
            }
        }