using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Castle.ActiveRecord;
[Export]
public class WorkflowAgent
{
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
readonly Agent<WorkflowState> _agent;
public IStatusNotification StatusNotification { get; set; }
[System.ComponentModel.Composition.Import]
public NetworkAgent NetworkAgent { get; set; }
- private static readonly ILog Log = LogManager.GetLogger("WorkflowAgent");
+ [System.ComponentModel.Composition.Import]
+ public IPithosSettings Settings { get; set; }
+
public WorkflowAgent()
{
NetworkAgent.Post(new CloudDeleteAction(accountInfo, info, fileState));
break;
case FileStatus.Renamed:
+ if (state.OldPath == null)
+ {
+ //We reach this point only if the app closed before propagating a rename to the server
+ Log.WarnFormat("Unfinished rename [{0}]",state.Path);
+ StatusKeeper.SetFileState(state.Path,FileStatus.Conflict,FileOverlayStatus.Conflict, "Rename without old path");
+ break;
+ }
FileSystemInfo oldInfo = Directory.Exists(state.OldPath)
? (FileSystemInfo) new DirectoryInfo(state.OldPath)
: new FileInfo(state.OldPath);
newInfo));
//TODO: Do I have to move children as well or will Pithos handle this?
//Need to find all children of the OLD filepath
- MoveChildObjects(state);
+ //MoveChildObjects(state);
break;
}
}
}
}
+
private void DeleteChildObjects(WorkflowState state, FileState fileState)
{
if (fileState != null)
}
}
- private void MoveChildObjects(WorkflowState state)
+ /*private void MoveChildObjects(WorkflowState state)
{
var oldFileState = StatusKeeper.GetStateByFilePath(state.OldPath);
if (oldFileState != null)
oldMoveInfo, newMoveInfo));
}
}
- }
+ }*/
//Starts interrupted files for a specific account
public void RestartInterruptedFiles(AccountInfo accountInfo)
{
- StatusNotification.NotifyChange("Restart processing interrupted files", TraceLevel.Verbose);
-
- using (log4net.ThreadContext.Stacks["Workflow"].Push("Restart"))
+ StatusKeeper.CleanupOrphanStates();
+ using (log4net.ThreadContext.Stacks["Operation"].Push("RestartInterrupted"))
{
if (Log.IsDebugEnabled)
Log.Debug("Starting interrupted files");
.ToLower();
-
+
+
var account = accountInfo;
- var pendingEntries = from state in FileState.Queryable
+ var pendingEntries = (from state in FileState.Queryable
where state.FileStatus != FileStatus.Unchanged &&
+ state.FileStatus != FileStatus.Forbidden &&
+ state.FileStatus != FileStatus.Conflict &&
!state.FilePath.StartsWith(cachePath) &&
!state.FilePath.EndsWith(".ignore") &&
- state.FilePath.StartsWith(account.AccountPath)
- select state;
- var pendingStates = new List<WorkflowState>();
- foreach (var state in pendingEntries)
- {
- pendingStates.Add(new WorkflowState(account, state));
- }
+ state.FilePath.StartsWith(account.AccountPath)
+ select state).ToList();
+ if (pendingEntries.Count>0)
+ StatusNotification.NotifyChange("Restart processing interrupted files", TraceLevel.Verbose);
+
+ var pendingStates = pendingEntries
+ .Select(state => new WorkflowState(account, state))
+ .ToList();
+
if (Log.IsDebugEnabled)
Log.DebugFormat("Found {0} interrupted files", pendingStates.Count);
-
- foreach (var entry in pendingStates)
- {
- Post(entry);
- }
+ pendingStates.ForEach(Post);
}
}