Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class PendingResourceMigrationRequest
{
public UserFile UserFile { get; }
public PendingResourceMigrationRequest(UserFile userUserFile)
{
UserFile = userUserFile;
}
public override string ToString()
{
return $"journal event: pending {UserFile} migration";
}
}
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}");
});
});
}
}
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
You can’t perform that action at this time.