public AsyncCalculateResult(Intent i)
 {
     Log.Info("com.ComputeApps.MandelbrotApp.Intents.DoWork", "Calculating result of WO");
        deserialisaitonStart = DateTime.Now;
        _cp = CommPackage.DeserializeJson(i.GetStringExtra("CommPackage"));
        deserialisationEnd = DateTime.Now;
 }
        protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
        {
            Log.Error("COMPUTING", "STARTING TO COMPUTE RESULT FOR WO: " + _cp.ComputationRequestId);
            _resultPackage = WorkerClass.DoWork(_cp);

            _resultPackage.DeserialisationTime = (Decimal)deserialisationEnd.Subtract(deserialisaitonStart).TotalSeconds;

            return true;
        }
Esempio n. 3
0
        public static void AddWorkItem(CommPackage toAdd)
        {
            if (workList == null) {
                InitWorkList();
            }

            workList.Add(toAdd);

            DoNextWorkItem();
        }
Esempio n. 4
0
        public static void SubmitNewWorkOrder(CommPackage cp)
        {
            CommunicationPackages.Add(cp);

            // Send to controller.

            Intent submitIntent = new Intent(ComputeAndroidSDK.Communication.Constants.REQUEST_WORK_ORDER_INTENT);
            submitIntent.Extras.PutString("CommPackage", cp.SerializeJson());
            ApplicationContext.SendBroadcast(submitIntent);
        }
Esempio n. 5
0
        public static void AddWorkItem(CommPackage toAdd)
        {
            if (workList == null) {
                InitWorkList();
            }

            workList.Add(toAdd);

            // Continue doing work.
            CommPackage nextWorkItem = GetNextWorkItem();

            if (nextWorkItem != null)
                DoWork(nextWorkItem);
        }
Esempio n. 6
0
        public void RequestWorkOrderComputation(object o)
        {
            Intent i = (Intent)o;
            String a = i.GetStringExtra("CommPackage");

            ComputeAndroidSDK.Communication.CommPackage cp = ComputeAndroidSDK.Communication.CommPackage.DeserializeJson(a);


            try {
                new WorkOrderWS.WorkOrderSvc().CreateWorkOrder(App.GetAuthToken(this), App.GetDeviceId(this), true, cp.ApplicationId, true, cp.SerializeParamList(), "ProcessRequest", cp.DeviceLocalRequestId, true);
            } catch (Exception e) {
                Log.Error("RequestWorkOrderComputation", e.Message);
            }

            StartCommFetch();
        }
Esempio n. 7
0
        public static void SubmitResult(CommPackage resultPackage)
        {
            currentWorkItem = null;
            workList.Remove(resultPackage);

            Intent intent = new Intent();
            intent.PutExtra("CommPackage", resultPackage.SerializeJson());
            intent.SetAction(Constants.RETURN_RESULT_INTENT);
            applicationContext.SendBroadcast(intent);

            // Continue doing work.
            CommPackage nextWorkItem = GetNextWorkItem();

            if (nextWorkItem != null)
                DoWork(nextWorkItem);
        }
Esempio n. 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here

            CommPackage cp = new CommPackage();

            cp.BackgroundProcessFunction = "WorkerFunction";
            cp.ParameterList = new List<CommPackage.ParamListItem>();

            cp.ParameterList.Add(new CommPackage.ParamListItem("a", 3));
            cp.ParameterList.Add(new CommPackage.ParamListItem("b", 9));

            string test = cp.SerializeJson();

            WorkList.SetAppContext(this.ApplicationContext);
               //         WorkList.AddWorkItem(cp);
        }
