private List <DriveCyclePoint> read(Stream driveCycleData) { StreamReader sr = new StreamReader(driveCycleData); List <DriveCyclePoint> points = new List <DriveCyclePoint>(); while (!sr.EndOfStream) { string[] line = sr.ReadLine().Split(','); float time; float setpoint; if (!float.TryParse(line[0], out time)) { continue; } if (!float.TryParse(line[1], out setpoint)) { continue; } ConverterMode mode = ConverterMode.Off; if (setpoint < 0) { mode = ConverterMode.ReverseCC; } else if (setpoint > 0) { mode = ConverterMode.ForwardCC; } else if (setpoint == 0) { mode = ConverterMode.Off; } points.Add(new DriveCyclePoint(mode, setpoint, (int)time * 1000)); } return(points); }
public static string Convert(string toConvert, ConverterMode mode) { Dictionary <string, string> CharacterSet = new Dictionary <string, string>() { { "?", "%3f" }, { ">", "%3e" }, { "<", "%3c" }, { "|", "%7c" }, { "\\", "%5c" }, { "]", "%5d" }, { "[", "%5b" }, { "}", "%7d" }, { "{", "%7b" }, { "+", "%2b" }, { "=", "%3d" }, { ")", "%29" }, { "(", "%28" }, { "*", "%2a" }, { "&", "%26" }, { "^", "%5e" }, { "%", "%25" }, { "$", "%24" }, { "#", "%23" }, { "@", "%40" }, { "!", "%21" }, { "~", "%7e" }, { "`", "%60" }, { ",", "%82" }, { "/", "%2f" }, { ":", "%3a" }, { ";", "%3b" }, { "€", "%80" }, { " ", "%20" } }; string Converted = toConvert; if (mode == ConverterMode.StandardToUrl) { foreach (KeyValuePair <string, string> s in CharacterSet) { Converted = Converted.Replace(s.Key, s.Value); } } else { foreach (KeyValuePair <string, string> s in CharacterSet) { Converted = Converted.Replace(s.Value, s.Key); } } return(Converted); }
/// <summary> /// 根据模式创建转换器 /// </summary> /// <param name="mode"></param> /// <returns></returns> public static IConverter CreateConverter(ConverterMode mode) { switch (mode) { case ConverterMode.HTML: return(new HtmlConverter()); case ConverterMode.WORD: return(new WordConverter()); default: return(null); } }
private void modeBtn_CheckedChanged(object sender, EventArgs e) { CheckBox btn = (CheckBox)sender; ConverterMode newMode = (ConverterMode)btn.Tag; gbForward.Focus(); if (this.Mode == newMode && btn.Checked == false) // an already checked mode was clicked, turn off converter { OnControllerModeChange(ConverterMode.Off); } else if (btn.Checked) // a new state was clicked { OnControllerModeChange(newMode); } }
// controller mode change event handler private void OnControllerModeChange(ConverterMode newMode) { lblStatus.Text = "Mode: " + newMode.ToString(); this.Mode = newMode; if (!controllerTransmit()) // if error TX, disable buttons TODO: make sure state is determinate { foreach (CheckBox cb in modeSelectors) { cb.Checked = false; } return; } foreach (CheckBox cb in modeSelectors) { if ((ConverterMode)cb.Tag != newMode) { cb.Checked = false; } } }
public Converter( IRdfHandler rdfHandler, ITableResolver resolver = null, ConverterMode mode = ConverterMode.Standard, Action <string> errorMessageSink = null, IProgress <int> conversionProgress = null, int reportInterval = 50, bool suppressStringDatatype = false) { _resolver = resolver ?? new DefaultResolver(); _rdfHandler = rdfHandler; Mode = mode; _errors = new List <string>(); _progress = conversionProgress; _errorMessageSink = errorMessageSink; _reportInterval = reportInterval; _suppressStringDatatype = suppressStringDatatype; using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("DataDock.CsvWeb.Resources.csvw.jsonld"), Encoding.UTF8)) { _csvwContext = JsonConvert.DeserializeObject <JObject>(reader.ReadToEnd())["@context"] as JObject; } }
public PlacementTargetToQATPositionConverter(ConverterMode mode) { _mode = mode; }
public DriveCyclePoint(ConverterMode mode, float setpoint, int time) { this.Mode = mode; this.Setpoint = setpoint; this.Time = time; }
public static void Main(string[] args) { #region Set console // Maximize console NativeMethods.ShowWindow(Process.GetCurrentProcess().MainWindowHandle, 3); //SW_MAXIMIZE = 3 // Set flag for colorful output var handle = NativeMethods.GetStdHandle(-11); // STD_OUTPUT_HANDLE = -11 NativeMethods.GetConsoleMode(handle, out int mode); NativeMethods.SetConsoleMode(handle, mode | 0x4); // ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4 #endregion Set console // Load image or video path OpenFileDialog ofd = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, Filter = string.Format("Media({0};{1})|{0};{1}", ImageConverter.FilterString, VideoConverter.FilterString), Multiselect = false, Title = "Select an image or video to convert..." }; ofd.ShowDialog(); if (string.IsNullOrEmpty(ofd.FileName)) { return; } string filename = ofd.FileName; // Set converter mode ConverterMode converterMode = ConverterMode.Unsupported; string extension = new FileInfo(filename).Extension; if (VideoConverter.SupportedFormats.Contains(extension)) { converterMode = ConverterMode.Video; } else if (ImageConverter.SupportedFormats.Contains(extension)) { converterMode = ConverterMode.Image; } // Draw Application.EnableVisualStyles(); ScaleBox scaleBox; switch (converterMode) { case ConverterMode.Image: ImageConverter ic = new ImageConverter(filename); if (!ic.IsValid) { break; } scaleBox = new ScaleBox(ic.GetSuggestedHScale()); Application.Run(scaleBox); if (scaleBox.DialogResult != DialogResult.OK) { return; } ic.SetScale(scaleBox.HScale); ic.Draw(); break; case ConverterMode.Video: VideoConverter vc = new VideoConverter(filename); scaleBox = new ScaleBox(vc.GetSuggestedHScale()); Application.Run(scaleBox); if (scaleBox.DialogResult != DialogResult.OK) { return; } vc.SetScale(scaleBox.HScale); vc.CreatePipe(); vc.Decode(); break; default: Console.WriteLine($"\x1b[38;2;200;200;200mUnsupported format."); break; } // Exit Console.WriteLine($"\x1b[38;2;200;200;200mPress any key to exit..."); Console.ReadKey(); }