//This file was deleted while we were down. We should mark it as deleted
//We have to go through UpdateStatus here because the state object we are using
//was created by a different ORM session.
- UpdateStatus(fileState.Id,state=> state.FileStatus = FileStatus.Deleted);
+ FileState.UpdateStatus(fileState.Id,FileStatus.Deleted);
}
else
{
//If the hashes don't match the file was changed
if (fileState.Checksum != hashString)
{
- UpdateStatus(fileState.Id, state => state.FileStatus = FileStatus.Modified);
+ FileState.UpdateStatus(fileState.Id, FileStatus.Modified);
}
}
});
private string _pithosDataPath;
-
- public T GetStatus<T>(string path,Func<FileState,T> getter,T defaultValue )
- {
- if (String.IsNullOrWhiteSpace(path))
- throw new ArgumentNullException("path");
- if (!Path.IsPathRooted(path))
- throw new ArgumentException("path must be a rooted path", "path");
- if (getter == null)
- throw new ArgumentNullException("getter");
- Contract.EndContractBlock();
-
-
- try
- {
- var state = FileState.FindByFilePath(path);
- return state == null ? defaultValue : getter(state);
- }
- catch (Exception exc)
- {
- Log.ErrorFormat(exc.ToString());
- return defaultValue;
- }
- }
-
- /// <summary>
- /// Sets the status of a file, creating a new FileState entry if one doesn't already exist.
- /// </summary>
- /// <param name="path"></param>
- /// <param name="setter"></param>
- public void SetStatus(string path,Action<FileState> setter)
- {
- if (String.IsNullOrWhiteSpace(path))
- throw new ArgumentNullException("path", "path can't be empty");
- if (setter==null)
- throw new ArgumentNullException("setter", "setter can't be empty");
- Contract.EndContractBlock();
-
- _persistenceAgent.Post(() =>
- {
- using (new SessionScope())
- {
- var filePath = path.ToLower();
- var state = FileState.FindByFilePath(filePath);
- if (state != null)
- {
- setter(state);
- state.Save();
- }
- else
- {
- state = new FileState {FilePath = filePath};
- setter(state);
- state.Save();
- }
- }
- });
- }
-
- /// <summary>
- /// Sets the status of a file only if the file already exists
- /// </summary>
- /// <param name="path"></param>
- /// <param name="setter"></param>
- private void UpdateStatus(string path, Action<FileState> setter)
- {
- if (String.IsNullOrWhiteSpace(path))
- throw new ArgumentNullException("path");
- if (!Path.IsPathRooted(path))
- throw new ArgumentException("The path must be rooted", "path");
- if (setter == null)
- throw new ArgumentNullException("setter");
- Contract.EndContractBlock();
-
- Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
- Debug.Assert(!path.EndsWith(".ignore"));
-
- if (String.IsNullOrWhiteSpace(path))
- throw new ArgumentNullException("path", "path can't be empty");
-
- if (setter == null)
- throw new ArgumentNullException("setter", "setter can't be empty");
-
- _persistenceAgent.Post(() =>
- {
- using (new SessionScope())
- {
- var filePath = path.ToLower();
-
- var state = FileState.FindByFilePath(filePath);
- if (state == null)
- {
- Log.WarnFormat("[NOFILE] Unable to set status for {0}.", filePath);
- return;
- }
- setter(state);
- state.Save();
- }
-
- });
- }
-
- /// <summary>
- /// Sets the status of a specific state
- /// </summary>
- /// <param name="path"></param>
- /// <param name="setter"></param>
- private void UpdateStatus(Guid stateID, Action<FileState> setter)
- {
- if (setter == null)
- throw new ArgumentNullException("setter");
- Contract.EndContractBlock();
-
-
- _persistenceAgent.Post(() =>
- {
- using (new SessionScope())
- {
- var state = FileState.Find(stateID);
- if (state == null)
- {
- Log.WarnFormat("[NOFILE] Unable to set status for {0}.", stateID);
- return;
- }
- setter(state);
- state.Save();
- }
-
- });
- }
+
public FileOverlayStatus GetFileOverlayStatus(string path)
{
try
{
- var state = FileState.FindByFilePath(path);
- return state == null ? FileOverlayStatus.Unversioned : state.OverlayStatus;
+ var status = from state in FileState.Queryable
+ where state.FilePath ==path.ToLower()
+ select state.OverlayStatus;
+ return status.Any()? status.First():FileOverlayStatus.Unversioned;
}
catch (Exception exc)
{
throw new ArgumentException("The path must be rooted","path");
Contract.EndContractBlock();
- SetStatus(path.ToLower(),s=>s.OverlayStatus=overlayStatus);
+ _persistenceAgent.Post(() => FileState.StoreOverlayStatus(path.ToLower(),overlayStatus));
}
/*public void RemoveFileOverlayStatus(string path)
throw new ArgumentException("The newPath must be rooted", "newPath");
Contract.EndContractBlock();
- _persistenceAgent.Post(() =>
- InnerRenameFileOverlayStatus(oldPath, newPath));
- }
-
- private static void InnerRenameFileOverlayStatus(string oldPath, string newPath)
- {
- if (String.IsNullOrWhiteSpace(oldPath))
- throw new ArgumentNullException("oldPath");
- if (!Path.IsPathRooted(oldPath))
- throw new ArgumentException("The oldPath must be rooted", "oldPath");
- if (String.IsNullOrWhiteSpace(newPath))
- throw new ArgumentNullException("newPath");
- if (!Path.IsPathRooted(newPath))
- throw new ArgumentException("The newPath must be rooted", "newPath");
- Contract.EndContractBlock();
-
- var state = FileState.FindByFilePath(oldPath);
-
- if (state == null)
- {
- Log.WarnFormat("[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();
+ _persistenceAgent.Post(() =>FileState.RenameState(oldPath, newPath));
}
public void SetFileState(string path, FileStatus fileStatus, FileOverlayStatus overlayStatus)
throw new ArgumentException("The path must be rooted", "path");
Contract.EndContractBlock();
- UpdateStatus(path.ToLower(),state=>
- {
- state.FileStatus = fileStatus;
- state.OverlayStatus = overlayStatus;
- });
+ Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
+ Debug.Assert(!path.EndsWith(".ignore"));
+
+ _persistenceAgent.Post(() => FileState.UpdateStatus(path.ToLower(), fileStatus, overlayStatus));
}
public void StoreInfo(string path,ObjectInfo objectInfo)
//Forgetting to use a sessionscope results in two sessions being created, one by
//FirstOrDefault and one by Save()
var state =FileState.FindByFilePath(filePath);
+
//Create a new empty state object if this is a new file
state = state ?? new FileState();
public void SetFileStatus(string path, FileStatus status)
- {
- UpdateStatus(path.ToLower(), state=>state.FileStatus = status);
+ {
+ if (String.IsNullOrWhiteSpace(path))
+ throw new ArgumentNullException("path");
+ if (!Path.IsPathRooted(path))
+ throw new ArgumentException("The path must be rooted", "path");
+ Contract.EndContractBlock();
+
+ _persistenceAgent.Post(() => FileState.UpdateStatus(path.ToLower(), status));
}
public FileStatus GetFileStatus(string path)
throw new ArgumentException("The path must be rooted", "path");
Contract.EndContractBlock();
- var state = FileState.FindByFilePath(path);
- return (state==null)?FileStatus.Missing:state.FileStatus ;
+ var status = from r in FileState.Queryable
+ where r.FilePath == path.ToLower()
+ select r.FileStatus;
+ return status.Any()?status.First(): FileStatus.Missing;
}
public void ClearFileStatus(string path)
throw new ArgumentException("The path must be rooted", "path");
Contract.EndContractBlock();
- _persistenceAgent.Post(() =>
- {
- using (new SessionScope())
- {
- var state = FileState.FindByFilePath(path);
- if (state == null)
- {
- Log.WarnFormat("[NOFILE] Unable to set checkesum for {0}.", path);
- return;
- }
- state.Checksum = checksum;
- state.Update();
- }
- });
+ _persistenceAgent.Post(() => FileState.UpdateChecksum(path.ToLower(), checksum));
}
}
}
+ public static void StoreFileStatus(string absolutePath, FileStatus newStatus)
+ {
+ if (string.IsNullOrWhiteSpace(absolutePath))
+ throw new ArgumentNullException("absolutePath");
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set FileStatus= :status where FilePath = :path ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetString("path", absolutePath.ToLower())
+ .SetEnum("status", newStatus)
+ .ExecuteUpdate();
+ if (updatedEntities == 0)
+ {
+ var newState = new FileState { FilePath = absolutePath, Id = Guid.NewGuid(), FileStatus = newStatus };
+ newState.CreateAndFlush();
+ }
+ return null;
+ }, null);
+
+ }
+
+ public static void StoreOverlayStatus(string absolutePath, FileOverlayStatus newStatus)
+ {
+ if (string.IsNullOrWhiteSpace(absolutePath))
+ throw new ArgumentNullException("absolutePath");
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set OverlayStatus= :status where FilePath = :path ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetString("path", absolutePath.ToLower())
+ .SetEnum("status", newStatus)
+ .ExecuteUpdate();
+ if (updatedEntities == 0)
+ {
+ var newState = new FileState { FilePath = absolutePath, Id = Guid.NewGuid(), OverlayStatus = newStatus };
+ newState.CreateAndFlush();
+ }
+ return null;
+ }, null);
+
+ }
+
+ public static void UpdateStatus(string absolutePath, FileStatus fileStatus, FileOverlayStatus overlayStatus)
+ {
+ if (string.IsNullOrWhiteSpace(absolutePath))
+ throw new ArgumentNullException("absolutePath");
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set OverlayStatus= :overlayStatus, FileStatus= :fileStatus where FilePath = :path ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetString("path", absolutePath.ToLower())
+ .SetEnum("fileStatus", fileStatus)
+ .SetEnum("overlayStatus", overlayStatus)
+ .ExecuteUpdate();
+ return null;
+ }, null);
+
+ }
+ public static void UpdateStatus(string absolutePath, FileStatus fileStatus)
+ {
+ if (string.IsNullOrWhiteSpace(absolutePath))
+ throw new ArgumentNullException("absolutePath");
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set FileStatus= :fileStatus where FilePath = :path ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetString("path", absolutePath.ToLower())
+ .SetEnum("fileStatus", fileStatus)
+ .ExecuteUpdate();
+ return updatedEntities;
+ }, null);
+
+ }
+
+ public static void RenameState(string oldPath, string newPath)
+ {
+ if (string.IsNullOrWhiteSpace(oldPath))
+ throw new ArgumentNullException("oldPath");
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set FilePath= :newPath where FilePath = :oldPath ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetString("oldPath", oldPath.ToLower())
+ .SetString("newPath", newPath.ToLower())
+ .ExecuteUpdate();
+ return updatedEntities;
+ }, null);
+
+ }
+
+ public static void UpdateStatus(Guid id, FileStatus fileStatus)
+ {
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set FileStatus= :fileStatus where Id = :id ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetGuid("id", id)
+ .SetEnum("fileStatus", fileStatus)
+ .ExecuteUpdate();
+ return null;
+ }, null);
+
+ }
+
+ public static void UpdateChecksum(string absolutePath, string checksum)
+ {
+ if (string.IsNullOrWhiteSpace(absolutePath))
+ throw new ArgumentNullException("absolutePath");
+ Contract.EndContractBlock();
+
+ Execute((session, instance) =>
+ {
+ const string hqlUpdate = "update FileState set Checksum= :checksum where FilePath = :path ";
+ var updatedEntities = session.CreateQuery(hqlUpdate)
+ .SetString("path", absolutePath.ToLower())
+ .SetString("checksum", checksum)
+ .ExecuteUpdate();
+ return null;
+ }, null);
+
+ }
+
public static void ChangeRootPath(string oldPath,string newPath)
{
if (String.IsNullOrWhiteSpace(oldPath))
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Pithos.Setup.x86", "Pithos.Setup.x86\Pithos.Setup.x86.vdproj", "{0D7E50F2-D7B4-4458-AA01-2CAC0F386737}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkTests", "Tests\NetworkTests\NetworkTests.csproj", "{052D04DA-28FE-471F-96FD-BC1E92BF2A54}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug All|Any CPU = Debug All|Any CPU
{0D7E50F2-D7B4-4458-AA01-2CAC0F386737}.Test|Mixed Platforms.ActiveCfg = Release
{0D7E50F2-D7B4-4458-AA01-2CAC0F386737}.Test|x64.ActiveCfg = Release
{0D7E50F2-D7B4-4458-AA01-2CAC0F386737}.Test|x86.ActiveCfg = Release
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug All|Any CPU.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug All|Mixed Platforms.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug All|Mixed Platforms.Build.0 = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug All|x64.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug All|x86.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug All|x86.Build.0 = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug|Any CPU.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug|x64.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug|x86.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Debug|x86.Build.0 = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Premium Debug|Any CPU.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Premium Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Premium Debug|Mixed Platforms.Build.0 = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Premium Debug|x64.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Premium Debug|x86.ActiveCfg = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Premium Debug|x86.Build.0 = Debug|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Release|Any CPU.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Release|Mixed Platforms.Build.0 = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Release|x64.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Release|x86.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Release|x86.Build.0 = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Test|Any CPU.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Test|Mixed Platforms.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Test|Mixed Platforms.Build.0 = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Test|x64.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Test|x86.ActiveCfg = Release|x86
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54}.Test|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
{2CFE2DF1-20AE-47E2-B1BB-36B974600BE1} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
{E027200B-C26A-4877-BFD9-1A18CF5DF2F4} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
{F9AF3E97-BCB7-46B7-8014-7FC858AEE9BA} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
- {052D04DA-28FE-471F-96FD-BC1E92BF2A54} = {B5DD7C4D-D396-4C55-A8D5-DCFE865AA095}
EndGlobalSection
EndGlobal