using (var client = await listener.AcceptTcpClientAsync()
.WithTimeout(TimeSpan.FromMinutes(5)))
{
-
using (var stream = client.GetStream())
using (var reader=new StreamReader(stream))
{
var request = await reader.ReadLineAsync();
- if (request == null)
+ //BUG
+ //TODO: Add proper warnings here if the content is empty, don't just throw an exception
+ //This may be a common occurence
+
+ if (String.IsNullOrWhiteSpace(request))
throw new Exception("Nothing retrieved");
Log.InfoFormat("[RETRIEVE] Got Connection {0}", request);
private bool _firstPoll = true;
private TaskCompletionSource<bool> _tcs;
+ private ConcurrentDictionary<string,DateTime> _lastSeen=new ConcurrentDictionary<string, DateTime>();
public void Start()
{
//Consider for deleteion only files modified before the PREVIOUS poll
//A user may perform a file creation or rename at roughly the same time as a poll. In such a case
//the new file will appear as deleted
- var previousPollTime = pollTime.Subtract(TimeSpan.FromMilliseconds(Settings.PollingInterval));
+ var previousPollTime = pollTime.Subtract(TimeSpan.FromMilliseconds(Settings.PollingInterval));
+ //Only consider files that are not being modified, ie they are in the Unchanged state
var deleteCandidates = FileState.Queryable.Where(state =>
state.Modified <= previousPollTime
- && state.FilePath.StartsWith(accountInfo.AccountPath)
- && state.FileStatus != FileStatus.Conflict).ToList();
+ && state.FilePath.StartsWith(accountInfo.AccountPath)
+ && state.FileStatus == FileStatus.Unchanged).ToList();
- //TODO: filesToDelete must take into account the Others container
+ //TODO: filesToDelete must take into account the Others container
var filesToDelete = (from deleteCandidate in deleteCandidates
let localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath)
let relativeFilePath = localFile.AsRelativeTo(accountInfo.AccountPath)
- where !cloudFiles.Any(r => r.RelativeUrlToFilePath(accountInfo.UserName) == relativeFilePath )
+ let agentActions = _agent.GetEnumerable()
+ where
+ !_lastSeen.ContainsKey(localFile.FullName)
+ && !cloudFiles.Any(r => r.RelativeUrlToFilePath(accountInfo.UserName) == relativeFilePath )
//Exclude files enqueued for uploading
//Large files will not appear on the server for multiple polls. They must not be marked as deleted
- && !_agent.GetEnumerable().Any(action => action.LocalFile.WithProperCapitalization().FullName == localFile.FullName)
+ && !agentActions.Any(action => action.LocalFile.WithProperCapitalization().FullName == localFile.FullName)
//Do NOT delete files modified since the previous poll
&& localFile.LastAccessTime < previousPollTime
select localFile).ToList();
+
//On the first run
if (_firstPoll)
using (new SessionScope(FlushAction.Never))
{
var state = StatusKeeper.GetStateByFilePath(localFile.FullName);
+ _lastSeen[localFile.FullName] = DateTime.Now;
//FileState.FindByFilePath(localFile.FullName);
//Common files should be checked on a per-case basis to detect differences, which is newer