public void TestFuncScalarExpressionWithMathExpressionArray()
        {
            DataStorage.WipeNonDataFields();

            var arr = new[] { "1", "2", "3", "4", "5", "6", "7" };

            DataStorage.Add(new ArrayExpression("data", "item", arr));
            var a = DataStorage.GetArrayExpression("data.item");

            Assert.AreEqual(arr.Length, a.Exprs.Length);
            for (var i = 0; i < a.Exprs.Length; ++i)
            {
                Assert.AreEqual(a.Exprs[i].CachedValue.AsDouble + "", arr[i]);
            }

            DataStorage.Add(new ArrayExpression("data", "item2", "data.item*2", a.Exprs.Length));
            var b = DataStorage.GetArrayExpression("data.item2");

            Assert.AreEqual(arr.Length, b.Exprs.Length);
            for (var i = 0; i < b.Exprs.Length; ++i)
            {
                Assert.AreEqual(b.Exprs[i].CachedValue.AsDouble / 2 + "", arr[i]);
            }

            DataStorage.Add(new ScalarExpression("data", "arrlen", "len(data.item2)"));
            Assert.AreEqual(DataStorage.GetScalarExpression("data.arrlen").CachedValue.AsDouble, arr.Length,
                            double.Epsilon);
        }
Example #2
0
        public async Task Amt(SocketGuildUser targetUser, [Remainder] string thing)
        {
            var ds  = new DataStorage <AmtObject>("Storage/AmtStorage.json");
            var amt = new AmtObject {
                User = targetUser, Thing = thing.ToLower()
            };
            ushort percentage = 0;

            var listOfMatching = from a in ds.ReturnList()
                                 where a.Equals(amt)
                                 select a;
            bool exists = listOfMatching.Any();

            // If the object doesn't already exist in storage
            if (!exists)
            {
                percentage = (ushort)R.Next(101);
                amt.Value  = percentage;
                ds.Add(amt);
            }

            var obj = from a in ds.ReturnList()
                      where a.Equals(amt)
                      select a.Value;

            percentage = obj.FirstOrDefault();

            await Context.Channel.SendMessageAsync($"{GetNickname(targetUser)} is {percentage}% {thing}");
        }
        public void TestConstantScalar()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "123"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 123.0, double.Epsilon);
        }
        public void TestFuncExpressionWithConstant()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "1024"));
            DataStorage.Add(new ScalarExpression("data", "varsqrt", "sqrt(var)"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 1024.0, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.varsqrt").CachedValue.AsDouble, 32.0, double.Epsilon);
        }
        public void TestComplexMathExpressionWithConstantScalar()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "123"));
            DataStorage.Add(new ScalarExpression("data", "var2", "data.var - ( 1 + ( ( 2.0 + 3 ) * ( 4 * 5.0 ) ) )"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 123.0, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.var2").CachedValue.AsDouble,
                            123.0 - (1 + (2.0 + 3) * (4 * 5.0)), double.Epsilon);
        }
        public void TestObjectNotSpecified()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "123"));
            DataStorage.Add(new ScalarExpression("data", "var2", "var*2"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 123.0, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.var2").CachedValue.AsDouble, 123.0 * 2,
                            double.Epsilon);
        }
        public void TestTextExpressionWithConstant()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "123"));
            DataStorage.Add(new ScalarExpression("data", "str", "var + \" is 123\""));
            DataStorage.Add(new ScalarExpression("data", "str2", "var + \" is \\\" 123\""));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 123.0, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.str").CachedValue.AsString, "123 is 123");
            Assert.AreEqual(DataStorage.GetScalarExpression("data.str2").CachedValue.AsString, "123 is \" 123");
        }
        public void TestFuncScalarExpressionWithMathExpressionArrayChanged()
        {
            DataStorage.WipeNonDataFields();

            var arr = new[] { "1", "2", "3", "4", "5", "6", "7" };

            DataStorage.Add(new ArrayExpression("data", "item", arr));
            var a = DataStorage.GetArrayExpression("data.item");

            Assert.AreEqual(arr.Length, a.Exprs.Length);
            for (var i = 0; i < a.Exprs.Length; ++i)
            {
                Assert.AreEqual(a.Exprs[i].CachedValue.AsDouble + "", arr[i]);
            }

            DataStorage.Add(new ArrayExpression("data", "item2", "data.item*2", a.Exprs.Length));
            var b = DataStorage.GetArrayExpression("data.item2");

            Assert.AreEqual(arr.Length, b.Exprs.Length);
            for (var i = 0; i < b.Exprs.Length; ++i)
            {
                Assert.AreEqual(b.Exprs[i].CachedValue.AsDouble / 2 + "", arr[i]);
            }

            DataStorage.Add(new ScalarExpression("data", "arrlen", "len(data.item2)"));
            Assert.AreEqual(DataStorage.GetScalarExpression("data.arrlen").CachedValue.AsDouble, arr.Length,
                            double.Epsilon);

            DataStorage.Add(new ScalarExpression("data", "arrmean", "mean(data.item2)"));
            // mean (2, 4, 6, 8, 10, 12, 14) = 8
            Assert.AreEqual(DataStorage.GetScalarExpression("data.arrmean").CachedValue.AsDouble, 8, double.Epsilon);

            a.Exprs[5].SetRawExpression("97");
            arr[5] = "97";

            // mean (2, 4, 6, 8, 10, 194, 14) = 34
            Assert.AreEqual(DataStorage.GetScalarExpression("data.arrmean").CachedValue.AsDouble, 34, double.Epsilon);

            for (var i = 0; i < a.Exprs.Length; ++i)
            {
                Assert.AreEqual(a.Exprs[i].CachedValue.AsDouble + "", arr[i]);
            }

            for (var i = 0; i < b.Exprs.Length; ++i)
            {
                Assert.AreEqual(b.Exprs[i].CachedValue.AsDouble / 2 + "", arr[i]);
            }

            DataStorage.Add(new ScalarExpression("data", "arrmax", "max(data.item2)"));
            // max (2, 4, 6, 8, 10, 194, 14) = 194
            Assert.AreEqual(DataStorage.GetScalarExpression("data.arrmax").CachedValue.AsDouble, 194, double.Epsilon);
        }
