private void bUpdateRes_Click(object sender, EventArgs e) { if (!Ut.FileExists(tbResMdf)) { return; } if (!Ut.FileExists(tbResLdf)) { return; } if (!Ut.IsCommand(tbSQLConn)) { return; } using (SqlConnection db = new SqlConnection(tbSQLConn.Text)) { db.Open(); new RunSQLForm(new SqlCommand(String.Format(Resources.ALTDb, tbResMdf.Text, tbResLdf.Text), db)).ShowDialog(this); db.Close(); } }
private IEnumerable <object> ProcessPinkButton(KMBombModule module) { var comp = GetComponent(module, "PinkButtonScript"); var words = GetArrayField <int>(comp, "_words").Get(expectedLength: 4, validator: v => v < 0 || v > 7 ? "expected range 0–7" : null); var colors = GetArrayField <int>(comp, "_colors").Get(expectedLength: 4, validator: v => v < 0 || v > 7 ? "expected range 0–7" : null); var fldSolved = GetField <bool>(comp, "_moduleSolved"); var abbreviatedColorNames = GetStaticField <string[]>(comp.GetType(), "_abbreviatedColorNames").Get(v => v.Length != 8 ? "expected length 8" : null); var colorNames = GetStaticField <string[]>(comp.GetType(), "_colorNames").Get(v => v.Length != 8 ? "expected length 8" : null); while (!fldSolved.Get()) { yield return(new WaitForSeconds(.1f)); } _modulesSolved.IncSafe(_PinkButton); addQuestions(module, Enumerable.Range(0, 4).SelectMany(ix => Ut.NewArray( makeQuestion(Question.PinkButtonWords, _PinkButton, formatArgs: new[] { ordinal(ix + 1) }, correctAnswers: new[] { abbreviatedColorNames[words[ix]] }), makeQuestion(Question.PinkButtonColors, _PinkButton, formatArgs: new[] { ordinal(ix + 1) }, correctAnswers: new[] { colorNames[colors[ix]] })))); }
/// <summary>Sets the part of the URL after the host, consisting of the path and optionally the query parameters.</summary> internal void SetLocation(string location) { Ut.Assert(location != null && location.Length > 0 && location[0] == '/'); ParentPaths = HttpHelper.EmptyStrings; int start = location.IndexOf('?'); if (start < 0) { Path = location; _hasQuery = false; _query = Enumerable.Empty <KeyValuePair <string, string> >(); _queryString = ""; } else { Path = location.Substring(0, start); _hasQuery = true; _query = null; _queryString = location.Substring(start); } }
static int Main(string[] args) { try { Console.OutputEncoding = Encoding.UTF8; } catch { } if (args.Length == 2 && args[0] == "--post-build-check") { return(Ut.RunPostBuildChecks(args[1], Assembly.GetExecutingAssembly())); } Classify.DefaultOptions.AddTypeSubstitution(new ClassifyColorSubstitute()); SettingsUtil.LoadSettings(out Settings); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Mainform(Settings, args)); Settings.Save(onFailure: SettingsOnFailure.ShowRetryWithCancel); return(0); }
private static IEnumerable <VertexInfo[]> ScreenHighlight() { const int revSteps = 6; const double innerRadius = .07; const double outerRadius = .12; const double displacement = .25; const double depth = 0; Pt rPt(double rds, double angle, int quadrant, double dpth, double dx, double dy) => pt(rds * cos(angle) + dx * new[] { 1, -1, -1, 1 }[quadrant], dpth, rds * sin(angle) + dy * new[] { 1, 1, -1, -1 }[quadrant]); var infs = Enumerable.Range(0, 4) .SelectMany(q => Enumerable.Range(0, revSteps).Select(i => i * 90.0 / (revSteps - 1)).Select(angle => new { Angle = angle, Quadrant = q })); foreach (var face in CreateMesh(true, false, infs.Select(inf => Ut.NewArray( rPt(innerRadius, inf.Angle + 90 * inf.Quadrant, inf.Quadrant, depth, displacement, displacement).WithMeshInfo(Normal.Average, Normal.Average, Normal.Mine, Normal.Mine), rPt(outerRadius, inf.Angle + 90 * inf.Quadrant, inf.Quadrant, depth, displacement, displacement).WithMeshInfo(0, 1, 0) )).ToArray())) { yield return(face); } }
public static List <hotspots> GetHotspots(int vehicle_id, string image, string lang = "EN") { if (!String.IsNullOrEmpty(lang)) { strConn = Ut.GetMySQLConnect(lang); } List <hotspots> list = null; try { #region strCommand string strCommand = " SELECT " + " cic.id, cic.image AS name, cic.label AS number, " + " cic.x1 AS min_x, " + " cic.y1 AS min_y, " + " cic.x2 AS max_x, " + " cic.y2 AS max_y " + " FROM " + " cat_img_coord cic " + " WHERE cic.catalog IN " + " (SELECT k.catalog " + " FROM ksrbhmh k " + " WHERE k.pos = @vehicle_id) " + " AND cic.image = @image; "; #endregion using (IDbConnection db = new MySqlConnection(strConn)) { list = db.Query <hotspots>(strCommand, new { vehicle_id, image }).ToList(); } } catch (Exception ex) { string Error = ex.Message; int o = 0; } return(list); }
public static string Generate(bool sortByLetter, int clip = 10) { var codes = new Dictionary <string, string> { { "T", "−" }, { "M", "−−" }, { "O", "−−−" }, { "G", "−−·" }, { "Q", "−−·−" }, { "Z", "−−··" }, { "N", "−·" }, { "K", "−·−" }, { "Y", "−·−−" }, { "C", "−·−·" }, { "D", "−··" }, { "X", "−··−" }, { "B", "−···" }, { "E", "·" }, { "A", "·−" }, { "W", "·−−" }, { "J", "·−−−" }, { "P", "·−−·" }, { "R", "·−·" }, { "L", "·−··" }, { "I", "··" }, { "U", "··−" }, { "F", "··−·" }, { "S", "···" }, { "V", "···−" }, { "H", "····" } }; var fibo = new[] { 1, 2, 3, 5, 8, 13, 21 }; var primes = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23 }; var squares = new[] { 1, 4, 9, 16, 25 }; var calculate = Ut.Lambda((int v, int frst) => (v * (frst + (fibo.Contains(v) ? 2 : 0) + (primes.Contains(v) ? -1 : 0) + (squares.Contains(v) ? -1 : 0)) + 3 * 26 + clip) % 26 - clip); var arr = codes .OrderBy(kvp => sortByLetter ? kvp.Key : kvp.Value, StringComparer.OrdinalIgnoreCase) .Select(kvp => $"<th class='letter'>{kvp.Key}<td class='number'>{(kvp.Key[0] - 'A' + 1).Apply(v => $"{v}<td class='number'>{calculate(v, -1)}<td class='number'>{calculate(v, 1)}")}<td><svg class='morse' viewBox='0 0 {kvp.Value.Sum(ch => ch == '−' ? 4 : 2)} 1'>{kvp.Value.Aggregate(new { X = 0, Str = "" }, (prev, ch) => ch == '−' ? new { X = prev.X + 4, Str = prev.Str + $"<rect x='{prev.X}' y='0' width='3' height='1'/>" } : new { X = prev.X + 2, Str = prev.Str + $"<circle cx='{prev.X + .5}' cy='.5' r='.5' />" }).Str}</svg>")
private void Pane_Paint(object sender, PaintEventArgs e) { Rectangle rc0 = ClientRectangle; int w = Math.Min(rc0.Width, rc0.Height); Rectangle rc1 = Rectangle.FromLTRB(rc0.Right - w, rc0.Bottom - w, rc0.Right, rc0.Bottom); if (ima == null) { return; } Graphics cv = e.Graphics; cv.DrawRectangle(new Pen(Color.FromArgb(50, ForeColor)), Rectangle.FromLTRB(rc1.Left, rc1.Top, rc1.Right - 1, rc1.Bottom - 1)); { int xc = (rc1.X + rc1.Right) / 2; int yc = (rc1.Y + rc1.Bottom) / 2; cv.DrawImage(ima, Ut.GetPts(xc, yc, ima.Size, rrot), new Rectangle(Point.Empty, ima.Size), GraphicsUnit.Pixel ); } if (killMe) { Rectangle rc3 = Rectangle.FromLTRB(rc1.X + 3, rc1.Y + 3, rc1.Right - 3, rc1.Bottom - 3); cv.DrawLine(penX, rc3.X, rc3.Y, rc3.Right, rc3.Bottom); cv.DrawLine(penX, rc3.Right, rc3.Y, rc3.X, rc3.Bottom); } if (splitHere) { cv.DrawLine(penI, rc0.X + 1, rc1.Y, rc0.X + 1, rc1.Bottom); } int fno = Parent.Controls.IndexOf(this); String fnos = String.Format("{0}", 1 + fno); SizeF fnosize = cv.MeasureString(fnos, Font); PointF ptfno = new PointF((rc1.Right + rc1.Left) / 2 - fnosize.Width / 2, rc1.Bottom - 1 - fnosize.Height); cv.FillRectangle(Brushes.White, new RectangleF(ptfno, fnosize)); cv.DrawString(fnos, Font, Brushes.Black, ptfno); }
private void checkConsistency() { foreach (var bucket in _buckets) { Ut.Assert(bucket.From <= bucket.To); Ut.Assert(bucket.To - bucket.From <= uint.MaxValue); } // Verify that buckets are sorted and non-overlapping for (int i = 0; i < _buckets.Count - 2; i++) { Ut.Assert(_buckets[i].From < _buckets[i + 1].From); Ut.Assert(_buckets[i].To < _buckets[i + 1].From); } // Verify that all items are within the from/to boundaries foreach (var bucket in _buckets) { foreach (var item in bucket.Values) { Ut.Assert(item + bucket.From <= bucket.To); } } }
private static Point[][] boolsToPaths(Virtual2DArray <bool> input) { int width = input.Width; int height = input.Height; var results = new List <Point[]>(); var visitedUpArrow = Ut.NewArray <bool>(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { // every region must have at least one up arrow (left edge) if (!visitedUpArrow[i][j] && input.Get(i, j) && !input.Get(i - 1, j)) { results.Add(tracePolygon(input, i, j, visitedUpArrow)); } } } return(results.ToArray()); }
public SucoParser(string source, SucoContext context) : base(source, Ut.NewArray( // MAKE SURE that every multi-character token that has another token as its prefix comes before said prefix // Arithmetic "+", "-", "−", "*", "×", "^", "%", "/", // Relational "<=", "<", "≤", ">=", ">", "≥", "=", "!=", "≠", // Logical "&", "|", "?", ":", "!", // Structural "{", "}", ",", "(", ")", ".", "[", "]", ";", // Flags; "+" is listed in Arithmetic; "1" is parsed as a numeral "$", // String literals "\"", // Shortcut filters "~", "←", "→", "↑", "↓" // “v” parses as an identifier; “<”/“>” are in Relational; “^” is in Arithmetic )) { Context = context; }
public static List <CarTypeInfo> GetListCarTypeInfo(string body_code, string body_num, string lang = "EN") { if (!String.IsNullOrEmpty(lang)) { strConn = Ut.GetMySQLConnect(lang); } List <CarTypeInfo> list = null; try { #region strCommand string strCommand = " SELECT " + " k.pos, " + " k.model, " + " k.body, " + " k.modification, " + " k.transmission, " + " k.door, " + " k.engine " + " FROM ksrbhmh k " + " WHERE k.body_code = @body_code " + " AND k.body_num_from <= @body_num AND " + " ((k.body_num_to IS NULL) OR " + " (k.body_num_to >= @body_num))"; #endregion using (IDbConnection db = new MySqlConnection(strConn)) { list = db.Query <CarTypeInfo>(strCommand, new { body_code, body_num }).ToList(); } } catch { } return(list); }
private static IEnumerable <VertexInfo[]> Button() { var height = .2; var fh = height * .4; var innerRadius = 0.4; var outerRadius = 1.0; var fr = innerRadius * .1; var angle = 30.0; var bézierSteps = 20; var d = Math.Sqrt(innerRadius * innerRadius + outerRadius * outerRadius - 2 * innerRadius * outerRadius * cos(angle)); var frix = outerRadius - (outerRadius - innerRadius * cos(angle)) / d * (d - fr); var friy = innerRadius * sin(angle) / d * (d - fr); var frox = outerRadius - (outerRadius - innerRadius * cos(angle)) / d * fr; var froy = innerRadius * sin(angle) / d * fr; var patchCoords = Ut.NewArray( new[] { pt(0, 0, 0), pt(fr * cos(-angle), fh, fr * sin(-angle)), pt((innerRadius - fr) * cos(-angle), fh, (innerRadius - fr) * sin(-angle)), pt(innerRadius * cos(-angle), 0, innerRadius * sin(-angle)) }, new[] { pt(fr * cos(angle), fh, fr * sin(angle)), pt(innerRadius / 2, height, 0), pt(innerRadius * cos(angle / 2), height, innerRadius * sin(angle / 2)), pt(frix, fh, -friy) }, new[] { pt((innerRadius - fr) * cos(angle), fh, (innerRadius - fr) * sin(angle)), pt(innerRadius * cos(angle / 2), height, innerRadius * sin(angle / 2)), pt((innerRadius + outerRadius) / 2, height, 0), pt(frox, fh, -froy) }, new[] { pt(innerRadius * cos(angle), 0, innerRadius * sin(angle)), pt(frix, fh, friy), pt(frox, fh, froy), pt(outerRadius, 0, 0) } ) .Select(arr => arr.Select(p => p.Add(x: .03)).ToArray()) .ToArray(); var patch = BézierPatch(patchCoords, bézierSteps); var extendedPatch = Ut.NewArray(bézierSteps + 2, bézierSteps + 2, (i, j) => { var ii = i == 0 ? 1 : i == bézierSteps + 1 ? bézierSteps - 1 : i - 1; var jj = j == 0 ? 1 : j == bézierSteps + 1 ? bézierSteps - 1 : j - 1; return(new MeshVertexInfo( patch[ii][jj].Set(y: i == 0 || i == bézierSteps + 1 || j == 0 || j == bézierSteps + 1 ? -.03 : (double?)null), i == bézierSteps + 1 ? Normal.Mine : Normal.Average, i == 0 ? Normal.Mine : Normal.Average, j == bézierSteps + 1 ? Normal.Mine : Normal.Average, j == 0 ? Normal.Mine : Normal.Average )); }); return(CreateMesh(false, false, extendedPatch)); }
public async Task <FileContentResult> GetImageAsync(string image_id) { string imgPath = Ut.GetImagePath(); // 17SA501_HMT0300.png string npl = image_id.Substring(0, image_id.IndexOf("_")); string imageName = image_id.Substring(image_id.IndexOf("_") + 1, image_id.Length - (image_id.IndexOf("_") + 1)).Replace("-", "."); // \honda_eu\Img\Pictures\18SA801\IMGE byte[] result = new byte[0]; string fullPath = Ut.GetImagePath() + npl + "/IMGE/" + imageName; try { if (fullPath.Substring(0, 4) == "http") { using (var handler = new HttpClientHandler()) { using (var client = new HttpClient(handler)) { result = await client.GetByteArrayAsync(fullPath); } } } else { if (System.IO.File.Exists(fullPath)) { result = await System.IO.File.ReadAllBytesAsync(fullPath); } } } catch (Exception ex) { string Error = ex.Message; int o = 0; } return(File(result, "image/png")); }
public override ToolStripMenuItem[] CreateMenus(IIde ide) { var inputModes = EnumStrong.GetValues <InputMode>(); var inputModeItems = new ToolStripMenuItem[inputModes.Length]; var setInputMode = Ut.Lambda((InputMode mode) => { _settings.InputMode = mode; for (int i = 0; i < inputModes.Length; i++) { inputModeItems[i].Checked = (mode == inputModes[i]); } }); var ret = Ut.NewArray( new ToolStripMenuItem("&Input semantics", null, Ut.NewArray( (inputModeItems[0] = new ToolStripMenuItem("Encode input as UTF-&8", null, (_, __) => setInputMode(InputMode.Utf8))), (inputModeItems[1] = new ToolStripMenuItem("Encode input as UTF-1&6 (little endian)", null, (_, __) => setInputMode(InputMode.Utf16))), (inputModeItems[2] = new ToolStripMenuItem("Input string is a list of &bytes", null, (_, __) => setInputMode(InputMode.Numbers)))))); setInputMode(_settings.InputMode); return(ret); }
public override ToolStripMenuItem[] CreateMenus(IIde ide) { var menuItems = new List <Tuple <ToolStripMenuItem, Func <bool> > >(); var update = Ut.Lambda(() => { foreach (var tuple in menuItems) { tuple.Item1.Checked = tuple.Item2(); } }); var createItem = Ut.Lambda((string label, Action action, Func <bool> checkedFunc) => { var menuItem = new ToolStripMenuItem(label, null, delegate { action(); update(); }); menuItems.Add(new Tuple <ToolStripMenuItem, Func <bool> >(menuItem, checkedFunc)); return(menuItem); }); var ret = Ut.NewArray <ToolStripMenuItem>( new ToolStripMenuItem("&Semantics", null, createItem("Input as &numbers", () => { _settings.InputType = IOType.Numbers; }, () => _settings.InputType == IOType.Numbers), createItem("Input as &characters", () => { _settings.InputType = IOType.Characters; }, () => _settings.InputType == IOType.Characters), new ToolStripSeparator(), createItem("Output as nu&mbers", () => { _settings.OutputType = IOType.Numbers; }, () => _settings.OutputType == IOType.Numbers), createItem("Output as c&haracters", () => { _settings.OutputType = IOType.Characters; }, () => _settings.OutputType == IOType.Characters), new ToolStripSeparator(), createItem("Cells are &bytes", () => { _settings.CellType = CellType.Bytes; }, () => _settings.CellType == CellType.Bytes), createItem("Cells are &signed 32-bit integers", () => { _settings.CellType = CellType.Int32s; }, () => _settings.CellType == CellType.Int32s), createItem("Cells are &unsigned 32-bit integers", () => { _settings.CellType = CellType.UInt32s; }, () => _settings.CellType == CellType.UInt32s), createItem("Cells are &arbitrary-size integers", () => { _settings.CellType = CellType.BigInts; }, () => _settings.CellType == CellType.BigInts) ) ); update(); return(ret); }
private static IEnumerable <VertexInfo[]> StickFigure() { const int revSteps = 72; const double middleRadius = 2; const double depth = .2; const double width = .3; const double innerRadius = middleRadius - width; const double outerRadius = middleRadius + width; foreach (var face in CreateMesh(true, false, Enumerable.Range(0, revSteps) .Select(i => 360.0 * i / revSteps) .Select(angle => Ut.NewArray( pt(innerRadius * cos(angle), 0, innerRadius * sin(angle) + 5).WithMeshInfo(-cos(angle), 0, -sin(angle)), pt(middleRadius * cos(angle), depth, middleRadius * sin(angle) + 5).WithMeshInfo(0, 1, 0), pt(outerRadius * cos(angle), 0, outerRadius * sin(angle) + 5).WithMeshInfo(cos(angle), 0, sin(angle)))) .ToArray())) { yield return(face); } var lines = Ut.NewArray( new { From = p(0, 3), To = p(0, -1) }, new { From = p(0, 2), To = p(-3, 0) }, new { From = p(0, 2), To = p(3, 0) }, new { From = p(0, -1), To = p(-2, -6) }, new { From = p(0, -1), To = p(2, -6) }); foreach (var line in lines) { var p1 = pt(line.From.X, 0, line.From.Y); var p2 = pt(line.To.X, 0, line.To.Y); var vector = ((p2 - p1) * pt(0, 1, 0)).Normalize() * width; yield return(Ut.NewArray((p1 + vector).WithNormal((p2 - p1) * pt(0, 1, 0)), (p2 + vector).WithNormal((p2 - p1) * pt(0, 1, 0)), p2.Add(y: depth).WithNormal(pt(0, 1, 0)), p1.Add(y: depth).WithNormal(pt(0, 1, 0)))); yield return(Ut.NewArray(p1.Add(y: depth).WithNormal(pt(0, 1, 0)), p2.Add(y: depth).WithNormal(pt(0, 1, 0)), (p2 - vector).WithNormal(-(p2 - p1) * pt(0, 1, 0)), (p1 - vector).WithNormal(-(p2 - p1) * pt(0, 1, 0)))); } }
private static Stuff SubmitButton() { var height = .03; var xWidth = .299; var yWidth = .099; var bevelWidth = .03; var outerRounding = .01; var bevelF = bevelWidth * .6; var outerF = outerRounding * .9; var bézierSteps = 10; var xy = Bézier(p(0, height), p(bevelF, height), p(bevelWidth, height - bevelF), p(bevelWidth, height - bevelWidth), bézierSteps) .RemoveConsecutiveDuplicates(false) .ToArray(); var arr = xy.Select(q => Bézier(pt(xWidth / 2 + q.X, q.Y, yWidth / 2 - outerRounding), pt(xWidth / 2 + q.X, q.Y, yWidth / 2 - outerRounding + outerF), pt(xWidth / 2 - outerRounding + outerF, q.Y, yWidth / 2 + q.X), pt(xWidth / 2 - outerRounding, q.Y, yWidth / 2 + q.X), bézierSteps) .Concat(Bézier(pt(-xWidth / 2 + outerRounding, q.Y, yWidth / 2 + q.X), pt(-xWidth / 2 + outerRounding - outerF, q.Y, yWidth / 2 + q.X), pt(-xWidth / 2 - q.X, q.Y, yWidth / 2 - outerRounding + outerF), pt(-xWidth / 2 - q.X, q.Y, yWidth / 2 - outerRounding), bézierSteps)) .Concat(Bézier(pt(-xWidth / 2 - q.X, q.Y, -yWidth / 2 + outerRounding), pt(-xWidth / 2 - q.X, q.Y, -yWidth / 2 + outerRounding - outerF), pt(-xWidth / 2 + outerRounding - outerF, q.Y, -yWidth / 2 - q.X), pt(-xWidth / 2 + outerRounding, q.Y, -yWidth / 2 - q.X), bézierSteps)) .Concat(Bézier(pt(xWidth / 2 - outerRounding, q.Y, -yWidth / 2 - q.X), pt(xWidth / 2 - outerRounding + outerF, q.Y, -yWidth / 2 - q.X), pt(xWidth / 2 + q.X, q.Y, -yWidth / 2 + outerRounding - outerF), pt(xWidth / 2 + q.X, q.Y, -yWidth / 2 + outerRounding), bézierSteps)) .Reverse() .ToArray() ).ToArray(); return(new Stuff { Button = CreateMesh(false, true, Ut.NewArray(arr.Length, arr[0].Length, (x, y) => x == 0 ? new MeshVertexInfo(arr[x][y], pt(0, 1, 0)) : new MeshVertexInfo(arr[x][y], x == arr.Length - 1 ? Normal.Mine : Normal.Average, Normal.Average, Normal.Average, Normal.Average))) .Concat(new[] { p(-1, -1), p(-1, 1), p(1, 1), p(1, -1) }.Select(p => new VertexInfo(pt(p.X * xWidth / 2, height, p.Y * yWidth / 2), pt(0, 1, 0))).ToArray()), Highlight = arr.Last().SelectConsecutivePairs(true, (p1, p2) => new[] { pt(0, 0, 0), p2, p1 }).ToArray(), Outline = arr.Last().Select(pt => p(pt.X, pt.Z)).ToArray() }); }
public static void SelfTest(int count, long max) { Console.WriteLine($"Self-test with {count:#,0} items"); var cset = new CompactSetOfLong(); var hset = new HashSet <long>(); for (int c = 0; c < count; c++) { var val = (long)(Rnd.NextDouble() * max); Ut.Assert(hset.Count == cset.Count); Ut.Assert(hset.Add(val) == cset.Add(val)); Ut.Assert(hset.Count == cset.Count); if (c < 1000 || (c < 100_000 && (c % 1000 == 0)) || (c % 10_000 == 0)) { cset.checkConsistency(); Ut.Assert(hset.Add(val) == cset.Add(val)); // Verify that Contains is true for every item foreach (var item in hset) { Ut.Assert(cset.Contains(item)); } foreach (var item in cset) { Ut.Assert(hset.Contains(item)); } // Verify that the set of items has no duplicates, relying on the fact that GetEnumerator is correct, and on the fact that we've checked that every item of hset is in it Ut.Assert(cset.Count == hset.Count); Ut.Assert(cset.Count == cset.Count()); // Verify that Contains is false for random items for (int i = 0; i < 50; i++) { val = (long)(Rnd.NextDouble() * max); Ut.Assert(hset.Contains(val) == cset.Contains(val)); } } } }
private static IEnumerable <string> generateDirectoryXml(string localPath, IHttpUrl url, string urlPath) { List <DirectoryInfo> dirs = new List <DirectoryInfo>(); List <FileInfo> files = new List <FileInfo>(); DirectoryInfo dirInfo = new DirectoryInfo(localPath); foreach (var d in dirInfo.GetDirectories()) { dirs.Add(d); } foreach (var f in dirInfo.GetFiles()) { files.Add(f); } dirs.Sort((a, b) => a.Name.CompareTo(b.Name)); files.Sort((a, b) => a.Name.CompareTo(b.Name)); yield return("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); yield return("<?xml-stylesheet href=\"{0}\" type=\"text/xsl\" ?>\n".Fmt(url.WithPathOnly("/$/directory-listing/xsl").ToHref().HtmlEscape())); yield return("<directory url=\"{0}\" unescapedurl=\"{1}\" img=\"{2}\" numdirs=\"{3}\" numfiles=\"{4}\">\n" .Fmt(url.ToHref().HtmlEscape(), url.ToHref().UrlUnescape().HtmlEscape(), url.WithPathOnly("/$/directory-listing/icons/folderbig").ToHref().HtmlEscape(), dirs.Count, files.Count)); foreach (var d in dirs) { yield return(" <dir link=\"{0}/\" img=\"{2}\">{1}</dir>\n".Fmt(d.Name.UrlEscape(), d.Name.HtmlEscape(), url.WithPathOnly("/$/directory-listing/icons/folder").ToHref().HtmlEscape())); } foreach (var f in files) { string extension = f.Name.Contains('.') ? f.Name.Substring(f.Name.LastIndexOf('.') + 1) : ""; yield return(" <file link=\"{0}\" size=\"{1}\" nicesize=\"{2}\" img=\"{3}\">{4}</file>\n" .Fmt(f.Name.UrlEscape(), f.Length, Ut.SizeToString(f.Length), url.WithPathOnly("/$/directory-listing/icons/" + GetDirectoryListingIconStr(extension)).ToHref().HtmlEscape(), f.Name.HtmlEscape())); } yield return("</directory>\n"); }
public static void Svg() { const int outerRadius = 100; const int innerRadius = 37; const int arrangementRadius = 250; var cos = Ut.Lambda((double angle) => Math.Cos(angle / 180.0 * Math.PI)); var sin = Ut.Lambda((double angle) => Math.Sin(angle / 180.0 * Math.PI)); var path = @"D:\c\KTANE\HTML\img\Component\Perspective Pegs.svg"; File.WriteAllText(path, Regex.Replace(File.ReadAllText(path), @"(?<=<!--##-->).*(?=<!--###-->)", $@" <g transform='translate(174, 174) scale(.34)'> { Enumerable.Range(0, 5).Select(i => i * 72 - 90).Select(angle2 => new { X = arrangementRadius * cos(angle2), Y = arrangementRadius * sin(angle2) }).Select(inf => $@" { Enumerable.Range(0, 5).Select(i => i * 72 + 90).Select(angle => $@" <line stroke-width='5' stroke='#000' x1='{inf.X + outerRadius * cos(angle)}' y1='{inf.Y + outerRadius * sin(angle)}' x2='{inf.X + innerRadius * cos(angle)}' y2='{inf.Y + innerRadius * sin(angle)}' /> <line stroke-width='5' stroke='#000' x1='{inf.X + innerRadius * cos(angle)}' y1='{inf.Y + innerRadius * sin(angle)}' x2='{inf.X + innerRadius * cos(72 + angle)}' y2='{inf.Y + innerRadius * sin(72 + angle)}' /> ").JoinString() } < polygon stroke - width = '10' stroke = '#000' points = '{Enumerable.Range(0, 5).Select(i => i * 72 + 90).Select(angle => $"{inf.X + outerRadius * cos(angle)} {inf.Y + outerRadius * sin(angle)}").JoinString(", ")}' / > ").JoinString() } </g>", RegexOptions.Singleline)); }
/// <summary> /// Generates a cylinder oriented along the Z axis.</summary> /// <param name="startZ"> /// Z-coordinate of the “bottom” of the cylinder. This must be less than <paramref name="endZ"/>.</param> /// <param name="endZ"> /// Z-coordinate of the “top” of the cylinder. This must be greater than <paramref name="startZ"/>.</param> public static VertexInfo[][] Cylinder(double startZ, double endZ, double radius, int numVertices = 20) { if (startZ > endZ) { var t = startZ; startZ = endZ; endZ = t; } // Create a circle in X/Y space var circle = Enumerable.Range(0, numVertices) .Select(i => new PointD(radius * cos(360.0 * i / numVertices), radius * sin(360.0 * i / numVertices))); return(Ut.NewArray( // Side wall Enumerable.Range(0, numVertices) .Select(i => 360.0 * i / numVertices) .Select(angle => new PointD(radius * cos(angle), radius * sin(angle))) .SelectConsecutivePairs(true, (p1, p2) => new[] { pt(p1.X, p1.Y, startZ).WithNormal(p1.X, p1.Y, 0), pt(p2.X, p2.Y, startZ).WithNormal(p2.X, p2.Y, 0), pt(p2.X, p2.Y, endZ).WithNormal(p2.X, p2.Y, 0), pt(p1.X, p1.Y, endZ).WithNormal(p1.X, p1.Y, 0) }), // Caps new[] { circle.Reverse().Select(c => pt(c.X, c.Y, startZ).WithNormal(0, 0, -1)).ToArray() }, new[] { circle.Select(c => pt(c.X, c.Y, endZ).WithNormal(0, 0, 1)).ToArray() } ).SelectMany(x => x).ToArray()); }
/// <summary> /// Invoked by "Edit => Finish editing" or the relevant toolbar button. /// Leaves editing mode and saves the modified level in the level list, /// then returns to playing mode. /// </summary> private void finishEditingLevel(object sender, EventArgs e) { if (lstLevels.ActiveLevel == null || lstLevels.State != LevelListBox.LevelListBoxState.Editing) // this should never happen { Ut.InternalError(); } SokobanLevelStatus status = ctMainArea.Level.Validity; if (status != SokobanLevelStatus.Valid) { string problem = status == SokobanLevelStatus.NotEnclosed ? Program.Tr.Mainform_Validity_NotEnclosed : Program.Tr.Mainform_Validity_WrongNumber; if (DlgMessage.Show(problem + "\n\n" + Program.Tr.Mainform_Validity_CannotSave_Warning, Program.Tr.Mainform_MessageTitle_FinishEditing, DlgType.Error, Program.Tr.Mainform_Validity_CannotSave_btnSave, Program.Tr.Mainform_Validity_CannotSave_btnResume) == 1) { return; } } saveLevel(sender, e); }
private static IEnumerable <VertexInfo[]> Button() { var height = .04; var fh = height * .4; var width = .1; var fw = .09; var leans = new[] { .001, .001, .001, .001 }; var bézierSteps = 20; var patchPiece = BézierPatch(Ut.NewArray( Ut.NewArray(pt(width, 0, width), pt(width - leans[0], 0, width), pt(fw, 0, width), pt(0, 0, width)), Ut.NewArray(pt(width, 0, width - leans[0]), pt(width - leans[1], fh, width - leans[1]), pt(fw, fh, width - leans[2]), pt(0, fh, width - leans[3])), Ut.NewArray(pt(width, 0, fw), pt(width - leans[2], fh, fw), pt(fw, height, fw), pt(0, height, fw)), Ut.NewArray(pt(width, 0, 0), pt(width - leans[3], fh, 0), pt(fw, height, 0), pt(0, height, 0)) ), bézierSteps); //return CreateMesh(false, false, patchPiece); return(CreateMesh(false, false, Ut.NewArray(2 * bézierSteps - 1, 2 * bézierSteps - 1, (u, v) => new MeshVertexInfo( patchPiece[u < bézierSteps ? u : 2 * bézierSteps - 2 - u][v < bézierSteps ? v : 2 * bézierSteps - 2 - v].Apply(p => pt(v < bézierSteps ? p.X : -p.X, p.Y, u < bézierSteps ? p.Z : -p.Z)), u == 2 * bézierSteps - 2 ? Normal.Mine : Normal.Average, u == 0 ? Normal.Mine : Normal.Average, v == 2 * bézierSteps - 2 ? Normal.Mine : Normal.Average, v == 0 ? Normal.Mine : Normal.Average)))); }
public override ToolStripMenuItem[] CreateMenus(IIde ide) { var menuItems = new List <Tuple <ToolStripMenuItem, Func <bool> > >(); var update = Ut.Lambda(() => { foreach (var tuple in menuItems) { tuple.Item1.Checked = tuple.Item2(); } }); var createItem = Ut.Lambda((string label, Action action, Func <bool> checkedFunc) => { var menuItem = new ToolStripMenuItem(label, null, delegate { action(); update(); }); menuItems.Add(new Tuple <ToolStripMenuItem, Func <bool> >(menuItem, checkedFunc)); return(menuItem); }); var ret = Ut.NewArray <ToolStripMenuItem>( new ToolStripMenuItem("&Semantics", null, createItem("Input as &bytes", () => { _settings.InputType = IOType.Bytes; }, () => _settings.InputType == IOType.Bytes), createItem("Input as &numbers", () => { _settings.InputType = IOType.Numbers; }, () => _settings.InputType == IOType.Numbers), new ToolStripSeparator(), createItem("Output as b&ytes", () => { _settings.OutputType = IOType.Bytes; }, () => _settings.OutputType == IOType.Bytes), createItem("Output as n&umbers", () => { _settings.OutputType = IOType.Numbers; }, () => _settings.OutputType == IOType.Numbers), new ToolStripSeparator(), createItem("No implicit &mirroring", () => { _settings.ImplicitlyMirror = MirrorType.None; }, () => _settings.ImplicitlyMirror == MirrorType.None), createItem("Implicitly mirror source to the &left (e.g. *|= becomes =|*|=)", () => { _settings.ImplicitlyMirror = MirrorType.Left; }, () => _settings.ImplicitlyMirror == MirrorType.Left), createItem("Implicitly mirror source to the &right (e.g. *|= becomes *|=|*)", () => { _settings.ImplicitlyMirror = MirrorType.Right; }, () => _settings.ImplicitlyMirror == MirrorType.Right) ) ); update(); return(ret); }
private static IEnumerable <VertexInfo[]> ScreenFrame() { var f = .0075; var h = .025; return(CreateMesh(true, true, Bézier(p(.1, 0), p(.1, f), p(.1 - h + f, h), p(.1 - h, h), 20).Select((p, first, last) => new BevelPoint(p.X, p.Y, first || last ? Normal.Mine : Normal.Average, first || last ? Normal.Mine : Normal.Average)).Concat( Bézier(p(h, h), p(h - f, h), p(0, f), p(0, 0), 20).Select((p, first, last) => new BevelPoint(p.X, p.Y, first || last ? Normal.Mine : Normal.Average, first || last ? Normal.Mine : Normal.Average))) .Select(bi => Ut.NewArray( // Bottom right bpa(-1 + bi.X, bi.Y, -.5 + bi.X, bi.Before, bi.After, Normal.Mine, Normal.Mine), // Top right quarterCircle(.5, bi.X).Reverse().Select((p, first, last) => pt(-1 + p.X, bi.Y, 1 - p.Z, bi.Before, bi.After, first || last ? Normal.Mine : Normal.Average, first || last ? Normal.Mine : Normal.Average)), // Top left bpa(1 - bi.X, bi.Y, 1 - bi.X, bi.Before, bi.After, Normal.Mine, Normal.Mine), // Bottom left quarterCircle(.5, bi.X).Reverse().Select((p, first, last) => pt(1 - p.X, bi.Y, -.5 + p.Z, bi.Before, bi.After, first || last ? Normal.Mine : Normal.Average, first || last ? Normal.Mine : Normal.Average)), null ).Where(x => x != null).SelectMany(x => x).ToArray()).ToArray())); }
/// <summary>Sets the host part of the URL, consisting of the domain and optionally the port number.</summary> internal void SetHost(string host) { Ut.Assert(host != null); var colonPos = host.IndexOf(':'); if (colonPos < 0) { if (host.Length > 0 && host[host.Length - 1] == '.') { Domain = host.Substring(0, host.Length - 1); } else { Domain = host; } Port = Https ? 443 : 80; } else { if (colonPos > 0 && host[colonPos - 1] == '.') { Domain = host.Substring(0, colonPos - 1); } else { Domain = host.Substring(0, colonPos); } int port; if (!int.TryParse(host.Substring(colonPos + 1), out port)) { throw new ArgumentException(); } Port = port; } ParentDomains = HttpHelper.EmptyStrings; }
private void discoverGameIds(bool full, HClient hClient, Func <SummonerInfo, string> getAuthHeader, Action <string> logger) { int step = 15; int count = step; int index = 0; while (true) { logger?.Invoke("{0}/{1}: retrieving games at {2} of {3}".Fmt(Name, Region, index, count)); var url = $"https://acs.leagueoflegends.com/v1/stats/player_history/auth?begIndex={index}&endIndex={index + step}&"; var json = retryOnAuthHeaderFail(url, hClient, getAuthHeader).Expect(HttpStatusCode.OK).DataJson; Ut.Assert(json["accountId"].GetLongLenient() == AccountId); // json["platformId"] may be different to Region for accounts that have been transferred to another region index += step; count = json["games"]["gameCount"].GetInt(); bool anyNew = false; foreach (var gameId in json["games"]["games"].GetList().Select(js => js["gameId"].GetLong().ToString())) { anyNew |= _GameIds.Add(gameId); } if (index >= count) { break; } if (!anyNew && !full) { break; } } logger?.Invoke($"{Name}/{Region}: done."); save(); }
private static IEnumerable <VertexInfo[]> SelectorFrame() { var f = .01; var h = .02; return(CreateMesh(true, true, Bézier(p(.05, 0), p(.05, f), p(.05 - h + f, h), p(.05 - h, h), 20).Select((p, first, last) => new BevelPoint(p.X, p.Y, first || last ? Normal.Mine : Normal.Average, first || last ? Normal.Mine : Normal.Average)).Concat( Bézier(p(h, h), p(h - f, h), p(0, f), p(0, 0), 20).Select((p, first, last) => new BevelPoint(p.X, p.Y, first || last ? Normal.Mine : Normal.Average, first || last ? Normal.Mine : Normal.Average))) .Select(bi => Ut.NewArray( // Bottom right bpa(-1 + bi.X, bi.Y, -1 + bi.X, bi.Before, bi.After, Normal.Mine, Normal.Mine), // Top right bpa(-1 + bi.X, bi.Y, -.55 - bi.X, bi.Before, bi.After, Normal.Mine, Normal.Mine), // Top left bpa(.5 - bi.X, bi.Y, -.55 - bi.X, bi.Before, bi.After, Normal.Mine, Normal.Mine), // Bottom left bpa(.5 - bi.X, bi.Y, -1 + bi.X, bi.Before, bi.After, Normal.Mine, Normal.Mine), null ).Where(x => x != null).SelectMany(x => x).ToArray()).ToArray())); }
protected override MemberInfo getMember(Type[] typeGenerics, Type[] methodGenerics, int numGenerics) { Ut.Assert(Inner != null); return((getMember(Inner, typeGenerics, methodGenerics, 0) as Type).NullOr(type => type.MakePointerType())); }