Esempio n. 1
0
        public static async Task Main(string[] args)
        {
            ControlSpace cs = new ControlSpace("Simple stuff");
            var          sw = new Stopwatch();

            sw.Start();
            var points = new List <Point>(400);

            for (int i = 0; i < 2; i++)
            {
                var point = await cs.CreatePointAsync(i.ToString(), PointType.Any, ChannelType.TCP);

                points.Add(point);
                point.RunAsync(new PointStartInfo(TestMethod));
            }

            int result = 0;

            //await Task.Delay(10000);
            foreach (var item in points)
            {
                for (int i = 0; i < N; i++)
                {
                    result += await item.GetAsync <int>();
                }
            }
            Console.WriteLine(result);
            Console.WriteLine(sw.Elapsed);
            Console.ReadKey();
        }
Esempio n. 2
0
        public static async Task Main()
        {
            using (ControlSpace cs = new ControlSpace("Example"))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                int N = 150;
                await cs.AddDirectoryAsync(Directory.GetCurrentDirectory());

                var points = new Point[N];
                var tasks  = new Task <string> [N];
                for (int i = 0; i < N; i++)
                {
                    points[i] = await cs.CreatePointAsync(i.ToString(), PointType.Remote, ChannelType.TCP);

                    await points[i].AddChannelAsync(cs.CurrentPoint.Channel);
                    await points[i].RunAsync(new PointStartInfo(Tests.TestParcsPoints));
                    await points[i].SendAsync(i);
                    tasks[i] = points[i].GetAsync <string>();
                }
                await Task.WhenAll(tasks);

                foreach (var item in tasks)
                {
                    Console.WriteLine(item.Result);
                }
                Console.WriteLine("Done " + sw.Elapsed);
                Console.ReadKey();
            }
        }
    public static ControlSpace FromBaseObject(BaseObject baseObj)
    {
        if (baseObj == null || baseObj.NativeObject == IntPtr.Zero)
        {
            return(null);
        }
        ControlSpace obj = baseObj as  ControlSpace;

        if (object.Equals(obj, null))
        {
            obj = new ControlSpace(CreatedWhenConstruct.CWC_NotToCreate);
            obj.BindNativeObject(baseObj.NativeObject, "CControlSpace");
            obj.IncreaseCast();
        }

        return(obj);
    }
Esempio n. 4
0
        static async Task Main(string[] args)
        {
            int    N       = 2048; //int.Parse(Console.ReadLine());// 1024;
            Matrix matrixA = new Matrix(N, N);

            matrixA.RandomFill(10);
            Matrix matrixB = new Matrix(N, N);

            matrixB.RandomFill(10);
            Stopwatch sw = new Stopwatch();

            //File.WriteAllBytes("A.txt", matrixA.ToByteArray());
            //File.WriteAllBytes("B.txt", matrixB.ToByteArray());
            sw.Start();
            using (ControlSpace cs = new ControlSpace("MatrixMult"))
            {
                await cs.AddDirectoryAsync(Directory.GetCurrentDirectory());

                var point = await cs.CreatePointAsync();

                await point.RunAsync(new PointStartInfo(MatrixMultiplicationParcsMethod.MultStart));

                point.SendAsync(matrixA);
                point.SendAsync(matrixB);
                //Console.WriteLine(matrixA.ToString());
                //Console.WriteLine(matrixB.ToString());
                var matr = await point.GetAsync <Matrix>();

                File.WriteAllText("Result.txt", matr.ToString());


                Console.WriteLine("ParcsResult");
                Console.WriteLine(sw.Elapsed);
                Console.WriteLine("Ordinal result");
                sw.Restart();
                await Task.Factory.StartNew(() => matrixA.MultiplyBy(matrixB));

                Console.WriteLine(sw.Elapsed);
                File.WriteAllText("RealResult.txt", matrixA.ToString());
                Console.WriteLine("Done");
                Console.ReadKey();
            }
        }
