20 using System.Collections.Generic;
34 #region Public properties 54 public Uri ReleaseInfoUri {
get;
protected set; }
58 #region Implementation of IReleaseInfo 62 public string Summary {
get;
protected set; }
64 public Uri DownloadUri {
get;
protected set; }
66 public string ExpectedHash {
get;
protected set; }
68 public string RawReleaseInfo {
get;
protected set; }
70 public ReleaseInfoStatus Status {
get;
protected set; }
72 public Exception Exception {
get;
protected set; }
77 if (ReleaseInfoUri == null)
79 Status = ReleaseInfoStatus.FailureToFetch;
80 throw new InvalidOperationException(
"Cannot fetch release information, URI missing");
82 using (_webClient =
new WebClient())
86 _webClient.DownloadStringCompleted += WebClient_DownloadStringCompleted;
87 var lockObject =
new Object();
90 _webClient.DownloadStringAsync(ReleaseInfoUri, lockObject);
91 Monitor.Wait(lockObject);
99 Status = ReleaseInfoStatus.FailureToFetch;
105 private void WebClient_DownloadStringCompleted(
object sender, DownloadStringCompletedEventArgs e)
109 Monitor.Pulse(e.UserState);
115 Logger.Info(
"WebClient_DownloadStringCompleted: Not cancelled and no error :-)");
116 RawReleaseInfo = e.Result;
117 Logger.Debug(
"WebClient_DownloadStringCompleted: \r\n{0}", RawReleaseInfo);
118 Status = Parse(RawReleaseInfo) ? ReleaseInfoStatus.InfoAvailable : ReleaseInfoStatus.FailureToParse;
122 Logger.Warn(
"WebClient_DownloadStringCompleted: Exception occurred while fetching release info");
123 Logger.Warn(e.Error);
124 Status = ReleaseInfoStatus.FailureToFetch;
130 Logger.Info(
"WebClient_DownloadStringCompleted: Fetching release info was cancelled");
131 Status = ReleaseInfoStatus.InfoUnavailable;
133 Logger.Info(
"WebClient_DownloadStringCompleted: Status: {0}", Status);
138 #region Implementation of ProcessModel 162 ReleaseInfoUri = releaseInfoUri;
169 protected override void OnCancelling()
172 if (_webClient != null && _webClient.IsBusy)
174 _webClient.CancelAsync();
180 #region Protected methods 182 protected virtual bool Parse(
string rawInfo)
185 using (StringReader r =
new StringReader(rawInfo))
190 string rawUri = r.ReadLine();
193 DownloadUri =
new Uri(rawUri.Replace(
"$VERSION", ReleaseVersion.ToString()));
196 ExpectedHash = r.ReadLine().Trim().Split(
' ')[0];
198 Summary = multi.
Text;
199 Status = ReleaseInfoStatus.InfoAvailable;
205 Status = ReleaseInfoStatus.FailureToParse;
212 protected virtual void SetDefaults()
214 ReleaseVersion = null;
216 Summary = String.Empty;
217 ExpectedHash = String.Empty;
222 #region Private fields 224 private WebClient _webClient;
230 private static NLog.Logger Logger {
get {
return _logger.Value; } }
232 private static readonly Lazy<
NLog.Logger> _logger =
new Lazy<
NLog.Logger>(() =>
NLog.LogManager.GetCurrentClassLogger());
Represents a text with multiple lines.
override bool Execute()
This method may be called by a ProcessViewModelBase-derived class in a worker task that wraps this me...
Interface for classes that fetch current release information.
virtual bool Fetch()
Updates the release information.
ReleaseInfo()
Creates a new ReleaseInfo object that can fetch release information from the internet.
string Text
Gets the multiline text as a single string.
ReleaseInfo(Uri releaseInfoUri)
Creates a new ReleaseInfo object that can fetch release information from the internet using the URI g...
Class that handles semantic versioning.
Fetches and digests release information.