home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Remoting / MyMedia / MyRemoteControl.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.5 KB  |  212 lines

  1. //==========================================================================
  2. //  File:       MyRemoteControl.cs
  3. //
  4. //  Summary:    This file implements client side of NGWS Remoting. 
  5. //            It illustrates COM+ Remoting 
  6. //           
  7. //  Classes:    MyRemoteControl
  8. //
  9. //--------------------------------------------------------------------------
  10. //  This file is part of the Microsoft NGWS Samples.
  11. //
  12. //  Copyright (C) 1999 Microsoft Corporation.  All rights reserved.
  13. //==========================================================================
  14.  
  15. using System;
  16. using System.IO;
  17. using System.Runtime.Remoting;
  18. using Homenet;
  19. using System.Threading;
  20.  
  21. public class MyRemoteControl
  22. {
  23.  
  24.     public static ManualResetEvent Done = new ManualResetEvent(false);
  25.  
  26.     public static void Main(String[] args)
  27.     {
  28.         int ret = Initialize(args);
  29.         Console.WriteLine("MyRemoteControl Sample\n");
  30.  
  31.         if (ret != -1)
  32.         {
  33.             RemoteControl remoteControl = new RemoteControl();
  34.       remoteControl.Scenario2();
  35.  
  36.             NullRemoteControl(out remoteControl);
  37.  
  38.             Console.WriteLine("\nEnd\n");
  39.         }
  40.     }
  41.  
  42.     private static void NullRemoteControl(out RemoteControl rc)
  43.     {
  44.         rc = null;
  45.     }
  46.  
  47.  
  48.  
  49.     //---------------------------------------------------
  50.     public static int scenario = 1;
  51.  
  52.     public static int Initialize(String[] args)
  53.     {
  54.         if (args.Length == 0)
  55.         {
  56.             RemotingServices.ConfigureRemoting("MyRemoteControl.cfg");
  57.             return 0;
  58.         }
  59.  
  60.  
  61.         for (int i=0;i<args.Length;i++)
  62.         {
  63.             if (
  64.                String.Compare(args[i],"HELP", true) == 0 ||
  65.                String.Compare(args[i],"?", true) == 0 ||
  66.                String.Compare(args[i],"/h", true) == 0 ||
  67.                String.Compare(args[i],"-h", true) == 0 ||
  68.                String.Compare(args[i],"-?", true) == 0 ||
  69.                String.Compare(args[i],"/?", true) == 0
  70.                )
  71.             {
  72.                 Usage();
  73.                 return -1;
  74.             }
  75.  
  76.             if (args[i].CompareTo("-cfg")==0)
  77.             {
  78.                 RemotingServices.ConfigureRemoting(args[i+1]);
  79.             }
  80.         }
  81.  
  82.         return 0;
  83.     }
  84.  
  85.     public static void Usage()
  86.     {
  87.         Console.WriteLine("Usage: MyRemoteControl [-cfg Configfile.cfg]\n");
  88.         Console.WriteLine("Examples : MyRemoteControl");
  89.         Console.WriteLine("Examples : MyRemoteControl-cfg MyRemoteControl.cfg");
  90.     }
  91. }
  92.  
  93. //public class RemoteControl : MarshalByRefObject, IMediaStatus
  94. public class RemoteControl : BaseRemoteControl
  95. {
  96.  
  97.     public bool Scenario0()
  98.     {
  99.         bool ret=true;
  100.         Console.WriteLine("Scenario 1");
  101.         Console.WriteLine("new VCR()");
  102.         VCR vcr = new VCR();
  103.  
  104.         String title = "clock.avi";
  105.         Console.WriteLine("Calling VCR.Play " + title);
  106.         ret = vcr.Play(title);
  107.  
  108.         return ret;
  109.     }
  110.  
  111.  
  112.     public bool Scenario1()
  113.     {
  114.         bool ret=true;
  115.         Console.WriteLine("Scenario 1");
  116.         Console.WriteLine("new VCR()");
  117.         VCR vcr = new VCR();
  118.  
  119.         String title = "clock.avi";
  120.         Console.WriteLine("Calling VCR.PlayWithStatus " + title);
  121.         ret = vcr.PlayWithStatus(title, this);
  122.  
  123.         return ret;
  124.     }
  125.  
  126.  
  127. //------------------------------------------------------
  128.  
  129.     public bool Scenario2()
  130.     {
  131.         bool ret=true;
  132.         Console.WriteLine("Scenario 2");
  133.         Console.WriteLine("new VCR()");
  134.         VCR vcr = new VCR();
  135.  
  136.         String title = "file://C:/winnt/clock.avi";
  137.  
  138.         String keyState = "";
  139.         while (String.Compare(keyState,"0", true) != 0)
  140.         {
  141.             Console.WriteLine("Press PT=Play Title, P=Play, A=Pause, S=Stop,0=Exit");
  142.             keyState = Console.ReadLine();
  143.  
  144.             Console.WriteLine("Pressed: " + keyState);
  145.  
  146.             if (String.Compare(keyState,"PT", true) == 0)
  147.             {
  148. /*
  149.                 Console.WriteLine("Calling VCR.PlayWithStatus - MBV with embedded MBR" + title);
  150.                 MediaRequest mediaRequest = new MediaRequest(title, this);
  151.                 ret = vcr.PlayWithStatus(mediaRequest);
  152. */
  153.                 ret = vcr.Play(title);
  154.             }
  155.  
  156.             if (String.Compare(keyState,"P", true) == 0)
  157.                 vcr.PlaySimple();
  158.  
  159.             if (String.Compare(keyState,"A", true) == 0)
  160.                 vcr.Pause();
  161.  
  162.             if (String.Compare(keyState,"S", true) == 0)
  163.                 vcr.Stop();
  164.         }
  165.  
  166.         return ret;
  167.     }
  168.  
  169.     public bool Scenario3()
  170.     {
  171.         bool ret=true;
  172.         Console.WriteLine("Scenario 3");
  173.         Console.WriteLine("new VCR()");
  174.         VCR vcr = new VCR();
  175.  
  176.         String title = "clock.avi";
  177.         Console.WriteLine("Calling VCR.PlayWithStatus - delegate " + title);
  178.  
  179.         StatusUpdateCallback callback = new StatusUpdateCallback(this.StatusUpdate);
  180.         ret = vcr.PlayWithStatus(title, callback);
  181.         return ret;
  182.     }
  183.  
  184.     public override bool StatusUpdate(String title)
  185.     {
  186.         Console.WriteLine("StatusUpdate: " + title);
  187.         return true;
  188.     }
  189.  
  190.     public bool Scenario4()
  191.     {
  192.         bool ret=true;
  193.         Console.WriteLine("new VCR()");
  194.         VCR vcr = new VCR();
  195.  
  196.         String title = "clock.avi";
  197.         Console.WriteLine("Calling VCR.Play " + title);
  198.         ret = vcr.Play(title);
  199.  
  200.         return ret;
  201.     }
  202.  
  203.     protected override void Finalize()
  204.     {
  205.         MyRemoteControl.Done.Set();
  206.     }
  207.  
  208. }
  209.  
  210.  
  211.  
  212.