public static ConfiguredActivityModel FromConfiguredActivity(ConfiguredActivity activity) { var model = new ConfiguredActivityModel { ActivityName = activity.ActivityName, Description = activity.Description, Config = activity.Config, Async = activity.Async }; if (activity.Async) { if (activity.AsyncDelay > 0) { var delay = TimeSpan.FromSeconds(activity.AsyncDelay); model.AsyncDelayDays = delay.Days; model.AsyncDelayHours = delay.Hours; model.AsyncDelayMinutes = delay.Minutes; model.AsyncDelaySeconds = delay.Seconds; } } return model; }
public ConfiguredActivity ToConfiguredActivity() { var activity = new ConfiguredActivity(ActivityName, Description) { Config = Config, Async = Async }; if (activity.Async) { var delay = new TimeSpan(AsyncDelayDays, AsyncDelayHours, AsyncDelayMinutes, AsyncDelaySeconds); activity.AsyncDelay = (int)delay.TotalSeconds; } return activity; }
private XElement SerializeActivity(ConfiguredActivity activity) { var element = new XElement("activity", new XAttribute("name", activity.ActivityName), new XAttribute("description", activity.Description), new XAttribute("async", activity.Async) ); if (activity.Async) { element.Add("async-delay", activity.AsyncDelay); } if (activity.Config != null) { var configElement = new XElement("config"); configElement.Add(new XCData(activity.Config)); element.Add(configElement); } return element; }
private ConfiguredActivity DeserializeActivity(XElement element) { var name = element.Attribute("name").Value; var desc = element.Attribute("description").Value; var activity = new ConfiguredActivity(name, desc); var asyncAttr = element.Attribute("async"); if (asyncAttr != null) { activity.Async = Convert.ToBoolean(asyncAttr.Value); } if (activity.Async) { var delayAttr = element.Attribute("async-delay"); if (delayAttr != null) { activity.AsyncDelay = Convert.ToInt32(delayAttr.Value); } } var configElement = element.Element("config"); if (configElement != null) { activity.Config = configElement.Value; } return activity; }