コード例 #1
0
            public override Task <Response> GetResponseAsync(CancellationToken cancellationToken)
            {
                var tcs = new TaskCompletionSource <Response> ();

                cancellationToken.Register(() => tcs.TrySetCanceled());

                request.PerformRequest((resposeData, urlResponse, err) => {
                    Response result = null;
                    try {
                        if (err != null)
                        {
                            throw new Exception(err.LocalizedDescription);
                        }

                        result = new FoundationResponse(resposeData, urlResponse);
                    } catch (Exception ex) {
                        tcs.TrySetException(ex);
                        return;
                    }

                    tcs.TrySetResult(result);
                });

                return(tcs.Task);
            }
コード例 #2
0
        private string RetrieveServiceURLByServiceName(string serviceName, int retryCounter = 0)
        {
            string empty  = string.Empty;
            string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.ApiStore);
            Uri    uri    = new Uri(new Uri(appUri), string.Format("LocateService?ServiceName={0}", serviceName));

            try
            {
                byte[] numArray = (new WebClient()).DownloadData(uri);
                string str      = Encoding.UTF8.GetString(numArray);
                FoundationResponse <string> foundationResponse = this.serializer.Deserialize(str, typeof(FoundationResponse <string>)) as FoundationResponse <string>;
                if (foundationResponse.IsSuccess)
                {
                    if (!string.IsNullOrEmpty(foundationResponse.Data))
                    {
                        empty = foundationResponse.Data;
                    }
                }
            }
            catch (Exception exception)
            {
                DebugUtil.LogException(exception);
            }
            if (string.IsNullOrEmpty(empty))
            {
                if (retryCounter < 2)
                {
                    int num = retryCounter + 1;
                    retryCounter = num;
                    this.RetrieveServiceURLByServiceName(serviceName, num);
                }
            }
            return(empty);
        }
コード例 #3
0
 public void Refresh()
 {
     if (!LocationHelper._appUriDic.IsEmpty)
     {
         List <string> list = LocationHelper._appUriDic.Keys.ToList <string>();
         IDictionary <string, string> data = null;
         try
         {
             string str = string.Concat(AppContext.LocationServerURI, "api/Location/BatchGetAppLocations");
             DebugUtil.CollectDebugInfo(str, "WJOP.Foundation.Location.LocationHelper.Refresh");
             BatchGetLocationRequest batchGetLocationRequest = new BatchGetLocationRequest()
             {
                 AppKey      = AppContext.AppKey,
                 AppNameList = list
             };
             EnvInfo envInfo = new EnvInfo()
             {
                 IP  = AppContext.IPv4,
                 Env = AppContext.Environment
             };
             batchGetLocationRequest.EnvInfo = envInfo;
             BatchGetLocationRequest batchGetLocationRequest1          = batchGetLocationRequest;
             FoundationResponse <IDictionary <string, string> > result = str.PostWebApi <FoundationResponse <IDictionary <string, string> >, BatchGetLocationRequest>(batchGetLocationRequest1, null, 180000).Result;
             if (!result.IsSuccess)
             {
                 DebugUtil.Log(string.Format("LocationHelper: Failed to Refresh error Message: {0}", result.ErrMsg));
             }
             else
             {
                 data = result.Data;
                 foreach (string key in data.Keys)
                 {
                     DebugUtil.Log(string.Format("WJOP.Foundation.Location.LocationHelper.Refresh key:[{0}],old value [{1}] , new Value:[{2}]", key, LocationHelper._appUriDic[key], data[key]));
                     LocationHelper._appUriDic[key] = data[key];
                 }
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             DebugUtil.LogException(exception);
             DebugUtil.CollectDebugInfo(exception, "WJOP.Foundation.Location.LocationHelper.Refresh");
         }
     }
     else
     {
         DebugUtil.Log("WJOP.Foundation.Location.LocationHelper.Refresh: don't need to refresh");
     }
 }
コード例 #4
0
        public List <MetricSerie> PerformQuery(string db, string query)
        {
            List <MetricSerie> metricSeries;

            ParamterUtil.CheckEmptyString("db", db);
            ParamterUtil.CheckEmptyString("query", query);
            List <MetricSerie> metricSeries1 = new List <MetricSerie>();

            try
            {
                DebugUtil.Log(string.Format("MeasurementHost: performing query '{0}' on db '{1}'.", query, db));
                string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi);
                if (string.IsNullOrEmpty(appUri))
                {
                    DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location.");
                }
                else
                {
                    string  str     = string.Format("{0}api/measurement/run", appUri);
                    Command command = new Command()
                    {
                        Type = CommandType.Read
                    };
                    command.Parameters.Add("dbname", db);
                    command.Parameters.Add("query", query);
                    FoundationResponse <string> result = ProxyBase.Call <FoundationResponse <string>, Command>(str, command, ApiHttpMethod.POST, 180000, null).Result;
                    if ((result == null ? true : string.IsNullOrEmpty(result.Data)))
                    {
                        DebugUtil.Log(string.Format("MeasurementHost: query '{0}' on db '{1}' return empty.", query, db));
                    }
                    else
                    {
                        metricSeries1 = JsonSerializerUtil.Deserialize <List <MetricSerie> >(result.Data);
                    }
                    metricSeries = metricSeries1;
                    return(metricSeries);
                }
            }
            catch (Exception exception)
            {
                DebugUtil.LogException(exception);
            }
            metricSeries = metricSeries1;
            return(metricSeries);
        }
