Ejemplo n.º 1
0
 public override void Initialise(ICalc calc)
 {
     _calc                = calc;
     _viewModel           = new ChartVM(_calc);
     _control             = new ChartControl();
     _control.DataContext = _viewModel;
 }
Ejemplo n.º 2
0
        public void TestFactoryBuild()
        {
            ICalc c = _k.Lookup <ICalc>("sdCalc");

            Assert.AreEqual(16, (c as SingleDigitCalc).Mode);
            Assert.AreEqual(3, c.Add(10, 25));
        }
Ejemplo n.º 3
0
 public ChartPlugIn(ICalc calc)
 {
     _calc                = calc;
     _viewModel           = new ChartVM(_calc);
     _control             = new ChartControl();
     _control.DataContext = _viewModel;
 }
Ejemplo n.º 4
0
        private void divide_Click(object sender, EventArgs e)   //деление на 0
        {
            if (textBox1.Text != "")
            {
                if (Calc != null)
                {
                    if (Convert.ToDouble(textBox1.Text) != 0)
                    {
                        tmp1 = Calc.DoMath(tmp1, Convert.ToDouble(textBox1.Text));
                    }

                    else
                    {
                        textBox1.Text = "error";
                    }                              //не выводит еррор
                }

                else
                {
                    tmp1 = Convert.ToDouble(textBox1.Text);
                }
                textBox1.Text = "";
                textBox2.Text = tmp1 + "/";
                Calc          = new Divider();
            }
        }
Ejemplo n.º 5
0
 private void eqally_Click(object sender, EventArgs e)
 {
     if (textBox1.Text != "" && Calc != null)
     {
         tmp2 = Convert.ToDouble(textBox1.Text);
         if (coint == 1)
         {
             if (tmp2 == 0.0)
             {
                 textBox1.Text = "Деление на 0! ";
             }
             else
             {
                 textBox1.Text = Calc.DoMath(tmp1, tmp2) + "";
                 tmp1          = Convert.ToDouble(textBox1.Text);
                 Calc          = null;
             }
         }
         else
         {
             textBox1.Text = Calc.DoMath(tmp1, tmp2) + "";
             tmp1          = Convert.ToDouble(textBox1.Text);
             Calc          = null;
         }
     }
 }
Ejemplo n.º 6
0
        public static void WriteToODT(ICalc calculation, bool includeInputs, bool includeBody, bool includeOutputs, Settings sett, IProgress <WordReportProgress> progress = null)
        {
            string filePath;

            try
            {
                var saveDialog = new SaveFileDialog();
                saveDialog.Filter   = @"Word files |*.docx";
                saveDialog.FileName = calculation.InstanceName + @".docx";
                //saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                if (saveDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                filePath = saveDialog.FileName;
                Properties.Settings.Default.Reload();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Oops..." + Environment.NewLine + ex.Message);
                return;
            }

            WriteToODT(new List <ICalc> {
                calculation
            }, includeInputs, includeBody, includeOutputs, filePath, sett);
        }