Example #9
0
        public override void Apply()
        {
            if (!Applied)
            {
                StepManager.Figures.Add(TextFigure);
            }

            Figure.FigureColor.SetIndex(0);
            TextFigure.FigureText.SetIndex(0);

            if ((TextFigure.X == null) || !Applied)
            {
                TextFigure.X = DataStorage.Add(new ScalarExpression(Figure.Name, "x", X, Figure.IsGuide));
            }
            else
            {
                TextFigure.X.SetRawExpression(X);
            }

            if ((TextFigure.Y == null) || !Applied)
            {
                TextFigure.Y = DataStorage.Add(new ScalarExpression(Figure.Name, "y", Y, Figure.IsGuide));
            }
            else
            {
                TextFigure.Y.SetRawExpression(Y);
            }

            if ((TextFigure.Width == null) || !Applied)
            {
                TextFigure.Width = DataStorage.Add(new ScalarExpression(Figure.Name, "width", Width, Figure.IsGuide));
            }
            else
            {
                TextFigure.Width.SetRawExpression(Width);
            }

            if ((TextFigure.Height == null) || !Applied)
            {
                TextFigure.Height =
                    DataStorage.Add(new ScalarExpression(Figure.Name, "height", Height, Figure.IsGuide));
            }
            else
            {
                TextFigure.Height.SetRawExpression(Height);
            }

            Applied = true;

            CopyStaticFigure();
        }
        public override void Apply()
        {
            if (!Applied)
            {
                StepManager.Figures.Add(EllipseFigure);
            }

            Figure.FigureColor.SetIndex(0);

            if ((EllipseFigure.X == null) || !Applied)
            {
                EllipseFigure.X = DataStorage.Add(new ScalarExpression(Figure.Name, "x", X, Figure.IsGuide));
            }
            else
            {
                EllipseFigure.X.SetRawExpression(X);
            }

            if ((EllipseFigure.Y == null) || !Applied)
            {
                EllipseFigure.Y = DataStorage.Add(new ScalarExpression(Figure.Name, "y", Y, Figure.IsGuide));
            }
            else
            {
                EllipseFigure.Y.SetRawExpression(Y);
            }

            if ((EllipseFigure.Radius1 == null) || !Applied)
            {
                EllipseFigure.Radius1 =
                    DataStorage.Add(new ScalarExpression(Figure.Name, "radius1", Radius, Figure.IsGuide));
            }
            else
            {
                EllipseFigure.Radius1.SetRawExpression(Radius);
            }

            if ((EllipseFigure.Radius2 == null) || !Applied)
            {
                EllipseFigure.Radius2 =
                    DataStorage.Add(new ScalarExpression(Figure.Name, "radius2", Radius, Figure.IsGuide));
            }
            else
            {
                EllipseFigure.Radius2.SetRawExpression(Radius);
            }

            Applied = true;

            CopyStaticFigure();
        }
