static async Task DoWork() { var ags = new AGSClient("https://philmbprowin.esri.com:6443/arcgis/admin/", "admin", "demopw"); await ags.Authenticate(); Console.Out.WriteLine("Authenticated against {0}: {1}", ags.ServerUrl, ags.IsAuthenticated); Console.Out.WriteLine("Session expires at {0}", ags.TokenExpiration.ToLocalTime()); Console.Out.WriteLine("------------------"); // get last 12 hours of log entries, do some statistics on them var logEntries = await ags.GetLogs(LogMessage.LogType.Info, DateTime.Now, DateTime.Now.AddHours(-12)); int severeCount = (from entry in logEntries where entry.type == LogMessage.LogType.Severe select entry).Count(); Console.Out.WriteLine(string.Format("The server had {0} severe events in the past hour!", severeCount)); Console.Out.WriteLine("------------------"); // get status of all services in all folders var folders = await ags.GetFolderNames(); Console.Out.WriteLine("The following folders are defined on the server:"); Console.Out.WriteLine("/"); foreach (string folder in folders) { Console.Out.WriteLine(folder); } Console.Out.WriteLine("------------------"); var serviceStatus = await ags.GetAllServiceReports(); foreach (string folder in serviceStatus.Keys) { Console.Out.WriteLine(folder); foreach (var report in serviceStatus[folder]) { Console.Out.WriteLine(string.Format(" - {0}: {1}", report.serviceName, report.status.realTimeState.ToString())); } } Console.Out.WriteLine("------------------"); // upload a pre-created .sd to create a new service //Console.Out.WriteLine(@"Uploading C:\Presentations\Demo.sd.."); //var publishResponse = await ags.PublishServiceDefinition(new System.IO.FileInfo(@"C:\Presentations\Demo.sd")); }
/// <summary> /// task that generate csvExport object /// </summary> /// <param name="url">url of arcgis server</param> /// <param name="user">user of admin</param> /// <param name="pwd">password of admin</param> /// <param name="options">object options</param> /// <param name="fromUnix">from of time</param> /// <param name="toUnix">to of time</param> /// <returns>csvExport object</returns> private static async Task <List <ReportData> > Report(string url, string user, string pwd, Options options, long?fromUnix, long?toUnix) { string urlServer = url; Uri serverUri = new Uri(urlServer); string host = serverUri.Host; var ags = new AGSClient(url, user, pwd); await ags.Authenticate(); ////Console.Out.WriteLine("Authenticated against {0}: {1}", ags.ServerUrl, ags.IsAuthenticated); ////Console.Out.WriteLine("Session expires at {0}", ags.TokenExpiration.ToLocalTime()); ////Console.Out.WriteLine("------------------"); List <string> services = await ags.ListServices(options.IncludeSystemFolders); string usageReport1 = Guid.NewGuid().ToString(); string[] metrics = Enum.GetNames(typeof(Metrics)); Task <JObject> addUsageReport1 = ags.AddUsageReport(usageReport1, services, options, fromUnix, toUnix, metrics); string usageReport2 = Guid.NewGuid().ToString(); string[] metrics2 = Enum.GetNames(typeof(Metrics2)); Task <JObject> addUsageReport2 = ags.AddUsageReport(usageReport2, services, options, fromUnix, toUnix, metrics2); Task.WaitAll(new Task <JObject>[] { addUsageReport1, addUsageReport2 }); Task <ReportResponse> queryUsageReport1 = ags.QueryUsageReport(usageReport1); Task <ReportResponse> queryUsageReport2 = ags.QueryUsageReport(usageReport2); Task.WaitAll(new Task <ReportResponse>[] { queryUsageReport1, queryUsageReport2 }); ArcGIS.Server.Rest.Classes.ReportData[] reportDatas1 = queryUsageReport1.Result.report.reportdata[0]; // one filter machine '*' so get [0] ArcGIS.Server.Rest.Classes.ReportData[] reportDatas2 = queryUsageReport2.Result.report.reportdata[0]; // one filter machine '*' so get [0] long[] time = queryUsageReport1.Result.report.timeslices; long numElement = time.LongCount(); string[] header = Enum.GetNames(typeof(Header)); List <ReportData> results = new List <ReportData>(); int cont1 = 0; int cont2 = 0; while (cont1 < reportDatas1.LongLength) { string nameService = reportDatas1[cont1].resourceURI; long?[] requestCount = reportDatas1[cont1++].data.Cast <long?>().ToArray(); long?[] requestsFailed = reportDatas1[cont1++].data.Cast <long?>().ToArray(); long?[] requestsTimedOut = reportDatas1[cont1++].data.Cast <long?>().ToArray(); double?[] requestMaxResponseTime = reportDatas1[cont1++].data.Cast <double?>().ToArray(); double?[] requestAvgResponseTime = reportDatas1[cont1++].data.Cast <double?>().ToArray(); long?[] serviceRunningInstancesMax = reportDatas2[cont2++].data.Cast <long?>().ToArray(); for (long j = 0; j < numElement; j++) { ReportData reportData = new ReportData(); reportData.HostName = host; reportData.NameService = nameService; reportData.Time = EncodingHelper.DateTimeFromUnixTimestampMillis(time[j]); reportData.RequestCount = requestCount[j]; reportData.RequestsFailed = requestsFailed[j]; reportData.RequestsTimedOut = requestsTimedOut[j]; reportData.RequestMaxResponseTime = requestMaxResponseTime[j]; reportData.RequestAvgResponseTime = requestAvgResponseTime[j]; reportData.ServiceRunningInstancesMax = serviceRunningInstancesMax[j]; results.Add(reportData); } } Task <JObject> deleteUsageReport1 = ags.DeleteUsageReport(usageReport1); Task <JObject> deleteUsageReport2 = ags.DeleteUsageReport(usageReport2); Task.WaitAll(new Task <JObject>[] { deleteUsageReport1, deleteUsageReport2 }); return(results); }