mirror of
https://github.com/chylex/Query.git
synced 2025-05-20 01:34:06 +02:00
Reformat code
This commit is contained in:
parent
9a386d25f4
commit
a283fe7c9e
AppCalc
AppConv
General
Units
Utils
AppWindows
Base
Query
@ -151,9 +151,15 @@ namespace AppCalc{
|
||||
}
|
||||
|
||||
switch (token) {
|
||||
case "+": stack.Push(operand1+operand2); break;
|
||||
case "-": stack.Push(operand1-operand2); break;
|
||||
case "*": stack.Push(operand1*operand2); break;
|
||||
case "+":
|
||||
stack.Push(operand1 + operand2);
|
||||
break;
|
||||
case "-":
|
||||
stack.Push(operand1 - operand2);
|
||||
break;
|
||||
case "*":
|
||||
stack.Push(operand1 * operand2);
|
||||
break;
|
||||
|
||||
case "/":
|
||||
if (operand2 == 0M) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
namespace AppCalc {
|
||||
internal static class Operators{
|
||||
static class Operators {
|
||||
internal static readonly string[] With2Operands = { "+", "-", "*", "/", "%", "^" };
|
||||
|
||||
internal static int GetPrecedence(string token) {
|
||||
|
@ -4,7 +4,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace AppConv.General {
|
||||
internal abstract class DecimalUnitConverterBase<T> : IUnitType where T : struct{
|
||||
abstract class DecimalUnitConverterBase<T> : IUnitType where T : struct {
|
||||
internal sealed class DecimalFuncMap : Dictionary<T, Func<decimal, decimal>> {
|
||||
public DecimalFuncMap() {}
|
||||
public DecimalFuncMap(int capacity) : base(capacity) {}
|
||||
@ -19,23 +19,11 @@ namespace AppConv.General{
|
||||
protected abstract DecimalFuncMap ConvertTo { get; }
|
||||
protected abstract DecimalFuncMap ConvertFrom { get; }
|
||||
|
||||
protected virtual int Precision{
|
||||
get{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
protected virtual int Precision => 0;
|
||||
|
||||
protected virtual bool CaseCheck{
|
||||
get{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected virtual bool CaseCheck => false;
|
||||
|
||||
protected virtual NumberStyles NumberStyle{
|
||||
get{
|
||||
return NumberStyles.Float & ~NumberStyles.AllowLeadingSign;
|
||||
}
|
||||
}
|
||||
protected virtual NumberStyles NumberStyle => NumberStyles.Float & ~NumberStyles.AllowLeadingSign;
|
||||
|
||||
protected virtual string ProcessSrc(string src) {
|
||||
return src;
|
||||
@ -82,7 +70,7 @@ namespace AppConv.General{
|
||||
src = ProcessSrc(src);
|
||||
dst = ProcessDst(dst);
|
||||
|
||||
KeyValuePair<string, T>[] pairs = new KeyValuePair<string, T>[2];
|
||||
var pairs = new KeyValuePair<string, T>[2];
|
||||
|
||||
for (int index = 0; index < 2; index++) {
|
||||
string str = index == 0 ? src : dst;
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace AppConv.General {
|
||||
internal abstract class DecimalUnitConverterSimple<T> : DecimalUnitConverterBase<T> where T : struct{
|
||||
abstract class DecimalUnitConverterSimple<T> : DecimalUnitConverterBase<T> where T : struct {
|
||||
// ReSharper disable once StaticMemberInGenericType
|
||||
private static readonly Func<decimal, decimal> FuncNoChange = val => val;
|
||||
|
||||
@ -11,35 +11,15 @@ namespace AppConv.General{
|
||||
|
||||
private int invalidUnitObject = -1;
|
||||
|
||||
protected sealed override NameMap Names{
|
||||
get{
|
||||
return UnitNames;
|
||||
}
|
||||
}
|
||||
protected sealed override NameMap Names => UnitNames;
|
||||
|
||||
protected sealed override DecimalFuncMap ConvertFrom{
|
||||
get{
|
||||
return MapFrom;
|
||||
}
|
||||
}
|
||||
protected sealed override DecimalFuncMap ConvertFrom => MapFrom;
|
||||
|
||||
protected sealed override DecimalFuncMap ConvertTo{
|
||||
get{
|
||||
return MapTo;
|
||||
}
|
||||
}
|
||||
protected sealed override DecimalFuncMap ConvertTo => MapTo;
|
||||
|
||||
protected override int Precision{
|
||||
get{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
protected override int Precision => 3;
|
||||
|
||||
protected override bool CaseCheck{
|
||||
get{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
protected override bool CaseCheck => true;
|
||||
|
||||
protected void AddUnit(T unitObject, params string[] names) {
|
||||
foreach (string name in names) {
|
||||
@ -56,7 +36,7 @@ namespace AppConv.General{
|
||||
}
|
||||
|
||||
protected void SetInvalidUnitObject(T unitObject) {
|
||||
this.invalidUnitObject = (int)(object)unitObject;
|
||||
invalidUnitObject = (int) (object) unitObject;
|
||||
}
|
||||
|
||||
protected sealed override bool IsValueInvalid(T value) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
namespace AppConv.General {
|
||||
internal interface IUnitType{
|
||||
interface IUnitType {
|
||||
bool TryProcess(string src, string dst, out string result);
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,15 @@
|
||||
using AppConv.General;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Angle : DecimalUnitConverterSimple<Angle.Units>{
|
||||
class Angle : DecimalUnitConverterSimple<Angle.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, Degree, Radian, Gradian
|
||||
Invalid = 0,
|
||||
Degree,
|
||||
Radian,
|
||||
Gradian
|
||||
}
|
||||
|
||||
protected override int Precision{
|
||||
get{
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
protected override int Precision => 4;
|
||||
|
||||
public Angle() {
|
||||
AddUnit(Units.Degree, "deg", "degree", "degrees", "arc degree", "arc degrees", "arcdegree", "arcdegrees", "°");
|
||||
|
@ -1,9 +1,24 @@
|
||||
using AppConv.General;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Area : DecimalUnitConverterSimple<Area.Units>{
|
||||
class Area : DecimalUnitConverterSimple<Area.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, SquareMM, SquareCM, SquareDM, SquareM, SquareKM, SquareMile, SquareYard, SquareFoot, SquareInch, Acre, Centiare, Deciare, Are, Decare, Hectare
|
||||
Invalid = 0,
|
||||
SquareMM,
|
||||
SquareCM,
|
||||
SquareDM,
|
||||
SquareM,
|
||||
SquareKM,
|
||||
SquareMile,
|
||||
SquareYard,
|
||||
SquareFoot,
|
||||
SquareInch,
|
||||
Acre,
|
||||
Centiare,
|
||||
Deciare,
|
||||
Are,
|
||||
Decare,
|
||||
Hectare
|
||||
}
|
||||
|
||||
public Area() {
|
||||
|
@ -5,9 +5,14 @@ using AppConv.General;
|
||||
using AppConv.Utils;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Length : DecimalUnitConverterSimple<Length.Units>{
|
||||
class Length : DecimalUnitConverterSimple<Length.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, Meter, Inch, Foot, Yard, Mile
|
||||
Invalid = 0,
|
||||
Meter,
|
||||
Inch,
|
||||
Foot,
|
||||
Yard,
|
||||
Mile
|
||||
}
|
||||
|
||||
private static readonly string[] NamesInch = { "in", "inch", "inches", "\"", "''" };
|
||||
|
@ -6,7 +6,7 @@ using AppConv.Utils;
|
||||
using Base;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Radix : IUnitType{
|
||||
class Radix : IUnitType {
|
||||
private static readonly Dictionary<string, int> RadixDescriptions = new Dictionary<string, int> {
|
||||
{ "UNARY", 1 },
|
||||
{ "BINARY", 2 },
|
||||
|
@ -3,9 +3,11 @@ using AppConv.General;
|
||||
using AppConv.Utils;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Storage : DecimalUnitConverterSimple<Storage.Units>{
|
||||
class Storage : DecimalUnitConverterSimple<Storage.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, Byte, Bit
|
||||
Invalid = 0,
|
||||
Byte,
|
||||
Bit
|
||||
}
|
||||
|
||||
public Storage() {
|
||||
@ -16,7 +18,7 @@ namespace AppConv.Units {
|
||||
|
||||
SetInvalidUnitObject(Units.Invalid);
|
||||
|
||||
SI.ExtededProperties bitConversionProperties = new SI.ExtededProperties{
|
||||
var bitConversionProperties = new SI.ExtededProperties {
|
||||
FactorPredicate = factor => factor > 0 && factor % 3 == 0,
|
||||
FromFunctionGenerator = exponent => () => (decimal) Math.Pow(1024, -(int) (exponent / 3)),
|
||||
ToFunctionGenerator = exponent => () => (decimal) Math.Pow(1024, (int) (exponent / 3))
|
||||
|
@ -4,9 +4,17 @@ using AppConv.General;
|
||||
using Base.Utils;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Temperature : DecimalUnitConverterBase<Temperature.Units>{
|
||||
class Temperature : DecimalUnitConverterBase<Temperature.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, Celsius, Kelvin, Fahrenheit, Rankine, Delisle, Newton, Reaumur, Romer
|
||||
Invalid = 0,
|
||||
Celsius,
|
||||
Kelvin,
|
||||
Fahrenheit,
|
||||
Rankine,
|
||||
Delisle,
|
||||
Newton,
|
||||
Reaumur,
|
||||
Romer
|
||||
}
|
||||
|
||||
private static readonly NameMap UnitNames = new NameMap(21) {
|
||||
@ -57,35 +65,15 @@ namespace AppConv.Units{
|
||||
|
||||
private static readonly Regex RegexCleanup = new Regex("deg(?:rees?)?|°", RegexUtils.Text);
|
||||
|
||||
protected override NameMap Names{
|
||||
get{
|
||||
return UnitNames;
|
||||
}
|
||||
}
|
||||
protected override NameMap Names => UnitNames;
|
||||
|
||||
protected override DecimalFuncMap ConvertFrom{
|
||||
get{
|
||||
return FromCelsius;
|
||||
}
|
||||
}
|
||||
protected override DecimalFuncMap ConvertFrom => FromCelsius;
|
||||
|
||||
protected override DecimalFuncMap ConvertTo{
|
||||
get{
|
||||
return ToCelsius;
|
||||
}
|
||||
}
|
||||
protected override DecimalFuncMap ConvertTo => ToCelsius;
|
||||
|
||||
protected override int Precision{
|
||||
get{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
protected override int Precision => 2;
|
||||
|
||||
protected override NumberStyles NumberStyle{
|
||||
get{
|
||||
return NumberStyles.Float;
|
||||
}
|
||||
}
|
||||
protected override NumberStyles NumberStyle => NumberStyles.Float;
|
||||
|
||||
protected override string ProcessSrc(string src) {
|
||||
return RegexCleanup.Replace(src, "");
|
||||
|
@ -2,9 +2,15 @@
|
||||
using AppConv.Utils;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Volume : DecimalUnitConverterSimple<Volume.Units>{
|
||||
class Volume : DecimalUnitConverterSimple<Volume.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, Liter, CubicMM, CubicCM, CubicDM, CubicM, CubicKM
|
||||
Invalid = 0,
|
||||
Liter,
|
||||
CubicMM,
|
||||
CubicCM,
|
||||
CubicDM,
|
||||
CubicM,
|
||||
CubicKM
|
||||
}
|
||||
|
||||
public Volume() {
|
||||
|
@ -2,9 +2,13 @@
|
||||
using AppConv.Utils;
|
||||
|
||||
namespace AppConv.Units {
|
||||
internal class Weight : DecimalUnitConverterSimple<Weight.Units>{
|
||||
class Weight : DecimalUnitConverterSimple<Weight.Units> {
|
||||
internal enum Units {
|
||||
Invalid = 0, Gram, Pound, Ounce, Stone
|
||||
Invalid = 0,
|
||||
Gram,
|
||||
Pound,
|
||||
Ounce,
|
||||
Stone
|
||||
}
|
||||
|
||||
public Weight() {
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AppConv.Utils {
|
||||
internal static class RadixConversion{
|
||||
static class RadixConversion {
|
||||
private const string Characters = "0123456789ABCDEF";
|
||||
|
||||
public static bool IsBaseValid(int checkedBase) {
|
||||
@ -62,7 +62,7 @@ namespace AppConv.Utils{
|
||||
return Characters[(int) wip].ToString();
|
||||
}
|
||||
else {
|
||||
StringBuilder converted = new StringBuilder();
|
||||
var converted = new StringBuilder();
|
||||
|
||||
while (wip >= toBase) {
|
||||
int index = (int) (wip % toBase);
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using AppConv.General;
|
||||
|
||||
namespace AppConv.Utils {
|
||||
internal static class SI{
|
||||
static class SI {
|
||||
private static readonly List<Tuple<string, string, int>> Factors = new List<Tuple<string, string, int>> {
|
||||
new Tuple<string, string, int>("yotta", "Y", 24),
|
||||
new Tuple<string, string, int>("zetta", "Z", 21),
|
||||
|
@ -5,29 +5,31 @@ using System.IO;
|
||||
using Base;
|
||||
|
||||
namespace AppSys.Handlers {
|
||||
internal class HandlerApps : IHandler{
|
||||
class HandlerApps : IHandler {
|
||||
private static readonly string PathSystem = Environment.GetFolderPath(Environment.SpecialFolder.System);
|
||||
|
||||
private static readonly Dictionary<string, ProcessStartInfo> Mappings = new Dictionary<string, ProcessStartInfo> {
|
||||
{ "audio", new ProcessStartInfo{
|
||||
{
|
||||
"audio", new ProcessStartInfo {
|
||||
FileName = Path.Combine(PathSystem, "control.exe"),
|
||||
Arguments = "mmsys.cpl"
|
||||
} },
|
||||
|
||||
{ "programs", new ProcessStartInfo{
|
||||
}
|
||||
}, {
|
||||
"programs", new ProcessStartInfo {
|
||||
FileName = Path.Combine(PathSystem, "control.exe"),
|
||||
Arguments = "appwiz.cpl"
|
||||
} },
|
||||
|
||||
{ "system", new ProcessStartInfo{
|
||||
}
|
||||
}, {
|
||||
"system", new ProcessStartInfo {
|
||||
FileName = Path.Combine(PathSystem, "control.exe"),
|
||||
Arguments = "sysdm.cpl"
|
||||
} },
|
||||
|
||||
{ "environment", new ProcessStartInfo{
|
||||
}
|
||||
}, {
|
||||
"environment", new ProcessStartInfo {
|
||||
FileName = Path.Combine(PathSystem, "rundll32.exe"),
|
||||
Arguments = "sysdm.cpl,EditEnvironmentVariables"
|
||||
} }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> Substitutions = new Dictionary<string, string> {
|
||||
@ -52,6 +54,7 @@ namespace AppSys.Handlers {
|
||||
}
|
||||
|
||||
using (Process.Start(Mappings[key])) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ using System.Text;
|
||||
using Base;
|
||||
|
||||
namespace AppSys.Handlers {
|
||||
internal class HandlerProcesses : IHandler{
|
||||
class HandlerProcesses : IHandler {
|
||||
public bool Matches(Command cmd) {
|
||||
return cmd.Text.StartsWith("kill ", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
@ -36,7 +36,7 @@ namespace AppSys.Handlers{
|
||||
return "No.";
|
||||
}
|
||||
|
||||
StringBuilder build = new StringBuilder();
|
||||
var build = new StringBuilder();
|
||||
build.Append("Killed ").Append(succeeded).Append(" process").Append(succeeded == 1 ? "" : "es");
|
||||
|
||||
if (failed > 0) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Base;
|
||||
|
||||
namespace AppSys {
|
||||
internal interface IHandler{
|
||||
interface IHandler {
|
||||
bool Matches(Command cmd);
|
||||
string Handle(Command cmd);
|
||||
}
|
||||
|
@ -27,14 +27,10 @@ namespace Base{
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSingleToken{
|
||||
get{
|
||||
return Text.IndexOf(' ') == -1;
|
||||
}
|
||||
}
|
||||
public bool IsSingleToken => Text.IndexOf(' ') == -1;
|
||||
|
||||
public Command(string text) {
|
||||
this.Text = text;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public Command ReplaceBrackets(MatchEvaluator evaluator) {
|
||||
|
@ -5,7 +5,7 @@ namespace Base{
|
||||
public Command Command { get; private set; }
|
||||
|
||||
public CommandEventArgs(string text) {
|
||||
this.Command = new Command(text);
|
||||
Command = new Command(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ using System.Windows.Forms;
|
||||
namespace Query.Controls {
|
||||
sealed partial class QueryHistoryLog : UserControl {
|
||||
public enum EntryType {
|
||||
UserInput, CommandResult, Information, Error
|
||||
UserInput,
|
||||
CommandResult,
|
||||
Information,
|
||||
Error
|
||||
}
|
||||
|
||||
private static readonly Dictionary<EntryType, Color> EntryColorMap = new Dictionary<EntryType, Color> {
|
||||
|
@ -17,8 +17,8 @@ namespace Query.Controls{
|
||||
}
|
||||
|
||||
public void Setup(CommandHistory historyObj, Action<string> logFunc) {
|
||||
this.history = historyObj;
|
||||
this.log = logFunc;
|
||||
history = historyObj;
|
||||
log = logFunc;
|
||||
}
|
||||
|
||||
private void OnCommandRan() {
|
||||
|
@ -5,17 +5,9 @@ namespace Query.Core{
|
||||
private readonly List<string> queries = new List<string>();
|
||||
private readonly List<string> results = new List<string>();
|
||||
|
||||
public IList<string> Queries{
|
||||
get{
|
||||
return queries;
|
||||
}
|
||||
}
|
||||
public IList<string> Queries => queries;
|
||||
|
||||
public IList<string> Results{
|
||||
get{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
public IList<string> Results => results;
|
||||
|
||||
public void AddQuery(string text) {
|
||||
queries.Add(text);
|
||||
|
Loading…
Reference in New Issue
Block a user