Ejemplo n.º 7
0
            public static void LoadCode_WithDuckTypedInterface(HostApp host)
            {
                // 1 - LoadCode compiles code and returns instance of a first class in the compiled assembly
                // 2- The script class doesn't implement host app interface but it can still be aligned to
                // one as long at it implements the  interface members
                // 3 - In this sample host object is passed into script routine.

                ICalc calc = CSScript.LoadCode(@"using CSScriptNativeApi;
                                                 public class Script : ICalc
                                                 { 
                                                     public int Sum(int a, int b)
                                                     {
                                                         if(Host != null) 
                                                             Host.Log(""Sum is invoked"");
                                                         return a + b;
                                                     }
                                                 
                                                     public HostApp Host { get; set; }
                                                 }")
                             .CreateObject("*")
                             .AlignToInterface <ICalc>();

                calc.Host = host;
                int result = calc.Sum(1, 2);
            }
Ejemplo n.º 8
0
        /// <summary>
        /// Filters the surges in a sequence whose absolute values deviate from the specified positive value by a
        /// positive factor specified.
        /// </summary>
        /// <typeparam name="T">The type of elements in the incoming sequence.</typeparam>
        /// <typeparam name="C">The calculator for the sequence elements type.</typeparam>
        /// <param name="sequence">A calling sequence object.</param>
        /// <param name="centerValue">A nonnegative value. Sequence elements that deviate from this value by more than <paramref name="allowedDeviationFactor"/> will be filtered out.</param>
        /// <param name="allowedDeviationFactor">The allowed factor of absolute deviation.</param>
        /// <param name="deviationType">
        /// If deviation type is Downwards, values which are smaller than <paramref name="centerValue"/>
        /// by a factor of <paramref name="allowedDeviationFactor"/> will be filtered.
        /// If deviation type is Upwards, values which are bigger than <paramref name="centerValue"/>
        /// by a factor of <paramref name="allowedDeviationFactor"/> will be filtered.
        /// If deviation type is EitherSide, all values that differ from the <paramref name="centerValue"/>
        /// by a factor of <paramref name="allowedDeviationFactor"/> will be filtered.
        /// </param>
        /// <param name="filteredValues">A reference to a collection to store the filtered values. May be null.</param>
        /// <returns>The list containing all incoming values except for the filtered ones.</returns>
        public static List <T> filterSurgesByAbsoluteFactorDeviationFromValue <T, C>(this IEnumerable <T> sequence, T centerValue, double allowedDeviationFactor, DeviationType deviationType = DeviationType.EitherSide, ICollection <T> filteredValues = null) where C : ICalc <T>, new()
        {
            ICalc <T> calc = Numeric <T, C> .Calculator;

            (centerValue > Numeric <T, C> .Zero).Assert(new ArgumentException("The center value specified should be positive."));
            (allowedDeviationFactor > 0).Assert(new ArgumentException("The allowed deviation factor should be positive."));

            List <T> result = new List <T>();

            foreach (Numeric <T, C> current in sequence)
            {
                Numeric <T, C> absCurrent = WhiteMath <T, C> .Abs(current);

                Numeric <T, C> multipliedValue   = (Numeric <T, C>)allowedDeviationFactor * centerValue;
                Numeric <T, C> multipliedCurrent = (Numeric <T, C>)allowedDeviationFactor * absCurrent;

                if (deviationType == DeviationType.EitherSide && (absCurrent > multipliedValue || multipliedCurrent < centerValue) ||
                    deviationType == DeviationType.Upwards && absCurrent > multipliedValue ||
                    deviationType == DeviationType.Downwards && multipliedCurrent < centerValue)
                {
                    // Filter the surge.

                    if (filteredValues != null)
                    {
                        filteredValues.Add(current);
                    }
                }
                else
                {
                    result.Add(current);
                }
            }

            return(result);
        }
Ejemplo n.º 9
0
            public static void LoadCode_WithDuckTypedInterface(HostApp host)
            {
                // 1 - LoadCode compiles code and returns instance of a first class in the compiled assembly
                // 2- The script class doesn't implement host app interface but it can still be aligned to
                // one as long at it implements the  interface members
                // 3 - In this sample host object is passed into script routine.

                //This use-case uses Interface Alignment and this requires all assemblies involved to have
                //non-empty Assembly.Location
                CSScript.GlobalSettings.InMemoryAssembly = false;

                ICalc calc = CSScript.LoadCode(@"using CSScriptNativeApi;
                                                 public class Script
                                                 {
                                                     public int Sum(int a, int b)
                                                     {
                                                         if(Host != null)
                                                             Host.Log(""Sum is invoked"");
                                                         return a + b;
                                                     }

                                                     public HostApp Host { get; set; }
                                                 }")
                             .CreateObject("*")
                             .AlignToInterface <ICalc>();

                calc.Host = host;
                int result = calc.Sum(1, 2);
            }
Ejemplo n.º 10
0
Archivo: Form1.cs Proyecto: pepipe/ISEL
        public Form1()
        {
            try
            {
                //Windows forms
                InitializeComponent();
                AppDomain myDomain = AppDomain.CurrentDomain;
                this.Text = myDomain.FriendlyName;

                //HTTP
                HttpChannel ch = new HttpChannel(0);

                //TCP
                //TcpChannel ch = new TcpChannel(0);

                ChannelServices.RegisterChannel(ch, false);

                //Marshal by ref object
                //m_calc = (ICalc)Activator.GetObject(
                //    typeof(ICalc),
                //    "tcp://localhost:1234/RemoteCalcServer.soap");

                //Factory
                IMemFactory fact = (IMemFactory)Activator.GetObject(
                                typeof(IMemFactory),
                                "http://localhost:1234/RemoteCalcServer.soap");
                m_calc = fact.GetNewInstanceCalc();
            }
            catch (Exception ex)
            {
                textRes.Text = ex.Message+"\n"+ex.StackTrace;
            }
        }
Ejemplo n.º 11
0
        static int _m_add(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                ICalc gen_to_be_invoked = (ICalc)translator.FastGetCSObj(L, 1);



                {
                    int _a = LuaAPI.xlua_tointeger(L, 2);
                    int _b = LuaAPI.xlua_tointeger(L, 3);

                    int gen_ret = gen_to_be_invoked.add(_a, _b);
                    LuaAPI.xlua_pushinteger(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        static void Main(string[] args)
        {
            string command = "add 1,4,5";

            ICalc  cal    = null;
            string result = null;

            CalcFactory cf = new CalcFactory();

            cal = cf.GetObject("add1"); //Wrong command
            //cal = cf.GetObject(cmd.Substring(0,cmd.Split(' ')[0].Length)); //correct command
            if (cal != null)
            {
                Console.WriteLine("No command found");
                result = cal.Calculation(command);
                Console.WriteLine($"output of add command is {result}");
            }

            cal = cf.GetObject(command.Substring(0, command.Split(' ')[0].Length));
            if (cal != null)
            {
                Console.WriteLine("No command found");
                result = cal.Calculation(command);
                Console.WriteLine($"output of add command is {result}");
            }


            Console.Read();
        }
Ejemplo n.º 13
0
    void Start()
    {
        // Debug.Log("sdfffffffffffff");

        LuaEnv luaenv = new LuaEnv();

        luaenv.DoString(script);

        CalcNew calc_new = luaenv.Global.GetInPath <CalcNew>("Calc.New");

        luaenv.Global.Set("InvokeLua", this);
        ICalc calc = calc_new(10000, "hi", "john"); //constructor

        Debug.Log("sum(*10) =" + calc.Add(1, 2));
        calc.Mult = 100;
        Debug.Log("sum(*100)=" + calc.Add(1, 2));
        int abc = luaenv.Global.GetInPath <int>("A.B.C");

        Debug.Log("---------" + abc);
        luaenv.Global.SetInPath <int>("A.B.C", 1000);
        int abc1 = luaenv.Global.GetInPath <int>("A.B.C");

        Debug.Log("------1---" + abc1);

        luaenv.Global.Set("tt", 12377);

        int t;

        luaenv.Global.Get("tt", out t);
        Debug.Log("---tt---" + t);

        luaenv.Dispose();
    }
Ejemplo n.º 14
0
 private void Division_Click(object sender, EventArgs e) //деление вводимой строки
 {
     if (textBox1.Text != "")
     {
         if (Calc != null)
         {
             tmp1 = Calc.DoMath(tmp1, Convert.ToDouble(textBox1.Text));
         }
         else
         {
             tmp1 = Convert.ToDouble(textBox1.Text);
         }
         if (tmp1 != 0)
         {
             textBox2.Text = tmp1 + "/";
             textBox1.Text = "";
             Calc          = new Division();
         }
         else
         {
             textBox2.Text = "ОШИБКА";
             textBox1.Text = "";
         }
         Comma.Enabled = true;
     }
 }
Ejemplo n.º 15
0
        public void TestSingleton()
        {
            ICalc c1 = _k.Lookup <ICalc>("c");
            ICalc c2 = _k.Lookup <ICalc>("c");

            Assert.AreEqual(c1, c2);
        }
Ejemplo n.º 16
0
        public void LoadMethod_T()
        {
            ICalc calc   = evaluator.LoadMethod <ICalc>("int Sum(int a, int b) => a+b;");
            var   result = calc.Sum(7, 3);

            Assert.Equal(10, result);
        }
Ejemplo n.º 17
0
 public override void Initialise(ICalc calc)
 {
     _calc                = calc;
     _viewModel           = new TableVM(_calc);
     _control             = new CrossRefTable();
     _control.DataContext = _viewModel;
 }
Ejemplo n.º 18
0
        // --------------------------------------------
        // --------- ЧИСЛЕННОЕ ИНТЕГРИРОВАНИЕ ---------
        // --------------------------------------------

        /// <summary>
        /// Returns the Monte-Carlo stochastic approximation of the function integral.
        ///
        /// Requirements: calculator for the function argument/value should provide
        /// reasonable implementation of the 'fromDouble()' method.
        /// </summary>
        /// <typeparam name="T">The type of the function's argument/value.</typeparam>
        /// <typeparam name="C">The calculator for the function argument.</typeparam>
        /// <param name="obj">The calling function object.</param>
        /// <param name="generator">The uniform distribution (pseudo)random generator.</param>
        /// <param name="interval">The interval on which the integral will be approximated.</param>
        /// <param name="rectangleHeight">The height of the testing rectangle. Should be more than the function's absolute maximum on the interval tested, otherwise the method would return wrong results. On the other side, the difference between the height and the function's absolute maximum should not be very large as it will reduce the accuracy of the method. The ideal case is equality of the max f(x) on [a; b] and the rectangle height.</param>
        /// <param name="throwsCount">A positive integer value of overall tests.</param>
        /// <returns>The value approximating the function integral on the interval specified.</returns>
        public static T IntegralMonteCarloApproximation <T, C>(this IFunction <T, T> obj, IRandomBounded <T> generator, BoundedInterval <T, C> interval, T rectangleHeight, T throwsCount) where C : ICalc <T>, new()
        {
            ICalc <T> calc = Numeric <T, C> .Calculator;

            T         hits = calc.zero; // overall hits.
            Point <T> randomPoint;      // random point.

            if (!calc.mor(throwsCount, calc.zero))
            {
                throw new ArgumentException("The amount of point throws count should be a positive integer value.");
            }

            for (T i = calc.zero; calc.mor(throwsCount, i); i = calc.increment(i))
            {
                randomPoint = new Point <T>(generator.Next(interval.LeftBound, interval.RightBound), generator.Next(calc.zero, rectangleHeight));

                // Если попали под функцию - увеличиваем количество хитов.

                if (!calc.mor(randomPoint.Y, obj.Value(randomPoint.X)))
                {
                    hits = calc.increment(hits);
                }
            }

            T result = calc.div(calc.mul(calc.mul(interval.Length, rectangleHeight), hits), throwsCount);

            return(result);
        }
Ejemplo n.º 19
0
 private void Form1_Load(object sender, EventArgs e)
 {
     tmp1         = 0;
     tmp2         = 0;
     Calc         = null;
     Textbox.Text = "";
 }
Ejemplo n.º 20
0
        public static ICalc GetCalc(string csCode)
        {
            ICalc obj = null;

#if !NETCOREAPP3_0 && !NETSTANDARD2_0 && !NETSTANDARD2_1
            using (Microsoft.CSharp.CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider())
            {
                var prm = new System.CodeDom.Compiler.CompilerParameters();
                prm.GenerateInMemory   = true;
                prm.GenerateExecutable = false;
#if NET451 || NET471
                prm.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
#endif

                counter++;
                // Implement the interface in the dynamic code
                var res = csProvider.CompileAssemblyFromSource(prm,
                                                               String.Format(@"public class CompiledCalc{0} : ICalc { public Exception LastError { get; set; }
                            public object Calc() { {1} }}", counter, csCode));
                var type = res.CompiledAssembly.GetType(string.Format("CompiledCalc{0}", counter));

                try
                {
                    obj = Activator.CreateInstance(type) as ICalc;
                }
                catch (Exception ex)
                {
                    obj           = obj ?? new CalcEmpty();
                    obj.LastError = ex;
                }
            }
#endif
            return(obj);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Calculates the sample unbiased variation for a sequence of observations.
        /// </summary>
        /// <typeparam name="T">The type of observations' values.</typeparam>
        /// <typeparam name="C">A calculator for the <typeparamref name="T"/> type.</typeparam>
        /// <param name="values">The sequence of observations.</param>
        /// <param name="sampleAverage">The sample average for the observations sequence.</param>
        /// <returns>The sample unbiased variation for the sequence of observations.</returns>
        public static T SampleUnbiasedVariance <T, C>(this IEnumerable <T> values, T sampleAverage) where C : ICalc <T>, new()
        {
            Contract.Requires <ArgumentNullException>(values != null, "values");
            Contract.Ensures(Contract.Result <T>() >= Numeric <T, C> ._0, "The variance should not be negative.");

            int count = values.Count();

            if (count == 0)
            {
                throw new ArgumentException("Cannot calculate the sample variance for an empty sequence.");
            }
            else if (count == 1)
            {
                return(Numeric <T, C> .Zero);
            }

            Numeric <T, C> sum  = Numeric <T, C> .Zero;
            ICalc <T>      calc = Numeric <T, C> .Calculator;

            foreach (T value in values)
            {
                sum += WhiteMath <T, C> .PowerInteger(calc.dif(value, sampleAverage), 2);
            }

            return(sum / (Numeric <T, C>)(values.Count() - 1));
        }
Ejemplo n.º 22
0
 public void Form1_Load(object sender, EventArgs e)
 {
     tmp1         = 0;
     tmp2         = 0;
     Calc         = null;
     TextBox.Text = "";
 }
Ejemplo n.º 23
0
        public void TestLookupInterfaceBuild()
        {
            ICalc c = _k.Lookup <ICalc>();

            Assert.AreEqual(10, c.Add(4, 6));
            _k.TearDown(c);
        }
Ejemplo n.º 24
0
    public static void LoadAndUnloadImpl(string asmFile, out WeakReference alcWeakRef)
    {
        CSScript.Evaluator
        .ReferenceAssemblyOf <ICalc>()
        .CompileAssemblyFromCode(
            @"using System;
                      public class Script : ICalc
                      {
                          public int Sum(int a, int b)
                          {
                              return a+b;
                          }
                      }", asmFile);

        var asm = new UnloadableAssembly();

        alcWeakRef = new WeakReference(asm);

        ICalc script = (ICalc)asm.LoadFromAssemblyPath(asmFile)
                       .CreateObject("*");              // or `CreateInstance("css_root+Script")`

        int result = script.Sum(1, 3);

        asm.Unload();
    }
Ejemplo n.º 25
0
 public TablePlugIn(ICalc calc)
 {
     _calc                = calc;
     _viewModel           = new TableVM(_calc);
     _control             = new CrossRefTable();
     _control.DataContext = _viewModel;
 }
Ejemplo n.º 26
0
 private void comboBoxCreditName_SelectedValueChanged(object sender, EventArgs e)
 {
     if (CurrentCalc != null)
     {
         CurrentCalc.Clear();
     }
     CurrentCalc = CalculatorLogic.InitializeCalc(this, groupBox1, comboBoxCreditName.SelectedItem.ToString());
 }
Ejemplo n.º 27
0
 public override void Initialise(ICalc calc)
 {
     _calc = (CalcCore.ICalc)Activator.CreateInstance(calc.GetType());
     this.CopyValuesFrom(calc);
     _viewModel           = new CrossRefVM(_calc);
     _control             = new CrossRef();
     _control.DataContext = _viewModel;
 }
Ejemplo n.º 28
0
 private void FormInit()
 {
     num1          = 0;
     num2          = 0;
     Calc          = null;
     isMinus       = false;
     textBox1.Text = 0 + "";
 }
Ejemplo n.º 29
0
 private void Form1_Load(object sender, EventArgs e)
 {
     tmp1        = 0;
     tmp2        = 0;
     Calc        = null;
     calc.Text   = "0";
     label1.Text = "";
 }
Ejemplo n.º 30
0
 private void Form1_Load(object sender, EventArgs e)
 {
     tmp1             = 0;
     tmp2             = 0;
     Calc             = null;
     textBoxMain.Text = "";
     textBoxAdd.Text  = "";
 }
Ejemplo n.º 31
0
 private void DeletAll_Click(object sender, EventArgs e) //удаление всего
 {
     tmp1          = 0;
     tmp2          = 0;
     textBox1.Text = "";
     textBox2.Text = "";
     Calc          = null;
     Comma.Enabled = true;
 }
Ejemplo n.º 32
0
        public void Load(ICalc plugin)
        {
            _plugins.Add(plugin);

            _after.Add(plugin.Id, new List<Guid>());
            _blocks.Add(plugin.Id, new List<Guid>());

            ValidateAll();
            UpdateList();
        }
Ejemplo n.º 33
0
 public CalcMock(ICalc c)
 {
     _c = c;
 }
Ejemplo n.º 34
0
 public CalcMock()
 {
     _c = new SimpleCalc();
 }