Example #11
0
        public MainForm()
        {
            InitializeComponent();

            _hotkeys = new Dictionary <Keys, Action>
            {
                { Keys.R, () => rectLabel_Click(rectLabel, EventArgs.Empty) },
                { Keys.C, () => circleLabel_Click(circleLabel, EventArgs.Empty) },
                { Keys.L, () => lineLabel_Click(lineLabel, EventArgs.Empty) },
                { Keys.T, () => textLabel_Click(textLabel, EventArgs.Empty) },
                { Keys.M, () => moveLabel_Click(moveLabel, EventArgs.Empty) },
                { Keys.S, () => scaleLabel_Click(scaleLabel, EventArgs.Empty) },
                { Keys.E, () => resizeLabel_Click(resizeLabel, EventArgs.Empty) },
                { Keys.O, () => rotateLabel_Click(rotateLabel, EventArgs.Empty) },
                { Keys.G, () => guideLabel_Click(guideLabel, EventArgs.Empty) },
                { Keys.P, () => loopLabel_Click(loopLabel, EventArgs.Empty) },
                { Keys.H, () => straightLabel_Click(straightLabel, EventArgs.Empty) },
                { Keys.A, () => addStepAfterLabel_Click(addStepAfterLabel, EventArgs.Empty) },
                { Keys.B, () => addStepBeforeLabel_Click(addStepBeforeLabel, EventArgs.Empty) },
                { Keys.D, () => addStepLoopedLabel_Click(addStepLoopedLabel, EventArgs.Empty) },
                { Keys.F, () => markAsFinalLabel_Click(markAsFinalLabel, EventArgs.Empty) },
                { Keys.X, () => exportLabel_Click(exportLabel, EventArgs.Empty) },
                { Keys.N, () => canvasLabel_Click(canvasLabel, EventArgs.Empty) }
            };

            RedrawNeeded = Redraw;

            StepManager.StepEditor      = stepEditor1;
            StepManager.StepListControl = _stepListControl1;
            _stepListControl1.MainForm  = this;

            DataStorage.Add(new ScalarExpression("canvas", "height", Drawer.CanvasHeight.ToString()));
            DataStorage.Add(new ScalarExpression("canvas", "width", Drawer.CanvasWidth.ToString()));
            DataStorage.Add(new ScalarExpression("canvas", "x", "0"));
            DataStorage.Add(new ScalarExpression("canvas", "y", "0"));

            AddCanvasMagnets();

            _mainGraphics = new MainGraphicOutput {
                DrawingFunc = Drawer.DrawScene
            };
            elementHost1.Child         = _mainGraphics;
            _mainGraphics.MouseDown   += MainGraphicsOnMouseDown;
            _mainGraphics.MouseMove   += MainGraphicsOnMouseMove;
            _mainGraphics.MouseUp     += MainGraphicsOnMouseUp;
            _mainGraphics.MouseLeave  += MainGraphicsOnMouseLeave;
            _mainGraphics.MouseEnter  += MainGraphicsOnMouseEnter;
            _mainGraphics.SizeChanged += MainGraphicsOnSizeChanged;

            ActiveControl = _stepListControl1;
        }
        public void TestMathUnaryOpWithConstantScalar()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var1", "-123"));
            DataStorage.Add(new ScalarExpression("data", "var2", "28*(-11)"));
            DataStorage.Add(new ScalarExpression("data", "var3", "28 * -11"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var1").CachedValue.AsDouble, -123, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.var2").CachedValue.AsDouble, 28 * -11,
                            double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.var3").CachedValue.AsDouble, 28 * -11,
                            double.Epsilon);
        }
        public void TestCanBeRemoved()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "123"));
            DataStorage.Add(new ScalarExpression("data", "var2", "data.var*2"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 123.0, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.var2").CachedValue.AsDouble, 123.0 * 2,
                            double.Epsilon);

            Assert.IsFalse(DataStorage.GetScalarExpression("data.var").CanBeRemoved);
            Assert.IsTrue(DataStorage.GetScalarExpression("data.var2").CanBeRemoved);
        }
        public void TestConstantArray()
        {
            DataStorage.WipeNonDataFields();

            var arr = new[] { "1", "2", "3", "4", "5", "6", "7" };

            DataStorage.Add(new ArrayExpression("data", "item", arr));
            var a = DataStorage.GetArrayExpression("data.item");

            Assert.AreEqual(arr.Length, a.Exprs.Length);
            for (var i = 0; i < a.Exprs.Length; ++i)
            {
                Assert.AreEqual(a.Exprs[i].CachedValue.AsDouble + "", arr[i]);
            }
        }
        public void TestFuncExpressionWithMathExpression()
        {
            DataStorage.WipeNonDataFields();

            DataStorage.Add(new ScalarExpression("data", "var", "1024"));
            DataStorage.Add(new ScalarExpression("data", "vardiv", "data.var/4"));
            DataStorage.Add(new ScalarExpression("data", "vardivsqrt", "sqrt(vardiv)"));

            Assert.AreEqual(DataStorage.GetScalarExpression("data.var").CachedValue.AsDouble, 1024.0, double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.vardiv").CachedValue.AsDouble, 1024.0 / 4,
                            double.Epsilon);
            Assert.AreEqual(DataStorage.GetScalarExpression("data.vardivsqrt").CachedValue.AsDouble,
                            Math.Sqrt(1024.0 / 4),
                            double.Epsilon);
        }
