A game about forced loneliness, made by TACStudios
at master 107 lines 3.6 kB view raw
1using System; 2using System.Collections.Generic; 3 4using Codice.LogWrapper; 5 6namespace Unity.PlasticSCM.Editor.AssetUtils.Processor 7{ 8 internal class PlasticAssetsProcessor : WorkspaceOperationsMonitor.IDisableAssetsProcessor 9 { 10 internal void SetWorkspaceOperationsMonitor( 11 IWorkspaceOperationsMonitor workspaceOperationsMonitor) 12 { 13 mWorkspaceOperationsMonitor = workspaceOperationsMonitor; 14 } 15 16 internal void AddToSourceControl(List<string> paths) 17 { 18 if (paths.Count == 0) 19 return; 20 21 if (IsDisableBecauseExceptionHappened(DateTime.Now)) 22 { 23 mLog.Warn( 24 "PlasticAssetsProcessor skipping AddToSourceControl operation " + 25 "because an exception happened in the last 60 seconds"); 26 return; 27 } 28 29 foreach (string path in paths) 30 mLog.DebugFormat("AddToSourceControl: {0}", path); 31 32 mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToAdd(paths); 33 } 34 35 internal void DeleteFromSourceControl(List<string> paths) 36 { 37 if (paths.Count == 0) 38 return; 39 40 if (IsDisableBecauseExceptionHappened(DateTime.Now)) 41 { 42 mLog.Warn( 43 "PlasticAssetsProcessor skipping DeleteFromSourceControl operation " + 44 "because an exception happened in the last 60 seconds"); 45 return; 46 } 47 48 foreach (string path in paths) 49 mLog.DebugFormat("DeleteFromSourceControl: {0}", path); 50 51 mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToDelete(paths); 52 } 53 54 internal void MoveOnSourceControl(List<AssetPostprocessor.PathToMove> paths) 55 { 56 if (paths.Count == 0) 57 return; 58 59 if (IsDisableBecauseExceptionHappened(DateTime.Now)) 60 { 61 mLog.Warn( 62 "PlasticAssetsProcessor skipping MoveOnSourceControl operation " + 63 "because an exception happened in the last 60 seconds"); 64 return; 65 } 66 67 foreach (AssetPostprocessor.PathToMove path in paths) 68 mLog.DebugFormat("MoveOnSourceControl: {0} to {1}", path.SrcPath, path.DstPath); 69 70 mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToMove(paths); 71 } 72 73 internal void CheckoutOnSourceControl(List<string> paths) 74 { 75 if (paths.Count == 0) 76 return; 77 78 if (IsDisableBecauseExceptionHappened(DateTime.Now)) 79 { 80 mLog.Warn( 81 "PlasticAssetsProcessor skipping CheckoutOnSourceControl operation " + 82 "because an exception happened in the last 60 seconds"); 83 return; 84 } 85 86 foreach (string path in paths) 87 mLog.DebugFormat("CheckoutOnSourceControl: {0}", path); 88 89 mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToCheckout(paths); 90 } 91 92 void WorkspaceOperationsMonitor.IDisableAssetsProcessor.Disable() 93 { 94 mLastExceptionDateTime = DateTime.Now; 95 } 96 97 bool IsDisableBecauseExceptionHappened(DateTime now) 98 { 99 return (now - mLastExceptionDateTime).TotalSeconds < 5; 100 } 101 102 DateTime mLastExceptionDateTime = DateTime.MinValue; 103 IWorkspaceOperationsMonitor mWorkspaceOperationsMonitor; 104 105 static readonly ILog mLog = PlasticApp.GetLogger("PlasticAssetsProcessor"); 106 } 107}