Exemplo n.º 1
0
        public ActionResult App()
        {
            try
            {
                // Test Params
                if ((HttpContext.Request.QueryString["LastFetchDate"].Trim() == String.Empty) ||
                    (HttpContext.Request.QueryString["FetchCount"].Trim() == String.Empty) ||
                    (HttpContext.Request.QueryString["ProcessName"].Trim() == String.Empty))
                {
                    return base.Json(new RESTResponse() { ResponseStatus = ResponseStatus.IllegalRequest }, JsonRequestBehavior.AllowGet);
                }

                // Get Params
                String processName = HttpContext.Request.QueryString["ProcessName"].Trim();
                DateTime dateEntered = DateTime.Parse(HttpContext.Request.QueryString["LastFetchDate"].Trim());
                int fetchCount = int.Parse(HttpContext.Request.QueryString["FetchCount"].Trim());
                WebRoleMgr webRoleMgr = new WebRoleMgr(cloudStorageAccount, processName, dateEntered);

                // Add row
                webRoleMgr.AddObject();

                // Call SharedLibrary which calls AzureStorage
                int totalCount = webRoleMgr.CountOfItems();
                ResponseDataItem[] lastNItems=null;

                if (totalCount > 0)
                {
                    lastNItems = webRoleMgr.LastItemsEntered(fetchCount).ToArray();
                }

                // Build repsonse
                RESTResponse response = new RESTResponse()
                {
                    ResponseStatus = ResponseStatus.Success,
                    Items = lastNItems,
                    Count = totalCount
                };
                Debug.WriteLine("*****MvcWebRole1.Controllers.PhoneController.App TotalCount=" + response.Count.ToString());
                Debug.WriteLine("*****MvcWebRole1.Controllers.PhoneController.App ItemCount=" + response.Items.Length.ToString());

                // Convert and return object to JSON
                return base.Json(response, JsonRequestBehavior.AllowGet);

            }
            catch
            {
                // Convert and return Unknown Exception
                return base.Json(new RESTResponse() { ResponseStatus = ResponseStatus.UnknownException }, JsonRequestBehavior.AllowGet);
            }
        }
Exemplo n.º 2
0
        public ActionResult BackgroundAgent()
        {
            try
            {
                // Test Params
                if ((HttpContext.Request.QueryString["LastFetchDate"].Trim() == String.Empty) ||
                    (HttpContext.Request.QueryString["ProcessName"].Trim() == String.Empty))
                {
                    return base.Json(new RESTResponse() { ResponseStatus = ResponseStatus.IllegalRequest }, JsonRequestBehavior.AllowGet);
                }
                // Get Params
                String processName = HttpContext.Request.QueryString["ProcessName"].Trim();
                DateTime dateEntered = DateTime.Parse(HttpContext.Request.QueryString["LastFetchDate"].Trim());
                WebRoleMgr webRoleMgr = new WebRoleMgr(cloudStorageAccount, processName, dateEntered);

                // Add row
                webRoleMgr.AddObject();

                // Call SharedLibrary which calls AzureStorage
                int countSinceLastFetchDate = webRoleMgr.CountOfItemsSince(dateEntered);
                ResponseDataItem lastItem = webRoleMgr.LastItemEntered();
                ResponseDataItem[] SampleDataModelItems = new ResponseDataItem[1];
                SampleDataModelItems[0] = lastItem;

                // Build repsonse
                RESTResponse response = new RESTResponse()
                {
                    ResponseStatus = ResponseStatus.Success,
                    Count = countSinceLastFetchDate,
                    Items = SampleDataModelItems
                };

                Debug.WriteLine("*****MvcWebRole1.Controllers.PhoneController.BackgroundAgent Count=" + response.Count.ToString());

                // Convert and return object to JSON
                return base.Json(response, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                // Convert and return Unknown Exception
                return base.Json(new RESTResponse() { ResponseStatus = ResponseStatus.UnknownException }, JsonRequestBehavior.AllowGet);
            }
        }