Example #16
0
 private void ValueTextBoxTextChanged(object sender, EventArgs eventArgs)
 {
     if (!_ignoreTextChange && !string.IsNullOrWhiteSpace(textBox2.Text))
     {
         if (Expr == null)
         {
             Expr = DataStorage.Add(new ScalarExpression("data", textBox1.Text, textBox2.Text));
             Expr.ValueChanged += ExprValueChanged;
         }
         else
         {
             Expr.SetRawExpression(textBox2.Text);
         }
         StepManager.RefreshToCurrentStep();
     }
 }
        public async Task UsersGetUserByLoginPassword()
        {
            form.buttonAuth.Enabled = false;

            string login    = form.textBoxLogin.Text;
            string password = form.textBoxPassword.Text;

            Response response = await API.UsersGetUserByLoginPassword(login, password);

            if (response.Status == Response.StatusList.OK)
            {
                User user = JsonConvert.DeserializeObject <User>(response.Data);
                form.textBoxResult.Text = "Success";
                DataStorage.Add("user", user);
                new FormMain().Show();
                form.Hide();
            }
            else
            {
                form.buttonAuth.Enabled = true;
                form.textBoxResult.Text = $"Error: {response.Data}";
            }
        }
Example #18
0
 private bool TryChangeData(string data)
 {
     _ignoreTextChange = true;
     if (Expr == null)
     {
         if ((ArrayExpressionEditor.Len == -1) || data.Contains(";"))
         {
             var items = data.Split(';');
             for (var i = 0; i < items.Length; ++i)
             {
                 items[i] = items[i].Trim();
                 if (items[i].Length == 0)
                 {
                     _ignoreTextChange = false;
                     return(false);
                 }
             }
             _definedAsConstVector = true;
             Expr = DataStorage.Add(new ArrayExpression("data", textBox1.Text, items));
             if ((ArrayExpressionEditor.Len != -1) &&
                 (items.Length != ArrayExpressionEditor.Len))
             {
                 ArrayExpressionEditor.Len = items.Length;
                 ArrayExpressionEditor.LenChanged(this);
             }
         }
         else
         {
             _definedAsConstVector = false;
             Expr =
                 DataStorage.Add(new ArrayExpression("data", textBox1.Text, data,
                                                     ArrayExpressionEditor.Len));
         }
         Expr.ValueChanged += ExprValueChanged;
     }
     else
     {
         if (data.Contains(";"))
         {
             var items = data.Split(';');
             for (var i = 0; i < items.Length; ++i)
             {
                 items[i] = items[i].Trim();
                 if (items[i].Length == 0)
                 {
                     _ignoreTextChange = false;
                     return(false);
                 }
             }
             _definedAsConstVector = true;
             Expr.SetRawExpressions(items);
             if ((ArrayExpressionEditor.Len != -1) &&
                 (items.Length != ArrayExpressionEditor.Len))
             {
                 ArrayExpressionEditor.Len = items.Length;
                 ArrayExpressionEditor.LenChanged(this);
             }
         }
         else
         {
             _definedAsConstVector = false;
             Expr.SetRawExpression(data, ArrayExpressionEditor.Len);
         }
     }
     ArrayExpressionEditor.Len = Expr.Exprs.Length;
     StepManager.RefreshToCurrentStep();
     _ignoreTextChange = false;
     return(true);
 }