Added Tags retrieval
authorPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 22 Aug 2011 16:43:44 +0000 (19:43 +0300)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Mon, 22 Aug 2011 16:43:44 +0000 (19:43 +0300)
trunk/Pithos.Core/Pithos.Core.csproj
trunk/Pithos.Core/StatusChecker.cs [deleted file]
trunk/Pithos.Core/StatusKeeper.cs
trunk/Pithos.Interfaces/ICloudClient.cs
trunk/Pithos.Network/CloudFilesClient.cs

index 8b73aa7..88acfe1 100644 (file)
@@ -97,6 +97,9 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\Libraries\Microsoft.WindowsAPICodePack.dll</HintPath>
     </Reference>
+    <Reference Include="Microsoft.WindowsAPICodePack.Shell">
+      <HintPath>..\Libraries\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
+    </Reference>
     <Reference Include="NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
       <HintPath>..\Libraries\NHibernate.dll</HintPath>
     </Reference>
diff --git a/trunk/Pithos.Core/StatusChecker.cs b/trunk/Pithos.Core/StatusChecker.cs
deleted file mode 100644 (file)
index 5657d52..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.ComponentModel.Composition;
-using System.Diagnostics;
-using System.Diagnostics.Contracts;
-using System.IO;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-using Castle.ActiveRecord;
-using Castle.ActiveRecord.Framework;
-using Castle.ActiveRecord.Framework.Config;
-using Pithos.Interfaces;
-
-namespace Pithos.Core
-{
-    [Export(typeof(IStatusChecker)),Export(typeof(IStatusKeeper))]
-    public class StatusChecker:IStatusChecker,IStatusKeeper
-    {
-        [System.ComponentModel.Composition.Import]
-        public IPithosSettings Settings { get; set; }
-
-
-        public StatusChecker()
-        {
-            var source = new XmlConfigurationSource("DbConfig.xml");
-            ActiveRecordStarter.Initialize(source,typeof(FileState));            
-            
-            if (!File.Exists("pithos.db"))
-                ActiveRecordStarter.CreateSchema();            
-            
-        }
-
-        public FileOverlayStatus GetFileOverlayStatus(string path)
-        {
-            try
-            {
-                var state = FileState.TryFind(path);
-                return state == null ? FileOverlayStatus.Unversioned : state.OverlayStatus;
-            }
-            catch (Exception exc)
-            {
-                Trace.TraceError(exc.ToString());
-                return FileOverlayStatus.Unversioned;
-            }
-        }
-
-        public IEnumerable<string> StoreUnversionedFiles(ParallelQuery<string> paths)
-        {            
-            var existingFiles =  FileState.FindAll().Select(state=>state.FilePath);
-
-            var newFiles = (from file in paths.Except(existingFiles.AsParallel())
-                            select new FileState
-                                       {
-                                           FilePath = file,
-                                           OverlayStatus = FileOverlayStatus.Unversioned,
-                                           FileStatus=FileStatus.Created,     
-                                           Checksum=Signature.CalculateHash(file)
-                                       }
-                           ).AsParallel();
-            
-            var files=new ConcurrentBag<string>();
-            newFiles.ForAll(state=>
-                                {
-                                    state.Save();
-                                    files.Add(state.FilePath);
-                                });
-            
-            return files.GetConsumingEnumerable();
-
-        }
-
-/*
-        private static Task<string> CalculateHashAsync(string path)
-        {
-
-            string hash;
-            using (var hasher = MD5.Create())
-            {
-                return FileAsync.ReadAllBytes(path)
-                    .ContinueWith(t => hasher.ComputeHash(t.Result))
-                    .ContinueWith(t =>
-                                      {
-                                          //var hashBuilder = new StringBuilder();
-                                          return (from byte b in t.Result.AsParallel()
-                                                  select b.ToString("x2").ToLower()).Aggregate((s1, s2) => s1 + s2);                                         
-                                      });
-            }
-            /*using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true))
-            {
-                
-                stream.ReadAllBytes()
-                    .ContinueWith(result => hasher.ComputeHash(result.Result))
-                    .;
-                var hashBytes = hasher.ComputeHash(stream);
-                var hashBuilder = new StringBuilder();
-                foreach (byte b in hasher.ComputeHash(stream))
-                    hashBuilder.Append(b.ToString("x2").ToLower());
-                hash = hashBuilder.ToString();
-
-            }
-            return hash;#1#
-        }
-*/
-
-
-        private PithosStatus _pithosStatus=PithosStatus.InSynch;
-        public void SetPithosStatus(PithosStatus status)
-        {
-            _pithosStatus = status;
-        }
-
-        public PithosStatus GetPithosStatus()
-        {
-            return _pithosStatus;
-        }
-
-        public void SetFileOverlayStatus(string path, FileOverlayStatus overlayStatus)
-        {
-            var state = FileState.TryFind(path);
-            if (state != null)
-            {
-                state.OverlayStatus = overlayStatus;
-                state.Update();
-            }
-            else
-            {
-                state=new FileState{FilePath=path,OverlayStatus=overlayStatus};
-                state.Save();
-            }
-        }
-
-        public void RemoveFileOverlayStatus(string path)
-        {
-            FileState.DeleteAll(new[] {path});            
-        }
-
-        public void RenameFileOverlayStatus(string oldPath, string newPath)
-        {
-            var state = FileState.Find(oldPath);
-            //TODO: This will cause problems if path is used as a key in relationships
-            state.FilePath = newPath;
-            state.Update();
-        }
-
-        public void SetFileStatus(string path, FileStatus status)
-        {
-            var state = FileState.Find(path);
-            state.FileStatus = status;
-        }
-
-        public FileStatus GetFileStatus(string path)
-        {
-            var state = FileState.TryFind(path);
-            return (state==null)?FileStatus.Missing:state.FileStatus ;
-        }
-
-        public void ClearFileStatus(string path)
-        {
-            //TODO:SHOULDN'T need both clear file status and remove overlay status
-            FileState.DeleteAll(new[] { path });   
-        }
-
-        public void UpdateFileChecksum(string path, string checksum)
-        {
-            var state = FileState.Find(path);
-            state.Checksum = checksum;
-            state.Update();
-        }
-    }
-}
index 29548bc..aa68980 100644 (file)
@@ -173,7 +173,12 @@ namespace Pithos.Core
 
         private static void InnerRenameFileOverlayStatus(string oldPath, string newPath)
         {
-            var state = FileState.Find(oldPath);
+            var state = FileState.TryFind(oldPath);
+            if (state == null)
+            {
+                Trace.TraceWarning("[NOFILE] Unable to set status for {0}.", oldPath);
+                return;
+            }
             //NOTE: This will cause problems if path is used as a key in relationships
             state.FilePath = newPath;
             state.Update();
@@ -187,7 +192,12 @@ namespace Pithos.Core
 
         private static void InnerSetFileStatus(string path, FileStatus status)
         {
-            var state = FileState.Find(path);
+            var state = FileState.TryFind(path.ToLower());
+            if (state == null)
+            {
+                Trace.TraceWarning("[NOFILE] Unable to set status for {0}.", path);
+                return;
+            }
             state.FileStatus = status;
         }
 
@@ -200,12 +210,18 @@ namespace Pithos.Core
         public void ClearFileStatus(string path)
         {
             //TODO:SHOULDN'T need both clear file status and remove overlay status
-            FileState.DeleteAll(new[] { path });   
+            _statusUpdateQueue.Add(()=>
+                FileState.DeleteAll(new[] { path.ToLower() }));   
         }
 
         public void UpdateFileChecksum(string path, string checksum)
         {
-            var state = FileState.Find(path);
+            var state = FileState.TryFind(path);
+            if (state == null)
+            {
+                Trace.TraceWarning("[NOFILE] Unable to set checkesum for {0}.",path);
+                return;
+            }
             state.Checksum = checksum;
             state.Update();
         }
index 7b6b5bf..dd293cd 100644 (file)
@@ -211,6 +211,13 @@ namespace Pithos.Interfaces
         public string Content_Type { get; set; }
         public DateTime Last_Modified { get; set; }
 
+        private Dictionary<string, string> _tags=new Dictionary<string, string>();
+        public Dictionary<string, string> Tags
+        {
+            get { return _tags; }
+            set { _tags = value; }
+        }
+
         public static ObjectInfo Empty=new ObjectInfo {Name=String.Empty,Hash=String.Empty,Bytes=0,Content_Type=String.Empty,Last_Modified=DateTime.MinValue};
     }
 }
index b24937f..032b2c6 100644 (file)
@@ -266,12 +266,18 @@ namespace Pithos.Network
                 case HttpStatusCode.OK:
                 case HttpStatusCode.NoContent:
                     var keys = response.Headers.AllKeys.AsQueryable();
+                    var tags=(from key in keys
+                             where key.StartsWith("X-Object-Meta-")
+                             let name=key.Substring(14)
+                             select new {Name=name,Value=response.Headers[name]})
+                             .ToDictionary(t=>t.Name,t=>t.Value);
                     return new ObjectInfo
                                {
                                    Name = objectName,
                                    Bytes = long.Parse(GetHeaderValue("Content-Length", response, keys)),
                                    Hash = GetHeaderValue("ETag", response, keys),
-                                   Content_Type = GetHeaderValue("Content-Type", response, keys)
+                                   Content_Type = GetHeaderValue("Content-Type", response, keys),
+                                   Tags=tags
                                };
                 case HttpStatusCode.NotFound:
                     return ObjectInfo.Empty;
@@ -455,6 +461,7 @@ namespace Pithos.Network
             }                
 
         }
+       
 
         /// <summary>
         /// Copies headers from a Hammock RestClient to a WebClient