コード例 #1
0
        static void Main(string[] args)
        {
            // ComputerMajor computerMajor = new ComputerMajor();
            // computerMajor.Id = 1;
            // computerMajor.Name = "李明";
            // computerMajor.English = 80;
            // computerMajor.Programming = 90;
            // computerMajor.Database = 85;
            // Console.WriteLine("学号:" + computerMajor.Id);
            // Console.WriteLine("姓名:" + computerMajor.Name);
            // Console.WriteLine("成绩信息如下:");
            // computerMajor.Total();
            // computerMajor.Avg();

            ComputerMajor computerMajor = new ComputerMajor();
            ICompute      compute       = computerMajor; //创建接口的实例

            compute.Id                = 1;
            compute.Name              = "李明";
            computerMajor.English     = 80;
            computerMajor.Programming = 90;
            computerMajor.Database    = 85;
            Console.WriteLine("学号:" + compute.Id);
            Console.WriteLine("姓名:" + compute.Name);
            Console.WriteLine("成绩信息如下:");
            compute.Total();
            compute.Avg();
        }
コード例 #2
0
 public ReportController(ReferralDbContext context, ICompute compute, IOptions <ReferralRoles> roles, IOptions <ReferralStatus> status)
 {
     _context = context;
     _compute = compute;
     _roles   = roles;
     _status  = status;
 }
コード例 #3
0
        public ILinkNode <TOutput> Append <TOutput>(ICompute <T, TOutput> compute)
        {
            var nextNode = new LinkNode <TOutput>();


            return(nextNode);
        }
コード例 #4
0
        public MainPageViewModel(INavigationService navigationService, ICompute compute)
            : base(navigationService)
        {
            getCompute = compute;
            switch (Device.RuntimePlatform)
            {
            case Device.UWP:
                Title = "Main Page UWP";
                break;

            case Device.WPF:
                Title = "Main Page WPF";
                break;

            case Device.iOS:
                Title = "Main Page IOS";
                break;

            case Device.Android:
                Title = "Main Page Android";
                break;

            default:
                Title = "Main Page";
                break;
            }
        }
コード例 #5
0
        public void ComputeGetVirtualMachinesTest()
        {
            ICompute compute = _kernel.Get <ICompute>();
            List <SimpleNamedString> names = compute.GetVirtualMachines("VMS-resource-group");

            Assert.AreEqual("Ubuntu2", names[0].value);
        }
コード例 #6
0
        public void TestFixtureSetUp()
        {
            var grid = Ignition.Start(TestUtils.GetTestConfiguration());

            _cache = grid.CreateCache <object, object>("cache");

            _compute = grid.GetCompute();
        }
コード例 #7
0
ファイル: ExceptionsTest.cs プロジェクト: zhunzhong/ignite
        /// <summary>
        /// Checks the exception.
        /// </summary>
        private static void CheckException <T>(ICompute comp, string name) where T : Exception
        {
            var ex = Assert.Throws <T>(() => comp.ExecuteJavaTask <string>(ExceptionTask, name));

            var javaEx = ex.InnerException as JavaException;

            Assert.IsNotNull(javaEx);
            Assert.IsTrue(javaEx.Message.Contains("at " + ExceptionTask));
        }
コード例 #8
0
        static void Main(string[] args)
        {
            IIgnite  ignite  = Ignition.Start();
            ICompute compute = ignite.GetCompute();

            // Execute a job and wait for the result.
            int res = compute.Call(new ComputeFunc());

            Console.WriteLine(res);
        }
