/// <summary> /// Save the profile. /// </summary> /// <param name="Name"></param> public static void Save <T>(IAlignmentArgs Args, string Name) where T : IAlignmentArgsProfile, new() { if (Name == null || Name == "") { throw new ArgumentException("the name of profile can not be empty."); } // check the file name if (Name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { throw new InvalidDataException("the name of profile contains invalid chars."); } // validate the arguments, save is not allowed if some of the arguments are in error format. Args.Validate(); // create the full path var path = string.Join("\\", PROFILE_FOLDER, Args.PresetProfileFolder); var filename = string.Join("\\", path, $"{Name}.json"); // if the directory does not exist, create it. if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } var profile = new T(); profile.FromArgsInstance(Args); var jsonstr = JsonConvert.SerializeObject(profile); File.WriteAllText(filename, jsonstr, new UTF8Encoding()); }
/// <summary> /// Load the specifed profile. /// </summary> /// <param name="Name">The name of the profile</param> /// <returns></returns> public static IAlignmentArgsProfile Load <T>(IAlignmentArgs Args, string Name) where T : IAlignmentArgsProfile, new() { if (Name != "") { var path = string.Join("\\", PROFILE_FOLDER, Args.PresetProfileFolder, $"{Name}.json"); if (File.Exists(path)) { var jsonstr = File.ReadAllText(path); var profile = JsonConvert.DeserializeObject <T>(jsonstr); // validate the content of profile by hash string if (profile.Validate()) { return(profile); } else { throw new Exception("the checksum is error."); } } else { throw new FileNotFoundException($"the profile {Name} was not found."); } } else { throw new Exception("the name of the profile can not be empty."); } }
public override void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { var targ = Args as Profile1DArgs; targ.IsEnabled = this.IsEnable; targ.Interval = this.Interval; targ.Range = this.ScanRange; targ.Order = this.ScanOrder; }
public override void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { var targ = Args as FastRotatingScanArgs; targ.AxisRotating = Service.FindLogicalAxisByHashString(this.AxisRotating); targ.AxisLinear = Service.FindLogicalAxisByHashString(this.AxisLinear); targ.LinearInterval = this.LinearInterval; targ.LinearRange = this.LinearScanRange; targ.Pitch = this.Pitch; }
public override void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { var targ = Args as SnakeRouteScanArgs; targ.Axis = Service.FindLogicalAxisByHashString(this.Axis); targ.Axis2 = Service.FindLogicalAxisByHashString(this.Axis2); targ.AxisRestriction = this.ScanRange; targ.Axis2Restriction = this.ScanRange2; targ.ScanInterval = this.Interval; targ.MoveSpeed = this.MoveSpeed; }
public override void FromArgsInstance(IAlignmentArgs Args) { var targ = Args as SpiralScanArgs; this.Axis = targ.Axis.HashString; this.Axis2 = targ.Axis2.HashString; this.Interval = targ.Interval; this.Range = targ.Range; this.Speed = targ.MoveSpeed; this.HashString = this.GetHashString(); }
public override void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { var targ = Args as SpiralScanArgs; targ.Axis = Service.FindLogicalAxisByHashString(this.Axis); targ.Axis2 = Service.FindLogicalAxisByHashString(this.Axis2); targ.Interval = this.Interval; targ.Range = this.Range; targ.MoveSpeed = this.Speed; }
public override void FromArgsInstance(IAlignmentArgs Args) { var targ = Args as Profile1DArgs; this.Axis = targ.Axis.HashString; this.IsEnable = targ.IsEnabled; this.Interval = targ.Interval; this.ScanRange = targ.Range; this.ScanOrder = targ.Order; this.HashString = this.GetHashString(); }
public override void FromArgsInstance(IAlignmentArgs Args) { var targ = Args as FastRotatingScanArgs; this.AxisRotating = targ.AxisRotating.HashString; this.AxisLinear = targ.AxisLinear.HashString; this.LinearInterval = targ.LinearInterval; this.LinearScanRange = targ.LinearRange; this.Pitch = targ.Pitch; this.HashString = this.GetHashString(); }
public override void FromArgsInstance(IAlignmentArgs Args) { var targ = Args as SnakeRouteScanArgs; this.Axis = targ.Axis.HashString; this.Axis2 = targ.Axis2.HashString; this.ScanRange = targ.AxisRestriction; this.ScanRange2 = targ.Axis2Restriction; this.Interval = targ.ScanInterval; this.MoveSpeed = targ.MoveSpeed; this.HashString = this.GetHashString(); }
public override void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { var targ = Args as FastCentralAlignArgs; targ.Axis = Service.FindLogicalAxisByHashString(this.HorizontalAxis); targ.HorizonalRange = this.HorizontalRange; targ.HorizonalInterval = this.HorizontalInterval; targ.Axis2 = Service.FindLogicalAxisByHashString(this.VerticalAxis); targ.VerticalRange = this.VerticalRange; targ.VerticalInterval = this.VerticalInterval; targ.MoveSpeed = this.MoveSpeed; }
public override void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { var targ = Args as FastNDArgs; targ.SelectedAligner = Service.FindLogicalMotionComponentByHashString(this.SelectedAligner); targ.Target = this.Target; targ.MaxCycles = this.MaxCycles; foreach (var targ1d in targ.AxisParamCollection) { var axishash = targ1d.Axis.HashString; var profile = this.AxisGroup.Where(item => item.Axis == axishash).Select(item => { return(item); }).First(); profile.ToArgsInstance(null, targ1d); } }
public override void FromArgsInstance(IAlignmentArgs Args) { var targ = Args as FastCentralAlignArgs; this.HorizontalAxis = targ.Axis.HashString; this.HorizontalInterval = targ.HorizonalRange; this.HorizontalRange = targ.HorizonalInterval; this.VerticalAxis = targ.Axis2.HashString; this.VerticalInterval = targ.VerticalRange; this.VerticalRange = targ.VerticalInterval; this.MoveSpeed = targ.MoveSpeed; this.HashString = this.GetHashString(); }
/// <summary> /// Check whether the profile is existed. /// </summary> /// <param name="Name"></param> /// <returns></returns> public static bool CheckExistance(IAlignmentArgs Args, string Name) { var path = string.Join("\\", PROFILE_FOLDER, Args.PresetProfileFolder); var filename = string.Join("\\", path, $"{Name}.json"); if (!Directory.Exists(path)) { return(false); } else if (!File.Exists(path)) { return(false); } else { return(true); } }
public override void FromArgsInstance(IAlignmentArgs Args) { var targ = Args as FastNDArgs; this.SelectedAligner = targ.SelectedAligner.HashString; this.Target = targ.Target; this.MaxCycles = targ.MaxCycles; this.MaxOrder = targ.MaxOrder; this.ListScanOrder = targ.ListScanOrder.ToArray(); List <Fast1DArgsProfile> subaxis = new List <Fast1DArgsProfile>(); foreach (var item in targ.AxisParamCollection) { var profile = new Fast1DArgsProfile(); profile.FromArgsInstance(item); subaxis.Add(profile); } this.AxisGroup = subaxis.ToArray(); this.HashString = this.GetHashString(); }
/// <summary> /// Load the existed profiles. /// </summary> public static string[] LoadProfileList(IAlignmentArgs Args) { var path = string.Join("\\", PROFILE_FOLDER, Args.PresetProfileFolder); if (Directory.Exists(path)) { List <string> list = new List <string>(); DirectoryInfo info = new DirectoryInfo(path); foreach (var file in info.GetFiles()) { if (file.Extension == ".json") { list.Add(Path.GetFileNameWithoutExtension(file.FullName)); } } return(list.ToArray()); } else { return(null); } }
public virtual void ToArgsInstance(SystemService Service, IAlignmentArgs Args) { throw new NotImplementedException(); }
public virtual void FromArgsInstance(IAlignmentArgs Args) { throw new NotImplementedException(); }