2using System.Collections.Generic;
10 internal enum CanUploadResult
31 internal class UploadInformation
34 private long byteCount;
35 private int fileCount;
36 private DateTime startedAt;
37 private readonly
object synchObject;
38 private LinkedList<SpecialFile> specialFiles;
46 this.bareJid = BareJid;
49 this.startedAt = DateTime.MinValue;
50 this.synchObject =
new object();
51 this.specialFiles =
null;
66 public CanUploadResult CanUploadFile(
long Size,
FilePurpose Purpose, HttpFileUploadSettings Settings)
68 lock (this.synchObject)
73 DateTime Now = DateTime.Now;
74 TimeSpan TS = Now - this.startedAt;
76 if (TS.TotalMinutes >= 1.0)
83 if (this.fileCount >= Settings.MaxFilesPerMinute)
84 return CanUploadResult.FileQuotaReached;
86 if (this.byteCount + Size > Settings.MaxBytesPerMinute)
87 return CanUploadResult.ByteQuotaReached;
92 if (
string.IsNullOrEmpty(Settings.KeyFolder) ||
string.IsNullOrEmpty(Settings.BackupFolder))
93 return CanUploadResult.FileQuotaReached;
97 if (
string.IsNullOrEmpty(Settings.EncryptedStorageFolder) ||
string.IsNullOrEmpty(Settings.EncryptedStorageRoot))
98 return CanUploadResult.FileQuotaReached;
102 if (
string.IsNullOrEmpty(Settings.PubSubStorageFolder) ||
string.IsNullOrEmpty(Settings.PubSubStorageRoot))
103 return CanUploadResult.FileQuotaReached;
108 this.byteCount += Size;
122 public bool TryGetSpecialFile(
string FileName,
string FileContentType,
long FileSize, out SpecialFile Result)
124 lock (this.synchObject)
126 if (!(this.specialFiles is
null))
128 foreach (SpecialFile Rec
in this.specialFiles)
130 if (Rec.FileName == FileName && Rec.FileContentType == FileContentType && Rec.FileSize == FileSize)
150 public void AddSpecialFile(
string FileName,
string FileContentType,
long FileSize,
FilePurpose Purpose)
152 lock (this.synchObject)
154 if (!(this.specialFiles is
null))
156 foreach (SpecialFile Rec
in this.specialFiles)
158 if (Rec.FileName == FileName && Rec.FileContentType == FileContentType && Rec.FileSize == FileSize)
160 Rec.Purpose = Purpose;
166 if (this.specialFiles is
null)
167 this.specialFiles =
new LinkedList<SpecialFile>();
169 this.specialFiles.AddLast(
new SpecialFile(Purpose, FileName, FileContentType, FileSize));
180 public bool RemoveSpecialFile(
string FileName,
string FileContentType,
long FileSize)
182 lock (this.synchObject)
184 if (!(this.specialFiles is
null))
186 LinkedListNode<SpecialFile> Loop = this.specialFiles.First;
188 while (!(Loop is
null) &&
189 (Loop.Value.FileName != FileName ||
190 Loop.Value.FileContentType != FileContentType ||
191 Loop.Value.FileSize != FileSize))
198 this.specialFiles.Remove(Loop);
Represents a case-insensitive string.
FilePurpose
Purpose of file uploaded