Esempio n. 9
0
        /**
         * This method should be the same across all implementations
         **/
        public static CommPackage DoWork(CommPackage workItem)
        {
            Type type = typeof(WorkerClass);
            MethodInfo method = type.GetMethod(workItem.BackgroundProcessFunction);
            WorkerClass c = new WorkerClass();

            // Build up parameter array
            object[] arr = new object[method.GetParameters().Count()];

            foreach (ParameterInfo pParameter in method.GetParameters()) {
                IEnumerable<CommPackage.ParamListItem> x = (from y in workItem.ParameterList
                                                            where y.ParameterName == pParameter.Name
                                                            select y);

                if (x.Count() == 1) {
                    Type tTest = x.First().ParameterValue.GetType();
                    if (Type.GetTypeCode(tTest) == TypeCode.Int64) {
                        arr[pParameter.Position] = Convert.ToInt32(x.First().ParameterValue);
                    } else {
                        arr[pParameter.Position] = x.First().ParameterValue;
                    }
                } else {
                    // Throw exception - param not given
                    throw new Exception("Parameter " + pParameter.Name + " not given.");
                }
            }

               // DateTime
            workItem.ComputationStartTime = DateTime.Now;
            int[][] result = (int[][])method.Invoke(c, arr);
            workItem.ComputationEndTime = DateTime.Now;

            DateTime serialisationStart = DateTime.Now;

            workItem.ComputationResult = new ResultPackage(result).SerializeJson();

            workItem.SerialisationTime = (Decimal)DateTime.Now.Subtract(serialisationStart).TotalSeconds;

            return workItem;
        }
        public String SubmitWorkOrders()
        {
            int x = 0;
            int y = 0;

            List <CommPackage> cpList = new List <CommPackage>();

            Bitmap bm = Bitmap.CreateBitmap(imgWidth, imgHeight, Bitmap.Config.Argb8888);

            while (x < imgWidth)
            {
                y = 0;

                while (y < imgHeight)
                {
                    ComputeAndroidSDK.Communication.CommPackage cp         = new ComputeAndroidSDK.Communication.CommPackage();
                    List <CommPackage.ParamListItem>            parameters = new List <CommPackage.ParamListItem>();

                    parameters.Add(new CommPackage.ParamListItem("xStart", x));
                    parameters.Add(new CommPackage.ParamListItem("yStart", y));
                    parameters.Add(new CommPackage.ParamListItem("xChunkSize", xChunk));
                    parameters.Add(new CommPackage.ParamListItem("yChunkSize", yChunk));
                    parameters.Add(new CommPackage.ParamListItem("xMax", xMax));
                    parameters.Add(new CommPackage.ParamListItem("xMin", xMin));
                    parameters.Add(new CommPackage.ParamListItem("yMin", yMin));
                    parameters.Add(new CommPackage.ParamListItem("yMax", yMax));
                    parameters.Add(new CommPackage.ParamListItem("width", imgWidth));
                    parameters.Add(new CommPackage.ParamListItem("height", imgHeight));
                    parameters.Add(new CommPackage.ParamListItem("maxIterations", maxIterations));
                    cp.ParameterList = parameters;
                    cp.ApplicationId = 5;
                    cpList.Add(cp);

                    y += yChunk;
                }
                x += xChunk;
            }

            return(Newtonsoft.Json.JsonConvert.SerializeObject(cpList));
        }
Esempio n. 11
0
        public void ReturnWORequestResult(object o)
        {
            Intent intent = (Intent)o;

            //  intent.PutExtra("FileLocation", fileName);
            String serializedJson;

            using (StreamReader sr = new StreamReader(intent.GetStringExtra("FileLocation"))) {
                serializedJson = sr.ReadToEnd();
            }

            File.Delete(intent.GetStringExtra("FileLocation"));


            // Get it
            //   ComputeAndroidSDK.Communication.CommPackage cp = ComputeAndroidSDK.Communication.CommPackage.DeserializeJson(intent.GetStringExtra("CommPackage"));
            ComputeAndroidSDK.Communication.CommPackage cp = ComputeAndroidSDK.Communication.CommPackage.DeserializeJson(serializedJson);

            new WorkOrderWS.WorkOrderSvc().SubmitWorkOrderResult(App.GetAuthToken(this), cp.ComputationRequestId, true, cp.ComputationResult, cp.ComputationStartTime, true, cp.ComputationEndTime, true, cp.SerialisationTime, true, cp.DeserialisationTime, true);
            Log.Info("ControllerService", cp.ComputationResult.Length + "  -- Result returned WO: " + cp.ComputationRequestId);
            App.UpdateLastTransmit();

            intent.Dispose();
        }
Esempio n. 12
0
 public static void RemoveWorkItem(CommPackage toRemove)
 {
     workList.Remove(toRemove);
 }
Esempio n. 13
0
 public static void DoWork(CommPackage workItem)
 {
     workItem = WorkerClass.DoWork(workItem);
     SubmitResult(workItem);
 }
Esempio n. 14
0
 private static void InitWorkList()
 {
     workList = new List<ComputeAndroidSDK.Communication.CommPackage>();
      currentWorkItem = null;
 }
        public String SubmitWorkOrders()
        {
            int x = 0;
            int y = 0;

            List<CommPackage> cpList = new List<CommPackage>();

            Bitmap bm = Bitmap.CreateBitmap(imgWidth, imgHeight, Bitmap.Config.Argb8888);
            while (x < imgWidth) {
                y = 0;

                while (y < imgHeight) {
                    ComputeAndroidSDK.Communication.CommPackage cp = new ComputeAndroidSDK.Communication.CommPackage();
                    List<CommPackage.ParamListItem> parameters = new List<CommPackage.ParamListItem>();

                    parameters.Add(new CommPackage.ParamListItem("xStart", x));
                    parameters.Add(new CommPackage.ParamListItem("yStart", y));
                    parameters.Add(new CommPackage.ParamListItem("xChunkSize", xChunk));
                    parameters.Add(new CommPackage.ParamListItem("yChunkSize", yChunk));
                    parameters.Add(new CommPackage.ParamListItem("xMax", xMax));
                    parameters.Add(new CommPackage.ParamListItem("xMin", xMin));
                    parameters.Add(new CommPackage.ParamListItem("yMin", yMin));
                    parameters.Add(new CommPackage.ParamListItem("yMax", yMax));
                    parameters.Add(new CommPackage.ParamListItem("width", imgWidth));
                    parameters.Add(new CommPackage.ParamListItem("height", imgHeight));
                    parameters.Add(new CommPackage.ParamListItem("maxIterations", maxIterations));
                    cp.ParameterList = parameters;
                    cp.ApplicationId = 5;
                    cpList.Add(cp);

                    y += yChunk;

                }
                x += xChunk;
            }

            return Newtonsoft.Json.JsonConvert.SerializeObject(cpList);
        }