/// <summary> /// Initializes a new instance of the <see cref="State"/> class. /// </summary> /// <param name="file">The file.</param> public State(string file) { this.stateFile = file; Read(); job = GetCurrentJob(); networks = GetCurrentNetworks(); }
private Job GetCurrentJob() { if (data["job"] == null) return null; Job currentJob = new Job(); currentJob.Name = data["job"]["name"].Value; currentJob.Version = data["job"]["version"].Value; currentJob.SHA1 = data["job"]["sha1"].Value; currentJob.Template = data["job"]["template"].Value; currentJob.BlobstoreId = data["job"]["blobstore_id"].Value; return currentJob; }
/// <summary> /// Writes the specified new state. /// </summary> /// <param name="newState">The new state.</param> public void Write(dynamic newState) { try { File.WriteAllText(stateFile, newState.ToString()); } catch (Exception ex) { throw new StateException(string.Format(CultureInfo.InvariantCulture, "Cannot write agent state file {0}:", stateFile), ex); } //This is because we do not support multiple documents in the same yaml data = newState; job = GetCurrentJob(); networks = GetCurrentNetworks(); File.WriteAllText(stateFile, data.ToString()); }