-// -----------------------------------------------------------------------
-// <copyright file="DeleteAgent.cs" company="GRNET">
-// Copyright 2011-2012 GRNET S.A. All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or
-// without modification, are permitted provided that the following
-// conditions are met:
-//
-// 1. Redistributions of source code must retain the above
-// copyright notice, this list of conditions and the following
-// disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials
-// provided with the distribution.
-//
-// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
-// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// The views and conclusions contained in the software and
-// documentation are those of the authors and should not be
-// interpreted as representing official policies, either expressed
-// or implied, of GRNET S.A.
-// </copyright>
-// -----------------------------------------------------------------------
-
+#region
+/* -----------------------------------------------------------------------
+ * <copyright file="DeleteAgent.cs" company="GRNet">
+ *
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ * </copyright>
+ * -----------------------------------------------------------------------
+ */
+#endregion
using System.Collections.Concurrent;
using System.ComponentModel.Composition;
using System.Diagnostics.Contracts;
using System.IO;
using System.Net;
+using System.Reflection;
using System.Threading.Tasks.Dataflow;
using Pithos.Interfaces;
using Pithos.Network;
/// <summary>
/// The Delete Agent is used to delete files from the Pithos server with high priority,
- /// blocking the network agent through the PauseEvent until all pending deletions complete
+ /// blocking the network agent through the ProceedEvent until all pending deletions complete
/// </summary>
[Export]
public class DeleteAgent
{
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
[Import]
public IStatusKeeper StatusKeeper { get; set; }
-
- private static readonly ILog Log = LogManager.GetLogger("DeleteAgent");
+
+ public IStatusNotification StatusNotification { get; set; }
//A separate agent is used to execute delete actions immediatelly;
private readonly ActionBlock<CloudDeleteAction> _deleteAgent;
- //The Pause event stops the network agent to give priority to the deletion agent
+ //The Proceed event signals the the network agent to proceed with processing.
+ //Essentially this event pauses the network agent to give priority to the deletion agent
//Initially the event is signalled because we don't need to pause
- private readonly AsyncManualResetEvent _pauseEvent = new AsyncManualResetEvent(true);
+ private readonly AsyncManualResetEvent _proceedEvent = new AsyncManualResetEvent(true);
- public AsyncManualResetEvent PauseEvent
+ public AsyncManualResetEvent ProceedEvent
{
- get { return _pauseEvent; }
+ get { return _proceedEvent; }
}
//Deleted file names are stored in memory so we can check that a file has already been deleted.
var accountInfo = action.AccountInfo;
- using (log4net.ThreadContext.Stacks["NETWORK"].Push("PROCESS"))
+ using (log4net.ThreadContext.Stacks["Operation"].Push("ProcessDelete"))
{
Log.InfoFormat("[ACTION] Start Processing {0}", action);
var key = GetFileKey(action.CloudFile);
_deletedFiles[key] = DateTime.Now;
- _pauseEvent.Reset();
+ _proceedEvent.Reset();
// and then delete the file from the server
DeleteCloudFile(accountInfo, cloudFile);
{
//Set the event when all delete actions are processed
if (_deleteAgent.InputCount == 0)
- _pauseEvent.Set();
+ _proceedEvent.Set();
}
}
_deleteAgent.Post(action);
}
- private void DeleteCloudFile(AccountInfo accountInfo, ObjectInfo cloudFile)
+ public void DeleteCloudFile(AccountInfo accountInfo, ObjectInfo cloudFile)
{
if (accountInfo == null)
throw new ArgumentNullException("accountInfo");
var fileAgent = GetFileAgent(accountInfo);
- using (ThreadContext.Stacks["DeleteCloudFile"].Push("Delete"))
+ using (ThreadContext.Stacks["Operation"].Push("DeleteCloudFile"))
{
var fileName = cloudFile.RelativeUrlToFilePath(accountInfo.UserName);
var info = fileAgent.GetFileSystemInfo(fileName);
var fullPath = info.FullName.ToLower();
- StatusKeeper.SetFileOverlayStatus(fullPath, FileOverlayStatus.Modified);
+ StatusKeeper.SetFileOverlayStatus(fullPath, FileOverlayStatus.Modified).Wait();
var account = cloudFile.Account ?? accountInfo.UserName;
var container = cloudFile.Container;//?? FolderConstants.PithosContainer;
client.DeleteObject(account, container, cloudFile.Name);
StatusKeeper.ClearFileStatus(fullPath);
+ StatusNotification.Notify(new CloudNotification{Data=cloudFile});
}
}