Exemplo n.º 1
0
        static int Main(string[] args)
        {
            try
            {
                CmdLine.Load(args);
            }
            catch (ArgumentException e)
            {
                Utilities.ShowInColor(e.Message, ConsoleColor.Red);
                Help();
                return(1);
            }

            if (CmdLine.Parameters.HelpRequired)
            {
                Help();
                return(1);
            }

            Buildings.Load();

            byte[] plaintext = Encoding.UTF8.GetBytes(
                String.Format("POLLING={0}\nACTIVATE={1}\nSECRET={2}",
                              Buildings.Settings[CmdLine.Parameters.BuildingID].PollingInterval,
                              CmdLine.Parameters.IsToActivate ? 1 : 0,
                              Buildings.Settings[CmdLine.Parameters.BuildingID].Secret));

            WebRequest request = WebRequest.Create(
                Buildings.Settings[CmdLine.Parameters.BuildingID].URI);

            Console.WriteLine("Requesting {0}", Buildings.Settings[CmdLine.Parameters.BuildingID].URI);
            Utilities.ShowInColor(
                String.Format("  for {0}", CmdLine.Parameters.IsToActivate ? "activation": "deactivation"),
                CmdLine.Parameters.IsToActivate ? ConsoleColor.Green: ConsoleColor.Red);

            request.Method        = "POST";
            request.ContentLength = plaintext.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(plaintext, 0, plaintext.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();

            Console.WriteLine("Response: {0}", ((HttpWebResponse)response).StatusDescription);

            return(0);
        }
Exemplo n.º 2
0
 public static void Reset()
 {
     instance = null;
 }