AutoGRAPH.NET Service Examples en — различия между версиями

Материал из TK
Перейти к: навигация, поиск
(Новая страница: «== Examples == Download project for Visual Studio 2013/2015 Media:AutoGRAPHSvc_ExampleResults.zip|Download example resulsts (.X…»)
 
Строка 39: Строка 39:
 
foreach (var item in devices.Items)
 
foreach (var item in devices.Items)
 
Console.WriteLine("\t" + item.Name);
 
Console.WriteLine("\t" + item.Name);
currentDevices = devices.Items.Where(p => p.Serial == 9999999 || p.Serial == 9999998).Select(p => p.ID).ToArray(); // select only devices with serial numbers 9999998 and 9999999
+
currentDevices = devices.Items.Where(p => p.Serial == 9999999 || p.Serial == 9999998).Select(p => p.ID).ToArray(); // select only the devices which have serial numbers 9999998 and 9999999
 
}
 
}
   
Строка 118: Строка 118:
 
[[AutoGRAPH.NET_Service_Examples_Powershell|Examples on Powershell (JSON and export to CSV)]]
 
[[AutoGRAPH.NET_Service_Examples_Powershell|Examples on Powershell (JSON and export to CSV)]]
   
By default will use HTTP binding.
+
By default HTTP binding is used.

Версия 16:11, 11 февраля 2016

Examples

Download project for Visual Studio 2013/2015

Download example resulsts (.XML-files)

Download automatically generated proxy class AutoGRAPHSvc.cs

Download examples (console and WinForms): http://agi.tk-chel.ru/install/service/AutoGRAPHServiceExamples.zip

Examples on Powershell (JSON and export to CSV)

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using AutoGRAPHService;

namespace AutoGRAPHSvcTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var svc = new AutoGRAPHSvcClient();            // create proxy class with endpoint by default

            RSchema[] schemas;
            using (var f = new TimeCalc("EnumSchemas"))    // get schema list
                schemas = svc.EnumSchemas();

            var currentSchema = schemas.FirstOrDefault(p => p.Name == "DemoCEBIT").Name; // select one scheme DemoCEBIT

            Guid[] currentDevices = null;
            using (var f = new TimeCalc("EnumDevices"))
            {
                var devices = svc.EnumDevices(currentSchema);
                foreach (var item in devices.Items)
                    Console.WriteLine("\t" + item.Name);
                currentDevices = devices.Items.Where(p => p.Serial == 9999999 || p.Serial == 9999998).Select(p => p.ID).ToArray(); // select only the devices which have serial numbers 9999998 and 9999999
            }

            using (var f = new TimeCalc("EnumGeoFences"))  // get list of geofences
                svc.EnumGeoFences(currentSchema);

            using (var f = new TimeCalc("GetDevicesInfo"))
                svc.GetDevicesInfo(currentSchema);

            using (var f = new TimeCalc("EnumParameters")) // get properties list
                svc.EnumParameters(currentSchema, currentDevices);

            
            using (var f = new TimeCalc("GetOnlineInfo")) // get online information
            {
                var onlineInfo = svc.GetOnlineInfo(currentSchema, currentDevices);
                var serializer = new DataContractSerializer(typeof (ROnlineInfo));
                foreach (var oi in onlineInfo)
                {
                    var stm = new MemoryStream();
                    serializer.WriteObject(stm, oi.Value);
                    var fileName = "OnlineInfo_" + oi.Key + ".xml";
                    File.WriteAllBytes(fileName, stm.ToArray()); // serialize and write result to disk
                    Console.WriteLine("OnlineInfo: {0}", fileName);
                }
            }

            using (var f = new TimeCalc("GetTrips")) // get list of trips
            {
                var serializer = new DataContractSerializer(typeof (RTrips));
                var trips = svc.GetTrips(currentSchema, currentDevices, DateTime.Now.Date, DateTime.Now);
                foreach (var trip in trips)
                {
                    var stm = new MemoryStream();
                    serializer.WriteObject(stm, trip.Value);
                    var fileName = "Trips_" + trip.Key + ".xml";
                    File.WriteAllBytes(fileName, stm.ToArray()); // serialize and write result to disk
                    Console.WriteLine("Trips: {0}", fileName);
                }
            }

            using (var f = new TimeCalc("GetTrack"))       // get trips for last 5 days
            {
                var serializer = new DataContractSerializer(typeof(RTrackInfo[]));
                var tracks = svc.GetTrack(currentSchema, currentDevices, DateTime.Now.Date, DateTime.Now);
                foreach (var trip in tracks)
                {
                    var stm = new MemoryStream();
                    serializer.WriteObject(stm, trip.Value);
                    var fileName = "Tracks_" + trip.Key + ".xml";
                    File.WriteAllBytes(fileName, stm.ToArray()); // serialize and write result to disk
                    Console.WriteLine("Tracks: {0}", fileName);
                }
            }
            Console.ReadLine();
        }
    }

    // simple class for time measuring
    class TimeCalc : IDisposable
    {
        readonly DateTime DT;
        readonly string name;
        internal TimeCalc(string name) { DT = DateTime.Now; this.name = name; }
        void IDisposable.Dispose() { Console.WriteLine(name + ": " + DateTime.Now.Subtract(DT).TotalSeconds.ToString("F3", CultureInfo.InvariantCulture)); }
    }
}

Download project for Visual Studio 2013/2015

Download example resulsts (.XML-files)

Download automatically generated proxy class AutoGRAPHSvc.cs

Download examples (console and WinForms): http://agi.tk-chel.ru/install/service/AutoGRAPHServiceExamples.zip

Examples on Powershell (JSON and export to CSV)

By default HTTP binding is used.