private void UpdateCacheBeforeTranscoding(bool sourceDocumentExist, bool savingSuccess, string sessionId, string documentId, string sourceDocumentName, int sourceDocumentSize) { if (!this.sessionDictionary.ContainsKey(sessionId)) { this.sessionDictionary.Add(sessionId, new Cache.Session()); } if (!this.sessionDictionary[sessionId].Documents.ContainsKey(documentId)) { this.sessionDictionary[sessionId].Documents.Add(documentId, new Cache.Document()); this.sessionDictionary[sessionId].Documents[documentId].SourceFileNumber = 1; } if (!this.sessionDictionary[sessionId].Documents[documentId].Files.ContainsKey(sourceDocumentName)) { Cache.FileStatus status = savingSuccess ? Cache.FileStatus.Transcoding : Cache.FileStatus.SavingFailed; this.sessionDictionary[sessionId].Documents[documentId].Files.Add(sourceDocumentName, new Cache.InputFileInformation(ExDateTime.UtcNow, status, sourceDocumentSize)); } else { Cache.InputFileInformation inputFileInformation = this.sessionDictionary[sessionId].Documents[documentId].Files[sourceDocumentName] as Cache.InputFileInformation; inputFileInformation.LastAccessTime = ExDateTime.UtcNow; inputFileInformation.Status = Cache.FileStatus.Transcoding; } int num = 0; if (sourceDocumentExist) { num += this.option.OutputThreshold; } else { num += sourceDocumentSize; if (savingSuccess) { num += this.option.OutputThreshold; } } this.cacheSize += num; }
private void CleanupThreadProc() { WaitHandle[] waitHandles = new WaitHandle[] { this.abortCleanupEvent, this.activeCleanupEvent }; while (WaitHandle.WaitAny(waitHandles) != 0) { this.cleanupThreadIdle = false; int num = (0 < this.expiredTime) ? this.expiredTime : 600; try { this.DeleteOtherOWACacheFolders(); List <string> list = new List <string>(); lock (this.myLock) { foreach (KeyValuePair <string, Cache.Session> keyValuePair in this.sessionDictionary) { if (keyValuePair.Value.Expired) { list.Add(keyValuePair.Key); } } } for (int i = list.Count - 1; i >= 0; i--) { int num2 = 0; int num3 = 0; string text = Path.Combine(this.processFolder, list[i]); DirectoryInfo dirInfo = new DirectoryInfo(text); try { num2 = this.GetFolderSize(dirInfo); Directory.Delete(text, true); } catch (IOException arg) { if (Directory.Exists(text)) { list.Remove(list[i]); try { num3 = this.GetFolderSize(dirInfo); } catch (UnauthorizedAccessException arg2) { ExTraceGlobals.TranscodingTracer.TraceError <string, UnauthorizedAccessException>((long)this.GetHashCode(), "Failed to get the size of the folder--{0}. Exception message: {1}", text, arg2); num3 = num2; } } ExTraceGlobals.TranscodingTracer.TraceError <string, IOException>((long)this.GetHashCode(), "Failed to delete the folder--{0}. Exception message: {1}", text, arg); } finally { lock (this.myLock) { this.cacheSize += num3 - num2; } } } lock (this.myLock) { foreach (string key in list) { this.sessionDictionary.Remove(key); } } List <Cache.ExpiredFile> list2 = new List <Cache.ExpiredFile>(); lock (this.myLock) { foreach (KeyValuePair <string, Cache.Session> keyValuePair2 in this.sessionDictionary) { foreach (KeyValuePair <string, Cache.Document> keyValuePair3 in keyValuePair2.Value.Documents) { foreach (KeyValuePair <string, Cache.FileInformation> keyValuePair4 in keyValuePair3.Value.Files) { TimeSpan timeSpan = TimeSpan.Zero; if (keyValuePair4.Value is Cache.InputFileInformation) { Cache.InputFileInformation inputFileInformation = keyValuePair4.Value as Cache.InputFileInformation; timeSpan = ExDateTime.UtcNow - inputFileInformation.LastAccessTime; } else if (keyValuePair4.Value is Cache.OutputFileInformation) { Cache.OutputFileInformation outputFileInformation = keyValuePair4.Value as Cache.OutputFileInformation; timeSpan = ExDateTime.UtcNow - outputFileInformation.CreateTime; } if (((double)num < timeSpan.TotalSeconds && keyValuePair4.Value.Status == Cache.FileStatus.Ready) || keyValuePair4.Value.Status == Cache.FileStatus.Deleting || keyValuePair4.Value.Status == Cache.FileStatus.SavingFailed) { Cache.ExpiredFile item = new Cache.ExpiredFile(keyValuePair2.Key, keyValuePair3.Key, keyValuePair4.Key, keyValuePair4.Value.Size); list2.Add(item); keyValuePair4.Value.Status = Cache.FileStatus.Deleting; } } } } } for (int j = list2.Count - 1; j >= 0; j--) { string text2 = Cache.CombinePath(new string[] { this.processFolder, list2[j].SessionId, list2[j].DocumentId, list2[j].FileName }); try { File.Delete(text2); lock (this.myLock) { this.cacheSize -= list2[j].Size; } } catch (IOException arg3) { if (File.Exists(text2)) { list2.Remove(list2[j]); } ExTraceGlobals.TranscodingTracer.TraceError <string, IOException>((long)this.GetHashCode(), "Failed to delete the file--{0}. Exception message: {1}", text2, arg3); } } lock (this.myLock) { foreach (Cache.ExpiredFile expiredFile in list2) { this.sessionDictionary[expiredFile.SessionId].Documents[expiredFile.DocumentId].Files.Remove(expiredFile.FileName); } } } catch (IOException arg4) { ExTraceGlobals.TranscodingTracer.TraceError <IOException>((long)this.GetHashCode(), "{0}", arg4); } finally { lock (this.myLock) { this.activeCleanupEvent.Reset(); } this.cleanupThreadIdle = true; } } }