using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

//using RegionClient.edu.jhu.pha.varelse;
using RegionClient.localhost;

namespace RegionClient
{
    class Program
    {
        static void Main(string[] args)
        {
            StcService ws = new StcService();
            Console.Out.WriteLine("URL: {0}", ws.Url);

            circleType ct = new circleType();
            ct.coord_system_id = "FK5-UTC-TOPO";
            ct.Center = new double2Type();
            ct.Center.C1 = new double1Type();
            ct.Center.C2 = new double1Type();
            ct.Center.C1.Value = 0;
            ct.Center.C2.Value = 0;
            ct.Radius = 1;
            ct.unit = posUnitType.deg;

            STCRegion sct = new STCRegion();
            sct.AstroCoordSystem = new astroCoordSystemType();
            sct.AstroCoordSystem.id = "FK5-UTC-TOPO";
            sct.AstroCoordSystem.href = @"ivo://STClib/CoordSys#FK5-UTC-TOPO";
            sct.Item = ct;

            XmlSerializer xml = new XmlSerializer(typeof(STCRegion));
            xml.Serialize(Console.Out, sct);
            Console.Out.WriteLine();
            
            regionAreaType a = ws.Area(sct);
            Console.Out.WriteLine("\nArea: {0}", a.Value);

            STCRegion sgt = ws.Grow(sct, 30);
            Console.Out.WriteLine("\nGrown: ");
            xml.Serialize(Console.Out, sgt);
            Console.Out.WriteLine();

            STCRegion spt = ws.ToPolygon(sct);
            xml.Serialize(Console.Out, spt);
            Console.Out.WriteLine();

            STCCoordinate sxt = ws.test_coords();
            bool cont = ws.ContainsPoint(sct, sxt);
            Console.Out.WriteLine("\nContains? {0}", cont);

            STCRegion srt = ws.test_region(); // sdss dr4
            Console.Out.WriteLine("DR4: {0}", srt.AstroCoordSystem.href);

            //byte[] buffer = ws.ImageCustom(rt, 180, 0, 1000, 512, 512, false, "gif");
            byte[] buffer = ws.ImageGif(srt);
            FileStream wri = new FileStream(@"C:\temp\ws.gif", FileMode.Create);
            wri.Write(buffer, 0, buffer.Length);
            wri.Close();
        }
    }
}