Esempio n. 5
0
        public async Task DestroyControlSpaceAsync(ControlSpace data)
        {
            List <Guid> points = new List <Guid>();

            foreach (var item in PointService.Points)
            {
                if (item.Value.CurrentControlSpace.ID == data.ID)
                {
                    if (item.Value.PointTask.Status == TaskStatus.Running)
                    {
                        item.Value.cancellationTokenSource.Dispose();
                    }
                    points.Add(item.Key);
                }
            }
            foreach (var item in points)
            {
                points.Remove(item);
                PointService.Points.Remove(item);
            }
        }
Esempio n. 6
0
 void ExecCancel()
 {
     if (CurrentObject != null)
     {
         ControlSpace cs = null;
         _dataService.GetControlSpace(CurrentObject.Id, (item, error) =>
         {
             if (error != null)
             {
                 return;
             }                               // Report error here
             cs = item;
         });
         if (cs != null)
         {
             int i = ControlSpaces.IndexOf(SelectedItem);
             ControlSpaces[i] = cs;
             SelectedItem     = cs;
         }
         NormalUIState();
     }
 }
Esempio n. 7
0
 private void CSAdded(ControlSpace obj)
 {
     ControlSpaces.Add(obj);
 }
Esempio n. 8
0
 private void CSRemoved(ControlSpace obj)
 {
     //var x = 5;
 }
Esempio n. 9
0
        public async Task <bool> StartAsync(Channel from, Channel to, PointStartInfo info, ControlSpace space)
        {
            var pointData = Points.ContainsKey(to.PointID) ? Points[to.PointID] : throw new Exception("Point not found");

            pointData.CurrentControlSpace = space;
            pointData.CurrentControlSpace.CheckDaemons();

            var currentPoint = new Point(to, to, space);

            currentPoint.Data       = new DataObjectsContainer <SendDataParams>();
            pointData._currentPoint = currentPoint;
            pointData.CurrentControlSpace.CurrentPoint = currentPoint;
            pointData.ParentPoint = new Point(from, to, space);

            if (info != null)
            {
                object     instance = null;
                MethodBase method   = null;
                var        assembly = Assembly.LoadFrom(info.AssemblyName);
                if (info.IsStatic)
                {
                    var type = assembly.GetType(info.NamespaceAndClass);
                    method = type.GetMethod(info.MethodName);
                }
                else
                {
                    instance = assembly.CreateInstance(info.NamespaceAndClass);
                    method   = instance.GetType().GetMethod(info.MethodName);
                }
                Stopwatch sw = new Stopwatch();
                sw.Start();

                ((Task)method.Invoke(instance, new object[] { pointData }))
                .ContinueWith((t) =>
                {
                    sw.Stop();
                    //Console.WriteLine($"point task {to.Name} done in {sw.Elapsed} task status {t.Status}");
                }
                              ).ConfigureAwait(false);

                /*pointData.PointThread = new System.Threading.Thread( () =>
                 * {
                 *  Stopwatch sw = new Stopwatch();
                 *  sw.Start();
                 *  ((Task)method.Invoke(instance, new object[] { pointData })).GetAwaiter().GetResult();
                 *  Console.WriteLine($"point task {to.Name} done in " + sw.Elapsed);
                 *  sw.Stop();
                 * });
                 * pointData.PointThread.Start();*/
            }
            return(true);
        }
Esempio n. 10
0
        public async Task <Channel> CreatePointAsync(string Name, ChannelType channelType, ControlSpace controlSpace)
        {
            // var cs = GetOrCreateControlSpace(controlSpace);
            Guid newPointGuid = Guid.NewGuid();

            var pointInfo = new PointInfo(controlSpace, Name);

            PointService.Points.Add(newPointGuid, pointInfo);

            Channel channel = new Channel(Name, channelType, IP, Port + 1, newPointGuid);

            //cs.ChannelsOnCurrentDaemon.Add(channel);
            return(channel);
        }
    public BaseObject Create()
    {
        ControlSpace emptyInstance = new ControlSpace(CreatedWhenConstruct.CWC_NotToCreate);

        return(emptyInstance);
    }