コード例 #5
0
        private static FoundationResponse <string> PushToServer(List <MetricPoint> points, string db, string rp)
        {
            string str;
            FoundationResponse <string> foundationResponse = null;

            if ((points == null ? false : points.Count > 0))
            {
                try
                {
                    string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi);
                    if (string.IsNullOrEmpty(appUri))
                    {
                        DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location.");
                        foundationResponse = new FoundationResponse <string>()
                        {
                            IsSuccess = false
                        };
                    }
                    else
                    {
                        str = (!appUri.EndsWith("/") ? string.Format("{0}/api/measurement/write/", appUri) : string.Format("{0}api/measurement/write/", appUri));
                        MeasurementRequest measurementRequest = new MeasurementRequest();
                        measurementRequest.MetricPoints.AddRange(points);
                        measurementRequest.DBName          = db;
                        measurementRequest.RetentionPolicy = rp;
                        DebugUtil.Log(string.Format("MeasurementHost: Sending {0} points to db '{1}' via {2}.", points.Count, measurementRequest.DBName, str));
                        foundationResponse = ProxyBase.Call <FoundationResponse <string>, object>(str, measurementRequest, ApiHttpMethod.POST, 180000, null).Result;
                        if (foundationResponse == null)
                        {
                            foundationResponse = new FoundationResponse <string>();
                        }
                        foundationResponse.IsSuccess = true;
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    foundationResponse.IsSuccess = false;
                    foundationResponse.ErrMsg    = string.Format("{0}\r\n{1}", exception.Message, exception.StackTrace);
                    DebugUtil.LogException(exception);
                }
            }
            return(foundationResponse);
        }
コード例 #6
0
        private string GetAppLocation(string appName)
        {
            string data = null;

            try
            {
                string str = string.Concat(AppContext.LocationServerURI, "api/Location/GetAppLocation");
                DebugUtil.CollectDebugInfo(str, "WJOP.Foundation.Location.LocationHelper.GetAppUris line:70");
                GetLocationRequest getLocationRequest = new GetLocationRequest()
                {
                    AppKey  = AppContext.AppKey,
                    AppName = appName
                };
                EnvInfo envInfo = new EnvInfo()
                {
                    IP  = AppContext.IPv4,
                    Env = AppContext.Environment
                };
                getLocationRequest.EnvInfo = envInfo;
                GetLocationRequest          getLocationRequest1 = getLocationRequest;
                FoundationResponse <string> result = str.PostWebApi <FoundationResponse <string>, GetLocationRequest>(getLocationRequest1, null, 180000).Result;
                if (!result.IsSuccess)
                {
                    DebugUtil.Log(string.Format("LocationHelper: Failed to match service uri for {0}, error Message: {1}", appName, result.ErrMsg));
                }
                else
                {
                    DebugUtil.Log(string.Format("LocationHelper: Found service uri for {0} : {1}", appName, result.Data));
                    data = result.Data;
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                DebugUtil.LogException(exception);
                DebugUtil.CollectDebugInfo(exception, "WJOP.Foundation.Location.LocationHelper.GetAppUris line:98");
            }
            return(data);
        }
コード例 #7
0
			public override Task<Response> GetResponseAsync (CancellationToken cancellationToken)
			{
				var tcs = new TaskCompletionSource<Response> ();

				cancellationToken.Register (() => tcs.TrySetCanceled ());

				request.PerformRequest ((resposeData, urlResponse, err) => {
					Response result = null;
					try {
						if (err != null)
							throw new Exception (err.LocalizedDescription);

						result = new FoundationResponse (resposeData, urlResponse);
					} catch (Exception ex) {
						tcs.TrySetException (ex);
						return;
					}

					tcs.TrySetResult (result);
				});

				return tcs.Task;
			}