Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ private void GetRecoveryPlanFile(
var json = JsonConvert.SerializeObject(
recoveryPlan,
Formatting.Indented,
new RecoveryPlanActionDetailsConverter());
new RecoveryPlanActionDetailsConverter(),
new RecoveryPlanProviderSpecificDetailsConverter());
file.WriteLine(json);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public override void ExecuteSiteRecoveryCmdlet()
{
this.recoveryPlan = JsonConvert.DeserializeObject<RecoveryPlan>(
file.ReadToEnd(),
new RecoveryPlanActionDetailsConverter());
new RecoveryPlanActionDetailsConverter(),
new RecoveryPlanProviderSpecificDetailsConverter());
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,77 @@ public override void WriteJson(

}

/// <summary>
/// Custom Convertor for deserializing RecoveryPlanProviderSpecificDetails(RecoveryPlan) object
/// </summary>
[JsonConverter(typeof(RecoveryPlanProviderSpecificDetails))]
public class RecoveryPlanProviderSpecificDetailsConverter :
JsonCreationConverter<RecoveryPlanProviderSpecificDetails>
{
/// <summary>
/// Gets a value indicating whether this Newtonsoft.Json.JsonConverter can write JSON
/// </summary>
public override bool CanWrite => true;

/// <summary>
/// Creates RecoveryPlanProviderSpecific details.
/// </summary>
/// <param name="objectType">Object type.</param>
/// <param name="jObject">JSON object that will be deserialized.</param>
/// <returns>Returns recovery plan action custom details.</returns>
protected override RecoveryPlanProviderSpecificDetails Create(
Type objectType,
JObject jObject)
{
RecoveryPlanProviderSpecificDetails outputType = null;
var actionType = (RecoveryPlanProviderType)Enum.Parse(
typeof(RecoveryPlanProviderType),
jObject.Value<string>(Constants.InstanceType));

switch (actionType)
{
case RecoveryPlanProviderType.A2A:
outputType = new RecoveryPlanA2ADetails();
break;
}

return outputType;
}

/// <summary>
/// Writes the JSON representation of the object.
/// </summary>
/// <param name="writer">The Newtonsoft.Json.JsonWriter to write to.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(
JsonWriter writer,
object value,
JsonSerializer serializer)
{
JToken t = JToken.FromObject(value);
string instanceType = null;
if (value != null)
{
if (string.Compare(value.GetType().ToString(), typeof(RecoveryPlanA2ADetails).ToString()) == 0)
{
instanceType = RecoveryPlanProviderType.A2A.ToString();
}
}

if (t.Type != JTokenType.Object)
{
t.WriteTo(writer);
}
else
{
JObject o = (JObject)t;
IList<string> propertyNames = o.Properties().Select(p => p.Name).ToList();
o.AddFirst(new JProperty(Constants.InstanceType, instanceType));
o.WriteTo(writer);
}
}
}
/// <summary>
/// Recovery Plan Action Types
/// </summary>
Expand All @@ -746,4 +817,12 @@ public enum RecoveryPlanActionDetailsType
ManualActionDetails,
ScriptActionDetails
}

/// <summary>
/// Recovery Plan Provider Types
/// </summary>
public enum RecoveryPlanProviderType
{
A2A
}
}
1 change: 1 addition & 0 deletions src/RecoveryServices/RecoveryServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Azure Site Recovery support for creating recovery plan for zone to zoen replication from xml input.

## Version 2.9.0
* Azure Site Recovery added support for protecting proximity placement group virtual machines for Azure to Azure provider.
Expand Down