Пример #1
0
 /// <summary>
 /// Adds a folder to the zip file
 /// </summary>
 /// <param name="Folder">Folder to add</param>
 public virtual void AddFolder(string Folder)
 {
     Folder.ThrowIfNullOrEmpty("Folder");
     Folder = new DirectoryInfo(Folder).FullName;
     if (Folder.EndsWith(@"\"))
         Folder = Folder.Remove(Folder.Length - 1);
     using (Package Package = ZipPackage.Open(ZipFileStream, FileMode.OpenOrCreate))
     {
         new DirectoryInfo(Folder)
             .GetFiles()
             .ForEach(x => AddFile(x.FullName.Replace(Folder, ""), x, Package));
     }
 }
Пример #2
0
        public static void InitLogger()
        {
            if (!Directory.Exists(LogFolder))
                Directory.CreateDirectory(LogFolder);

            var logs = new DirectoryInfo(LogFolder).GetFiles().OrderBy(s => s.LastWriteTime).ToList();
            while (logs.Count() >= ServerMain.settings.maximumLogs)
            {
                var first = logs.First();
                first.Delete();
                logs.Remove(first);
            }
        }
Пример #3
0
 public virtual void AddFolder(string Folder)
 {
     Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(Folder), "Folder");
     Folder = new DirectoryInfo(Folder).FullName;
     if (Folder.EndsWith(@"\", StringComparison.InvariantCulture))
         Folder = Folder.Remove(Folder.Length - 1);
     using (Package Package = ZipPackage.Open(ZipFileStream, FileMode.OpenOrCreate))
     {
         new DirectoryInfo(Folder)
             .GetFiles()
             .ForEach(x => AddFile(x.FullName.Replace(Folder, ""), x, Package));
     }
 }
        /// <summary>
        /// Deletes gallery
        /// </summary>
        /// <param name="id">Gallery identifier</param>
        public static bool DeleteGallery(int id)
        {
            lock (GetGallerySyncRoot(id))
            {
                OperationResult<OperationResults, Nullable<bool>> rslt = null;

                try
                {
                    rslt = GalleryRepository.DeleteGallery(id);
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex);
                    throw;
                }

                switch (rslt.Result)
                {
                    case OperationResults.Success:
                    case OperationResults.NotFound:
                        {
                            var dir = new DirectoryInfo(GetGalleryDevPath(id));

                            if (dir.Exists)
                            {
                                try
                                {
                                    dir.Remove();
                                }
                                catch (Exception ex)
                                {
                                    Logger.WriteError(ex);
                                }
                            }

                            RemoveGallerySyncRoot(id);

                            return true;
                        }
                    case OperationResults.Failure:
                        return false;
                    default:
                        throw new NotImplementedException();
                }
            }
        }