+++ /dev/null
-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();
- }
- }
-}
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();
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;
}
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();
}
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;
}
}
+
/// <summary>
/// Copies headers from a Hammock RestClient to a WebClient