예제 #1
0
        private void GetDataItems(string scope, string app, string graph, DataFilter dataFilter, string start, string limit)
        {
            try
            {
                string format = "json";

                string relativeUri   = "/" + app + "/" + scope + "/" + graph + "/filter?format=" + format + "&start=" + start + "&limit=" + limit;
                string dataItemsJson = string.Empty;

                WebHttpClient client  = CreateWebClient(_dataServiceUri);
                string        isAsync = _settings["Async"];

                if (isAsync != null && isAsync.ToLower() == "true")
                {
                    client.Async = true;
                    string statusUrl = client.Post <DataFilter, string>(relativeUri, dataFilter, format, true);

                    if (string.IsNullOrEmpty(statusUrl))
                    {
                        throw new Exception("Asynchronous status URL not found.");
                    }

                    dataItemsJson = WaitForRequestCompletion <string>(_dataServiceUri, statusUrl);
                }
                else
                {
                    dataItemsJson = client.Post <DataFilter, string>(relativeUri, dataFilter, format, true);
                }

                DataItemSerializer serializer = new DataItemSerializer();
                dataItems = serializer.Deserialize <DataItems>(dataItemsJson, false);
            }
            catch (Exception ex)
            {
                _logger.Error("Error getting data items." + ex);
                //response = response + " " + ex.Message.ToString();
                CustomErrorLog objCustomErrorLog = new CustomErrorLog();
                _CustomError = objCustomErrorLog.customErrorLogger(ErrorMessages.errUIGridPages, ex, _logger);
                response     = response + " " + throwJsonResponse(_CustomError);
            }
        }
예제 #2
0
        private void GetDataItems(string scope, string app, string graph, string filter, string sort, string dir, string start, string limit)
        {
            try
            {
                string format = "json";
                if (sort != null)
                {
                    string[] sortArr = sort.Split('\"');
                    sort = sortArr[3];
                    dir  = sortArr[7];
                }

                DataFilter dataFilter    = CreateDataFilter(filter, sort, dir);
                string     relativeUri   = "/" + app + "/" + scope + "/" + graph + "/filter?format=" + format + "&start=" + start + "&limit=" + limit;
                string     dataItemsJson = string.Empty;

                WebHttpClient client  = CreateWebClient(_dataServiceUri);
                string        isAsync = _settings["Async"];


                DataItems sessionDataItem = null;
                sessionDataItem = (DataItems)Session[keyName];
                bool item = false;


                if (sessionDataItem != null)
                {
                    if (filter == null)
                    {
                        var data = (from d in sessionDataItem.items
                                    select d).Skip(int.Parse(start)).Take(int.Parse(limit)).AsEnumerable().ToList();
                        if (data.Count == 0)
                        {
                            item = true;
                        }
                        else
                        {
                            dataItems       = new DataItems();
                            dataItems.items = data;
                            dataItems.limit = data.Count;
                            dataItems.total = sessionDataItem.total;
                        }
                    }
                    else
                    {
                        item = true;
                    }
                }

                if (sessionDataItem == null || item)
                {
                    if (isAsync != null && isAsync.ToLower() == "true")
                    {
                        client.Async = true;
                        string statusUrl = client.Post <DataFilter, string>(relativeUri, dataFilter, format, true);

                        if (string.IsNullOrEmpty(statusUrl))
                        {
                            throw new Exception("Asynchronous status URL not found.");
                        }

                        dataItemsJson = WaitForRequestCompletion <string>(_dataServiceUri, statusUrl);
                    }
                    else
                    {
                        dataItemsJson = client.Post <DataFilter, string>(relativeUri, dataFilter, format, true);
                    }

                    DataItemSerializer serializer = new DataItemSerializer();
                    dataItems = serializer.Deserialize <DataItems>(dataItemsJson, false);


                    mergeSessionData(dataItems);

                    if (Convert.ToInt32(start) == 0)
                    {
                        Session.Add(keyName, dataItems);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error getting data items." + ex);
                //response = response + " " + ex.Message.ToString();
                CustomErrorLog objCustomErrorLog = new CustomErrorLog();
                _CustomError = objCustomErrorLog.customErrorLogger("Cache entry has not been created. You need to refresh or import cache files.", ex, _logger);
                //_CustomError = objCustomErrorLog.customErrorLogger(ErrorMessages.errUIGridPages, ex, _logger);
                response = response + " " + throwJsonResponse(_CustomError);
            }
        }