Last active
April 4, 2016 18:17
-
-
Save knorrus/c2575fd893f6432d2ee15e2b1750b3b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PendingResourceMigrationRequest | |
{ | |
public UserFile UserFile { get; } | |
public PendingResourceMigrationRequest(UserFile userUserFile) | |
{ | |
UserFile = userUserFile; | |
} | |
public override string ToString() | |
{ | |
return $"journal event: pending {UserFile} migration"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tracker : ReceivePersistentActor | |
{ | |
public override string PersistenceId => $"some-stable-id"; | |
public Tracker() | |
{ | |
Become(Working); | |
} | |
private void Working() | |
{ | |
Recover<PendingResourceMigrationRequest>(jornaledEvent => | |
{ | |
_logger.Info($"{Self.Path} Recovery event: {jornaledEvent.UserFile}"); //UserFile is always null! | |
}); | |
Command<UserFile>(userFile => | |
{ | |
var evt = new PendingResourceMigrationRequest(userFile); | |
PersistAsync(evt, journaledEvent => | |
{ | |
_logger.Debug($"{Self.Path} Tracked {journaledEvent}"); | |
}); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserFile : IEquatable<UserFile> | |
{ | |
public string UserId { get; } | |
public string OldPath { get; } | |
public string NewPath { get; } | |
public UserFile(string userId, string oldPath, string newPath) | |
{ | |
UserId = userId; | |
OldPath = oldPath; | |
NewPath = newPath; | |
} | |
public bool Equals(UserFile other) | |
{ | |
return string.Equals(UserId, other.UserId, StringComparison.OrdinalIgnoreCase) && | |
string.Equals(OldPath, other.OldPath, StringComparison.OrdinalIgnoreCase) && | |
string.Equals(NewPath, other.NewPath, StringComparison.OrdinalIgnoreCase); | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) return false; | |
if (ReferenceEquals(this, obj)) return true; | |
if (obj.GetType() != this.GetType()) return false; | |
return Equals((UserFile) obj); | |
} | |
public override int GetHashCode() | |
{ | |
unchecked | |
{ | |
var hashCode = (UserId != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(UserId) : 0); | |
hashCode = (hashCode*397) ^ (OldPath != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(OldPath) : 0); | |
hashCode = (hashCode*397) ^ (NewPath != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(NewPath) : 0); | |
return hashCode; | |
} | |
} | |
public override string ToString() | |
{ | |
return $"user (id: {UserId}) file {OldPath} --> {NewPath}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment