Click here to Skip to main content
15,896,348 members
Articles / Programming Languages / C#

Remote Access .NET CF Devices

Rate me:
Please Sign up or sign in to vote.
4.94/5 (16 votes)
8 Jan 2010CDDL18 min read 36.4K   3.2K   60  
Implementing remote access to .NET enabled devices.
//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="Matjazev.NET">
//     Copyright (c) www.matjazev.net. All rights reserved.
// </copyright>
// <author>Matjaz Prtenjak</author>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using Matjazev.Tcp;
using Matjazev.Tcp.Plugin;

namespace TCPClientCmd
{
  public class Program
  {
    private static void help()
    {
      Console.WriteLine(string.Format(
@"USAGE: {0} <server IP> <xml file with actions to execute> [result XML file] [1 if you wand log files]",
Environment.GetCommandLineArgs()[0]));
    }

    public static void Main(string[] args)
    {
      PerformanceTimer pTimer = new PerformanceTimer();
      try
      {
        if (args.Length < 2)
        {
          help();
          return;
        }

        string programPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
        PluginsManager.Inst.LoadPlugins(programPath);

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(args[1]);

        string log = string.Empty;
        if (args.Length > 3)
        {
          log = Path.Combine(programPath, @"log");
          if (!Directory.Exists(log)) Directory.CreateDirectory(log);
        }

        XmlDocument xmlNewDoc = JobExecuter.Execute(args[0], 15555, new Message(xmlDoc), log).XmlDocument;

        if (args.Length > 2)
        {
          using (XmlTextWriter writer = new XmlTextWriter(args[2], null))
          {
            writer.Formatting = Formatting.Indented;
            xmlNewDoc.Save(writer);
          }
        }
        else
          Console.WriteLine(xmlNewDoc.OuterXml.ToString());
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);        
      }

      Console.WriteLine("WorkTime: " + pTimer.Stop().ToString());
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior) MERKUR D.D.
Slovenia Slovenia
I am a software developer in one of the largest retailer in our country. My job is (beside else) also in setting some standards in SW development throughout our company.

I have a M.Sc. in computer science and 20 years of experience. I have written 2 books in Slovenian language and both are sold out (the first about C++ language and the second about VBA language)...

Comments and Discussions