public static ShellData ParseData(string[] args) { ShellData result = new ShellData(); if (args.Length % 2 != 0) { throw new ArgumentException($"Length of params {args.Length} must be odd"); } for (int i = 0; i < args.Length; i += 2) { var name = args[i].Trim('-', ' ', '/', '\\'); if (!AllowedTokens.Select(p => p.Name).Contains(name.ToLower())) { throw new ArgumentException($"{args[i]} is not allowed value"); } try { result.AssignValue(name, args[i + 1]); } catch (Exception e) { throw e; } } try { result.ValidParams(); } catch (Exception e) { throw e; } return(result); }
public static string ShellDataToCmdString(ShellData shellData) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("-{0} \"{1}\" ", TokenKey.FName, shellData.FileName); sb.AppendFormat("-{0} {1} ", TokenKey.ActionType, shellData.AT == ActionType.CMDScript ? "cmd" : "csharp"); sb.AppendFormat("-{0} {1} ", TokenKey.CommandType, shellData.CT == CommandType.OneTime ? "o" : "r"); sb.AppendFormat("-{0} {1} ", TokenKey.RepType, shellData.RT == RepeatableType.Monotonous ? "m" : "s"); if (shellData.CT == CommandType.OneTime) { sb.AppendFormat("-{0} {1} ", TokenKey.OnetimeDate, TimeHelper.DateTimeToUnixTimestamp(shellData.OTD)); } else { if (shellData.RT == RepeatableType.Monotonous) { sb.AppendFormat("-{0} {1} ", TokenKey.MonPeriod, shellData.MP); sb.AppendFormat("-{0} {1} ", TokenKey.MonStartTime, TimeHelper.DateTimeToUnixTimestamp(shellData.MST)); sb.AppendFormat("-{0} {1} ", TokenKey.MonRepeatCount, shellData.MRC); } else { sb.AppendFormat("-{0} {1} ", TokenKey.SpecificDates, string.Join(".", shellData.SD.Select(p => TimeHelper.DateTimeToUnixTimestamp(p)).ToArray())); } } sb.AppendFormat("-{0} \"{1}\" ", TokenKey.Name, shellData.Name); if (shellData.Autor != null) { sb.AppendFormat("-{0} \"{1}\" ", TokenKey.Autor, shellData.Autor); } if (shellData.Descr != null) { sb.AppendFormat("-{0} \"{1}\" ", TokenKey.Descr, shellData.Descr); } if (shellData.Refs != null) { sb.AppendFormat("-{0} \"{1}\" ", TokenKey.Refs, string.Join("_", shellData.Refs)); } return(sb.ToString()); }