コード例 #9
0
 private void _compute(ICompute obj)
 {
     try
     {
         txtAns.Text = obj.Execute(long.Parse(txtValue1.Text), long.Parse(txtValue2.Text)).ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #10
0
ファイル: Test.cs プロジェクト: xclouder/linco
    public void TestSimplePasses()
    {
        var node = default(ILinkNode <string>);

        ICompute <string, int>  c  = default(ICompute <string, int>);
        ICompute <int, Object>  c2 = default(ICompute <int, Object>);
        ICompute <Object, byte> c3 = default(ICompute <Object, byte>);

        var cancel = node.Append(c).Append(c2).Append(c3).Run();

        cancel.Dispose();
    }
コード例 #11
0
        public void TestBinarizableArgTask()
        {
            ICompute compute = _grid1.GetCompute();

            compute.WithKeepBinary();

            PlatformComputeNetBinarizable arg = new PlatformComputeNetBinarizable {
                Field = 100
            };

            int res = compute.ExecuteJavaTask <int>(BinaryArgTask, arg);

            Assert.AreEqual(arg.Field, res);
        }
コード例 #12
0
        public void TestEchoTaskBinarizableNoClass()
        {
            ICompute compute = _grid1.GetCompute();

            compute.WithKeepBinary();

            IBinaryObject res = compute.ExecuteJavaTask <IBinaryObject>(EchoTask, EchoTypeBinarizableJava);

            Assert.AreEqual(1, res.GetField <int>("field"));

            // This call must fail because "keepBinary" flag is reset.
            var ex = Assert.Throws <BinaryObjectException>(() =>
            {
                compute.ExecuteJavaTask <IBinaryObject>(EchoTask, EchoTypeBinarizableJava);
            });

            Assert.AreEqual("Unknown pair [platformId=1, typeId=2009791293]", ex.Message);
        }
コード例 #13
0
 /// <summary>
 /// Performs computation ignoring leaving nodes.
 /// </summary>
 private static AssemblyRequestResult ComputeApplySafe(ICompute compute, GetAssemblyFunc func,
                                                       AssemblyRequest req)
 {
     try
     {
         return(compute.Apply(func, req));
     }
     catch (ClusterGroupEmptyException)
     {
         // Normal situation: node has left.
         return(null);
     }
     catch (AggregateException aex)
     {
         // Normal situation: node has left.
         aex.Handle(e => e is ClusterGroupEmptyException);
         return(null);
     }
 }
コード例 #14
0
        public void TestFixtureSetUp()
        {
            TestUtils.KillProcesses();

            var grid = Ignition.Start(new IgniteConfiguration
            {
                SpringConfigUrl     = "config\\compute\\compute-standalone.xml",
                JvmClasspath        = TestUtils.CreateTestClasspath(),
                JvmOptions          = TestUtils.TestJavaOptions(),
                BinaryConfiguration = new BinaryConfiguration
                {
                    TypeConfigurations =
                        new List <BinaryTypeConfiguration> {
                        new BinaryTypeConfiguration(typeof(Binarizable))
                    }
                }
            });

            _cache = grid.GetCache <object, object>(null);

            _compute = grid.GetCompute();
        }
コード例 #15
0
        /// <summary>
        /// Checks the exception.
        /// </summary>
        private static void CheckException <T>(ICompute comp, string name) where T : Exception
        {
            var ex = Assert.Throws <T>(() => comp.ExecuteJavaTask <string>(ExceptionTask, name));

            var javaEx = ex.InnerException as JavaException;

            Assert.IsNotNull(javaEx);
            Assert.IsTrue(javaEx.Message.Contains("at " + ExceptionTask));
            Assert.AreEqual(name, javaEx.JavaMessage);
            Assert.IsTrue(javaEx.JavaClassName.EndsWith("." + name));

            // Check serialization.
            var formatter = new BinaryFormatter();

            using (var ms = new MemoryStream())
            {
                formatter.Serialize(ms, ex);

                ms.Seek(0, SeekOrigin.Begin);

                var res = (T)formatter.Deserialize(ms);

                Assert.AreEqual(ex.Message, res.Message);
                Assert.AreEqual(ex.Source, res.Source);
                Assert.AreEqual(ex.StackTrace, res.StackTrace);
                Assert.AreEqual(ex.HelpLink, res.HelpLink);

                var resJavaEx = res.InnerException as JavaException;

                Assert.IsNotNull(resJavaEx);
                Assert.AreEqual(javaEx.Message, resJavaEx.Message);
                Assert.AreEqual(javaEx.JavaClassName, resJavaEx.JavaClassName);
                Assert.AreEqual(javaEx.JavaMessage, resJavaEx.JavaMessage);
                Assert.AreEqual(javaEx.StackTrace, resJavaEx.StackTrace);
                Assert.AreEqual(javaEx.Source, resJavaEx.Source);
                Assert.AreEqual(javaEx.HelpLink, resJavaEx.HelpLink);
            }
        }
コード例 #16
0
        /// <summary>
        /// Construct a progressive response request that will execute progressive request responses to the
        /// Ignite node identified by nodeId
        /// </summary>
        /// <param name="tRexNodeId">The internal TREx node identifier of the node originating the request for the sub grids being returned</param>
        public SubGridProgressiveResponseRequest(Guid tRexNodeId)
        {
            // Determine the single node the request needs to be sent to
            _immutableCompute = ImmutableIgnite
                                .GetCluster()
                                .ForAttribute("TRexNodeId", tRexNodeId.ToString())
                                .GetCompute()
                                .WithExecutor(TREX_PROGRESSIVE_QUERY_CUSTOM_THREAD_POOL_NAME);

            if (_immutableCompute == null)
            {
                _log.LogWarning($"Failed to creating SubGridProgressiveResponseRequest instance for node '{tRexNodeId}'. Compute cluster projection is null");
                DumpClusterStateToLog(ImmutableIgnite, "ImmutableGrid", "ProgressiveResponseRequest");
            }
            else
            {
                var projectionSize = _immutableCompute?.ClusterGroup?.GetNodes()?.Count ?? 0;
                if (projectionSize == 0)
                {
                    _log.LogWarning($"Failed to creating SubGridProgressiveResponseRequest instance for node '{tRexNodeId}'. Topology projection contains no nodes");
                    DumpClusterStateToLog(ImmutableIgnite, "ImmutableGrid", "ProgressiveResponseRequest");
                }
            }
        }
コード例 #17
0
        static void Main(string[] args)
        {
            string   s;
            DateTime startTime;
            DateTime endTime;

            IgniteConfiguration cfg = new IgniteConfiguration()
            {
                IgniteInstanceName = "TRex",

                // Register custom class for Ignite serialization
                BinaryConfiguration = new Apache.Ignite.Core.Binary.BinaryConfiguration(typeof(MyCacheClass))
            };

            IIgnite ignite = Ignition.Start(cfg);

            // Add a cache to Ignite
            ICache <string, MyCacheClass> cache = ignite.CreateCache <string, MyCacheClass>
                                                      (new CacheConfiguration()
            {
                Name                      = "TestCache",
                CopyOnRead                = false,
                KeepBinaryInStore         = false,
                CacheStoreFactory         = new TRexCacheStoreFactory(),
                ReadThrough               = true,
                WriteThrough              = true,
                WriteBehindFlushFrequency = new TimeSpan(0, 0, 5),     // 5 seconds
                EvictionPolicy            = new LruEvictionPolicy()
                {
                    MaxMemorySize = 1000000,
                }
            });

            int NumCacheEntries = 5000;

            // Add a cache item
            cache.Put("First", new MyCacheClass("FirstItem"));

            // Add a collectikon of items
            startTime = DateTime.Now;
            for (int i = 0; i < NumCacheEntries; i++)
            {
                cache.Put("First" + i, new MyCacheClass("First" + i));
            }
            endTime = DateTime.Now;

            s = string.Format("{0}", endTime - startTime);
            Console.WriteLine("Time to add cache items with serialisation: {0}", s);

            int sumsum = 0;

            // Query back the cache items with serialisation
            startTime = DateTime.Now;
            for (int i = 0; i < NumCacheEntries; i++)
            {
                MyCacheClass first = cache.Get("First" + i);

                int sum = 0;
                for (int ii = 0; ii < first.localData.Length; ii++)
                {
                    sum += first.localData[ii];
                }
                sumsum += sum;
            }
            endTime = DateTime.Now;

            s = string.Format("{0}", endTime - startTime);
            Console.WriteLine("Time to query cache items with serialisation: {0}, sum = {1}", s, sumsum);

            var binCache = cache.WithKeepBinary <string, IBinaryObject>();

            //            IBinaryObject binCacheItem = binCache["First"];
            //            Console.WriteLine(binCacheItem.GetField<string>("Name"));

            // Query back the cache items without serialisation (using BinaryObject)
            startTime = DateTime.Now;
            for (int i = 0; i < NumCacheEntries; i++)
            {
                IBinaryObject binCacheItem = binCache["First" + i];

                byte[] bytes = binCacheItem.GetField <byte[]>("localData");

                int sum = 0;
                for (int ii = 0; ii < bytes.Length; ii++)
                {
                    sum += bytes[ii];
                }
                sumsum += sum;
            }
            endTime = DateTime.Now;

            s = string.Format("{0}", endTime - startTime);
            Console.WriteLine("Time to query cache items without serialisation: {0}, sum = {1}", s, sumsum);

            // Get compute instance over all nodes in the cluster.
            ICompute      compute  = ignite.GetCompute();
            IClusterGroup compute2 = ignite.GetCompute().ClusterGroup;



            // Execute a map reduce on the cluster
            if (compute2.ForServers()?.GetNodes()?.Any() == true)
            {
                try
                {
                    string mapReduceResult = ignite.GetCompute().Execute <string, string, string>(new MyComputeTask(), "Bob");
                    Console.WriteLine("Mapreduce result = '{0}'", mapReduceResult);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception executing mapReduce execution\r\n: {0}", e);
                }
            }
            else
            {
                Console.WriteLine("Calling cluster mapReduce broadcast function: No servers present in cluster");
            }

            // Execute a command using affinity on the cluster
            try
            {
                string affinityResult = ignite.GetCompute().AffinityCall <string>("TestCache", "First", new AffinityComputeFunc("First"));
                Console.WriteLine("Affinity result = '{0}'", affinityResult);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception executing affinity execution\r\n: {0}", e);
            }

            if (ignite == null)
            {
                Console.WriteLine("Ignite instance is null at end of method");
            }
            Console.ReadKey();
        }
コード例 #18
0
 public ProcessFile(string fileName, IKernel kernel)
 {
     this.FileName = fileName;
     primeFactors  = kernel.Get <Compute>();
 }
コード例 #19
0
ファイル: Program.cs プロジェクト: CDcoder78/StringCalculator
        private static void Main(string[] args)
        {
            var done         = false;
            var defaultColor = Console.ForegroundColor;

            // Stretch goal #4 DI IoC container
            var container = new Container();

            container.Register <IParser, Parser>(Lifestyle.Singleton);
            container.Register <IAdd, Add>(Lifestyle.Singleton);
            container.Register <ISubtraction, Subtraction>(Lifestyle.Singleton);
            container.Register <IMultiplication, Multiplication>(Lifestyle.Singleton);
            container.Register <IDivision, Division>(Lifestyle.Singleton);
            container.Verify();

            var modes = new Dictionary <ComputeTypes, ICompute>()
            {
                { ComputeTypes.Add, container.GetInstance <IAdd>() },
                { ComputeTypes.Subtract, container.GetInstance <ISubtraction>() },
                { ComputeTypes.Division, container.GetInstance <IDivision>() },
                { ComputeTypes.Multiplication, container.GetInstance <IMultiplication>() }
            };


            ICompute mode = modes[ComputeTypes.Add];

            // Stretch goal #2 exit with Ctrl+C
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                done = true;
                Console.WriteLine("Exiting.");
            };

            void PrintMenu()
            {
                Console.ForegroundColor = ConsoleColor.Yellow;

                var parser = container.GetInstance <IParser>();

                Console.WriteLine(_menuText, parser.GetDelimiters(), parser.CurrentMode, parser.DenyNegative, parser.UpperBound, parser.GetCommandText());

                Console.ForegroundColor = defaultColor;
            }

            try
            {
                while (!done)
                {
                    PrintMenu();

                    try
                    {
                        var input = Console.ReadLine();

                        if (input == null)
                        {
                            break;
                        }

                        var unescapeInput = Regex.Unescape(input);

                        if (!container.GetInstance <IParser>().HandleCommand(unescapeInput))
                        {
                            Console.WriteLine($"{mode.Compute(unescapeInput)}");
                        }
                        else
                        {
                            mode = modes[container.GetInstance <IParser>().CurrentMode];
                        }
                    }
                    catch (Exception e)
                    {
                        if (!done)
                        {
                            Console.WriteLine($"{e.GetType()}: {e.Message}");
                        }
                    }
                }
            }
            finally
            {
                // set the color for the console back to the default
                Console.ForegroundColor = defaultColor;
            }
        }
コード例 #20
0
 public void peri(ICompute c)
 {
     c.peri();
 }
コード例 #21
0
 public void area(ICompute c)
 {
     c.area();
 }
コード例 #22
0
 /// <summary>
 /// The SetComputeStrategy function is responsible for identifying the selected strategy and invoking the compute of the selected strategy
 /// </summary>
 /// <param name="computeStrategy">The compute strategy to be used - Add, Subtract, Multiple and Divide are available strategies</param>
 public void SetComputeStrategy(ICompute computeStrategy)
 {
     _computeStrategy = computeStrategy;
 }