Beispiel #1
0
 public frmMain(DesktopClient client, frmFirst ff)
 {
     InitializeComponent();
     this.client           = client;
     client.RcvImageEvent += Client_RcvImageEvent;
     this.ff = ff;
 }
        // GET: /Action/Launch
        public ActionResult Launch(
            string name,
            string args,
            string title,
            string detach)
        {
            Security.ClearSavedProfile();

            if (String.IsNullOrEmpty(Running.RunningProgram))
            {
                DesktopClient.SendSpecialkey("ClearDesktop");
            }

            if (!string.IsNullOrEmpty(name))
            {
                if (!string.IsNullOrEmpty(args))
                {
                    args = HttpUtility.UrlDecode(args);
                }
                if (!string.IsNullOrEmpty(detach))
                {
                    Running.LaunchNewProgram(name, args);
                }
                else
                {
                    Running.LaunchProgram(name, args);
                }
            }

            return(Content("OK"));
        }
Beispiel #3
0
        public async Task <string> GenerateToken(DesktopClient i, int userId, string type)
        {
            var tokenClaims = new List <Claim> {
            };

            tokenClaims.Add(new Claim("Desktopid", i.Id.ToString()));
            tokenClaims.Add(new Claim("Name", i.ClientName));
            tokenClaims.Add(new Claim("Type", i.ClientType));
            tokenClaims.Add(new Claim("macAddr", i.ClientMacAddress));
            tokenClaims.Add(new Claim("UserId", userId.ToString()));
            tokenClaims.Add(new Claim(ClaimTypes.Role, type));

            var keyByte = Encoding.UTF8.GetBytes(_config.GetSection("LoginSettings:Key").Value);

            var key         = new SymmetricSecurityKey(keyByte);
            var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(tokenClaims),
                SigningCredentials = credentials,
                Expires            = DateTime.Now.AddMonths(1),
            };
            var tokenHandler = new JwtSecurityTokenHandler();

            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);


            return(tokenString);
        }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 private static void StopSky()
 {
     if (runningProgram == "Sky")
     {
         DesktopClient.SendIR(IRCodes.Codes["Sky.PowerSTB"], "Sky.PowerSTB");
     }
 }
Beispiel #5
0
    /// <summary>
    /// Load the profile anew from the XML file, selecting the appropriate "current" schedule to be used
    /// </summary>
    /// <param name="id"></param>
    /// <param name="isReload"></param>
    /// <returns></returns>
    static bool LoadProfile(
        int id,
        XElement profile,
        bool isReload = false)
    {
        CurrentProfileSchedules  = LoadSchedulesForToday(profile.Elements("Schedule"));
        CurrentSecurityProfileId = id;
        CurrentProfileIsDefault  = profile.Attribute("default") != null;
        DateLoaded = DateTime.Now.Date;

        if (!isReload)
        {
            InitSchedule();

            if (profile.Attribute("nonpersistent") == null)
            {
                DesktopClient.PersistStringInRegistry("SecurityProfile", id.ToString());
            }
        }

        Tick(DateTime.Now);

        logger.Info("Loaded profile {0}", profile.Attribute("name").Value);
        return(true);
    }
 // GET: /Action/MouseMove
 public ActionResult MouseMove(
     string dx,
     string dy)
 {
     DesktopClient.MouseMoveRelative(Convert.ToInt32(dx), Convert.ToInt32((dy)));
     return(Content(""));
 }
Beispiel #7
0
        private bool viewImageByDesktop(DesktopClient config, string patientId, string accNo)
        {
            config.param.PatientID       = patientId;
            config.param.AccessionNumber = accNo;

            var paramJson      = JsonConvert.SerializeObject(config.param);
            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(paramJson);
            var base64String   = System.Convert.ToBase64String(plainTextBytes);

            config.args.Add(base64String);

            config.args.ForEach(a => a = "\"" + a + "\"");
            var finalArgs = config.args.Select(a => "\"" + a + "\"");
            var args      = string.Join(" ", finalArgs);

            var path = Path.Combine(Directory.GetCurrentDirectory(), config.path);

            if (!File.Exists(path))
            {
                return(false);
            }

            var pro = Process.Start(path, args);

            pro.Dispose();

            return(true);
        }
        public async Task ConnectAlarm(Uri uri, int accountId)
        {
            accountUser = accountId;
            //Console.WriteLine(uri);
            //string p = uri.AbsoluteUri.Replace(uri.LocalPath, string.Empty);
            string test = uri.AbsoluteUri + "OperatorHub";

            Console.WriteLine(test);
            connection = new HubConnectionBuilder()
                         .WithUrl(test, options =>
            {
                options.Cookies = RestService.Instance.Cookies;
            })
                         .Build();

            await connection.StartAsync();

            Console.WriteLine(connection.State);

            client = new DesktopClient(connection);
            var list = await client.GetEventTypeList();

            //EventLog log = new EventLog
            //{
            //    Type = list.Where(i => i.Name == "CaptureWebcam").FirstOrDefault()
            //};

            //SubsystemEvent subsystemEvent = new SubsystemEvent
            //{
            //    Name
            //}

            //Console.WriteLine(JsonConvert.SerializeObject(log));

            Watcher = new GeoCoordinateWatcher();
            Watcher.StatusChanged += Watcher_StatusChanged;
            Watcher.Start();

            while (true)
            {
                await Task.Delay(100);

                if (webcamImage != null)
                {
                    var img = new Media
                    {
                        Type = "png",
                        Data = ImageToByte(webcamImage)
                    };
                    var frameImage = await client.CreateMedia(img);

                    var testresult = await client.GetEventFromSubsystemAsync(1, 0, accountUser, "CaptureWebcam", frameImage.Id.ToString());

                    Console.WriteLine(testresult);
                }
            }
        }
 // GET: /Action/GoPrime
 public ActionResult GoPrime()
 {
     Screen.EnsureScreenOn();
     Running.StartStream("Prime");
     Receiver.SelectComputerInput();
     Receiver.SelectTVOutput();
     DesktopClient.LaunchProgram("Prime", null);
     return(Content(""));
 }
Beispiel #10
0
 /// <summary>
 ///
 /// </summary>
 public static void StopZoom()
 {
     if (runningProgram == "Video" && zoomRunning)
     {
         Zoom.Stop();
         DesktopClient.ExitProgram("Video");
     }
     zoomRunning = false;
 }
 // GET: /Action/VisualOn
 public ActionResult VisualOn()
 {
     Screen.SetScreenDisplayMode(Running.RunningProgram == "Music" ? 2 : 1);
     if (Running.RunningProgram == "Spotify")
     {
         DesktopClient.LaunchProgram("GForce", "");
     }
     return(Content(""));
 }
Beispiel #12
0
    /// <summary>
    /// Is the screen really on (irrespective of our state)?
    /// </summary>
    /// <returns></returns>
    static bool TestScreenOn()
    {
        //  If we are watching an external source, it does not matter if the screen is on
        if (Receiver.SelectedInput != "Computer")
        {
            return(isOn);
        }

        return(DesktopClient.TvScreenIsOn());
    }
Beispiel #13
0
    /// <summary>
    /// Turn the screen off by issuing the appropriate HDMI-CEC command to device 0 (which is always the TV screen).
    /// </summary>
    static void TurnOff()
    {
        // if we've just turned the screen on, wait for the transition
        if (isOn)
        {
            WaitForScreenOn();
        }

        DesktopClient.TvScreenOff();
        isOn = false;
    }
 // GET: /Action/GoLogFire
 public ActionResult GoLogFire()
 {
     Screen.EnsureScreenOn();
     if (Running.RunningProgram != "Music" && Running.RunningProgram != "Spotify")
     {
         Running.StartStream("LogFire");
     }
     Receiver.SelectComputerInput();
     DesktopClient.LaunchProgram("LogFire", null);
     return(Content(""));
 }
Beispiel #15
0
        // GET: /Web/PlayBBC
        public ContentResult PlayBBC(
            string pid)
        {
            if (String.IsNullOrEmpty(Running.RunningProgram))
            {
                DesktopClient.SendSpecialkey("ClearDesktop");
            }

            Running.LaunchProgram("Web", "-k -nomerge " + BBC.GetTvPlayerUrl(pid));

            return(Content("OK"));
        }
        // GET: /Action/StartSky
        public ActionResult StartSky(
            string mode)
        {
            bool isAlreadyRunningSky = Running.RunningProgram == "Sky";

            if (mode != "radio")
            {
                Screen.EnsureScreenOn();
            }
            else if (!isAlreadyRunningSky)
            {
                Screen.SetScreenDisplayMode(0);
            }

            Running.StartSky();

            Receiver.SelectSkyInput();
            if (mode == "radio")
            {
                Receiver.SelectRoomsOutput();
            }
            else
            {
                Receiver.SelectTVOutput(null, false);
            }

            if (!isAlreadyRunningSky)
            {
                Receiver.SetMute(true);
            }

            DesktopClient.SendIR(IRCodes.Codes["Sky.Watch"], "Sky.Watch");

            if (!isAlreadyRunningSky)
            {
                System.Threading.Thread.Sleep(2000);
                SkyData.Sky.ChangeChannel(0);
            }

            switch (mode)
            {
            case "planner":
                return(Content("/Sky/Recordings"));

            case "live":
                return(Content("/Sky/Live"));

            case "radio":
                return(Content("/Sky/Radio"));
            }
            return(Content("/Sky/Watch"));
        }
Beispiel #17
0
        public Form1()
        {
            InitializeComponent();

            //We define our test class to pokein to let server side call the methods from this class
            test = new DesktopTest123(this);
            client = new DesktopClient(test, "http://localhost:7777/host.PokeIn", "");

            //DesktopClient events
            client.OnClientConnected += new OnConnection(client_OnClientConnected);
            client.OnClientDisconnected += new OnConnection(client_OnClientDisconnected);
            client.OnErrorReceived += new OnError(client_OnErrorReceived);
        }
Beispiel #18
0
        public Form1()
        {
            InitializeComponent();

            //We define our test class to pokein to let server side call the methods from this class
            test   = new DesktopTest(this);
            client = new DesktopClient(test, "http://localhost:7777/host.PokeIn", "");

            //DesktopClient events
            client.OnClientConnected    += new OnConnection(client_OnClientConnected);
            client.OnClientDisconnected += new OnConnection(client_OnClientDisconnected);
            client.OnErrorReceived      += new OnError(client_OnErrorReceived);
        }
        public async Task ConnectAlarm(Uri uri, int accountId)
        {
            accountUser = accountId;
            //Console.WriteLine(uri);
            //string p = uri.AbsoluteUri.Replace(uri.LocalPath, string.Empty);
            string test = uri.AbsoluteUri + "OperatorHub";

            Console.WriteLine(test);
            connection = new HubConnectionBuilder()
                         .WithUrl(test, options =>
            {
                options.Cookies = RestService.Instance.Cookies;
            })
                         .Build();

            await connection.StartAsync();

            Console.WriteLine(connection.State);

            client = new DesktopClient(connection);
            //var list = await client.GetEventTypeList();


            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/01.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/02.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/03.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/04.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/05.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/06.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/07.png")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/08.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/09.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/10.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/11.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/12.jpg")));
            imageList.Add(new BitmapImage(new Uri("pack://application:,,/;Component/Images/13.jpg")));
            int    idIndex = 3;
            Random random  = new Random();

            while (true)
            {
                await Task.Delay(1000);

                AddMedia(idIndex, imageList[random.Next(imageList.Count)]);
                idIndex++;
                if (idIndex == 22)
                {
                    idIndex = 3;
                }
            }
        }
Beispiel #20
0
        public async Task <DesktopClient> CreateDesktopClientAsync(DesktopCreateModel d)
        {
            var newD = new DesktopClient()
            {
                ClientName       = d.ClientName,
                ClientMacAddress = d.ClientMacAddress,
                ClientType       = d.ClientType,
            };
            var newDc = await _context.DesktopClients.AddAsync(newD);

            await _context.SaveChangesAsync();

            var result = newDc.Entity;

            return(result);
        }
Beispiel #21
0
        public frmFirst()
        {
            InitializeComponent();
            string CaCertPath = ConfigurationManager.AppSettings["CaCertPath"];
            string ServerIP   = ConfigurationManager.AppSettings["ServerIP"];
            string ServerPort = ConfigurationManager.AppSettings["ServerPort"];
            string ServerEui  = ConfigurationManager.AppSettings["ServerEui"];

            Client = new DesktopClient(CaCertPath, ReaderPc.GetCpuID(), ServerEui, ServerIP, ServerPort);
            Client.Start();
            Client.SelectServerEvent += Client_SelectServerEvent;
            Client.Conn1Event        += Client_Conn1Event;
            Client.Conn2Event        += Client_Conn2Event;
            Client.RcvKeyEvent       += Client_RcvKeyEvent;
            Client.MouseMoveEvent    += Client_MouseMoveEvent;
        }
Beispiel #22
0
    /// <summary>
    /// Exit all running programmes
    /// </summary>
    /// <param name="keepScreen"></param>
    /// <returns></returns>
    public static bool ExitAllPrograms(
        bool keepScreen = false)
    {
        logger.Info("ExitAllPrograms");

        lastActive = DateTime.UtcNow;

        if (spotifyRunning)
        {
            Spotify.ExitPlayer();
            spotifyRunning = false;
        }

        if (runningProgram == "Music" || runningProgram == "Photo")
        {
            ExitJRMC();
        }

        if (runningProgram == "Sky")
        {
            DesktopClient.SendIR(IRCodes.Codes["Sky.PowerSTB"], "Sky.PowerSTB");
            Receiver.SelectComputerInput();
        }

        if (runningProgram == "Roku")
        {
            Roku.KeyPress("Home");
            Receiver.SelectComputerInput();
        }

        if (!keepScreen)
        {
            Receiver.TurnOff();
            Screen.SetScreenDisplayMode(0);
        }
        else
        {
            Screen.EnsureScreenOn();
            Receiver.SelectTVOutput();
        }

        bool ok = DesktopClient.ExitAllPrograms();

        NothingRunning();

        return(ok);
    }
Beispiel #23
0
 static void Main(string[] args)
 {
     for (int i = 0; i < 100; i++)
     {
         var thread = new Thread(delegate()
          {
              var clientInstance = new ClientInstance();
              var client = new DesktopClient(clientInstance, "http://localhost:8006/host.PokeIn", "");
              client.Connect();
          });
         thread.Start();
         Thread.Sleep(1000);
         Console.WriteLine("");
     }
     Console.WriteLine();
     Console.ReadKey();
 }
        // GET: /Action/AllOff
        public ActionResult AllOff(
            string keep)
        {
            try
            {
                Security.ClearSavedProfile();

                Running.ExitAllPrograms(!string.IsNullOrEmpty(keep));
                DesktopClient.SendSpecialkey("ClearDesktop");
                return(Content(Receiver.VolumeDisplay));
            }
            catch (System.Exception ex)
            {
                logger.Error(ex, "Error in AllOff: {0}", ex.Message);
                return(Content("Error"));
            }
        }
Beispiel #25
0
    /// <summary>
    /// Apply any initial on/off settings in the current schedule, recording the current state for each device
    /// </summary>
    static void InitSchedule()
    {
        if (CurrentProfileSchedules.radioSchedule != null)
        {
            if (CurrentProfileSchedules.radioSchedule.initiallyOn || CurrentProfileSchedules.radioSchedule.initiallyOff || CurrentProfileSchedules.radioSchedule.onPeriods.Any())
            {
                Running.ExitAllPrograms();
                DesktopClient.SendSpecialkey("ClearDesktop");
            }

            if (CurrentProfileSchedules.radioSchedule.initiallyOn)
            {
                Receiver.Security();
                RadioState = "on";
            }

            if (CurrentProfileSchedules.radioSchedule.initiallyOff)
            {
                RadioState = "off";
            }
        }

        foreach (var zoneKV in CurrentProfileSchedules.zoneSchedules)
        {
            if (zoneKV.Value.initiallyOn && Zones.ContainsKey(zoneKV.Key))
            {
                foreach (Device d in Zones[zoneKV.Key])
                {
                    TP_Link.TurnOn(d.ipAddress, d.name, d.isSocket);
                }
                ZoneStates[zoneKV.Key] = "on";
            }
            if (zoneKV.Value.initiallyOff && Zones.ContainsKey(zoneKV.Key))
            {
                foreach (Device d in Zones[zoneKV.Key])
                {
                    TP_Link.TurnOff(d.ipAddress, d.name, d.isSocket);
                }
                ZoneStates[zoneKV.Key] = "off";
            }
        }
    }
Beispiel #26
0
    /// <summary>
    /// Launch the player applictaion (which will only be the Photo viewer) leaving any JRMC music still playing
    /// </summary>
    /// <param name="name"></param>
    /// <param name="args"></param>
    /// <returns></returns>
    public static bool LaunchNewProgram(
        string name,
        string args)
    {
        logger.Info("LaunchNewProgram {0} -> {1}", runningProgram, name);

        lastActive = DateTime.UtcNow;

        runningArgs = "";

        if (name == "Photo")
        {
            if (runningProgram == "Photo")
            {
                ExitJRMC();
                Thread.Sleep(500);
            }

            Zoom.Stop();
            DvbViewer.Stop();
            if (spotifyRunning)
            {
                Spotify.Stop();
            }
            DesktopClient.ExitAllPrograms();
            Receiver.SelectComputerInput();
            Receiver.ReselectInput();
            Screen.EnsureScreenOn();
            Receiver.SelectRoomsOutput();
            Screen.WaitForScreenOn();
            runningProgram = "Photo";

            if (DesktopClient.LaunchNewProgram(name, args))
            {
                JRMC.SetDisplay(JRMC.DisplayMode.Display, maximize: true);
                logger.Info("LaunchProgram OK {0}", runningProgram);
                return(true);
            }
        }

        return(false);
    }
Beispiel #27
0
    /// <summary>
    /// Note that we are starting streaming, and so stop all media PC player applications
    /// </summary>
    /// <returns></returns>
    public static bool StartStream(
        string streamSource)
    {
        logger.Info("StartStream: " + streamSource);

        if (runningProgram != streamSource)
        {
            if (runningProgram == "Music" || runningProgram == "Photo")
            {
                ExitJRMC();
            }
            StopSky();
            StopRoku();
            DesktopClient.ExitAllPrograms();
            DesktopClient.SendSpecialkey("ClearDesktop");
            NothingRunning();
        }

        runningProgram = streamSource;
        return(true);
    }
Beispiel #28
0
        protected void Application_Start()
        {
            logger.Info("Avid 4 Started");
            AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            JRMC.LoadAndIndexAllAlbums(new string[] { "1", "2" }, DateTime.Now.Hour < 5);   //  Reload album data from JRMC when restarting between midnight and five (i.e. in the overnight restart)
            DesktopClient.Initialize();
            Receiver.Initialize();
            Running.Initialize();
            Spotify.Initialize();
            DvbViewer.Initialize();
            Security.Initialize();

#if USE_SKY_STB
            SkyData.Initialize(Config.SkyFavourites, Config.SkyRadio, Config.SkyPackages, Config.SkyCapacityGB);
            var sky = SkyData.Sky;
#endif
        }
Beispiel #29
0
        private void OnCreateOrder(CustomersEnum customerEnumType)
        {
            BtnIsEnable = false;
            var wherePath = OrderTransportUI.GetETSOrderDirectory().FullName;

            if (orderFile == null)
            {
                orderFile = customerEnumType == CustomersEnum.Vostok ? OrderTransportUI.GetVostokOrder().FullName : customerEnumType == CustomersEnum.Inkay ? OrderTransportUI.GetInkayOrder().FullName : null;
                if (string.IsNullOrEmpty(orderFile))
                {
                    return;
                }
            }

            if (customerEnumType == CustomersEnum.Vostok)
            {
                if (treatyFile == null)
                {
                    treatyFile = OrderTransportUI.GetTreatyDraft().FullName;
                    if (string.IsNullOrEmpty(treatyFile))
                    {
                        return;
                    }
                }

                Order.Title = RequisitesVM.Title;
            }

            Order = OrderBP.GenerateOrder(customerEnumType, orderFile, treatyFile, Order, wherePath, "");

            DesktopClient.Send("EventsPipe", Order);

            BtnIsEnable = true;

            Process.Start("explorer", wherePath);
        }
Beispiel #30
0
    /// <summary>
    /// Note that we are starting the Sky box, and so stop all media PC player applications
    /// </summary>
    /// <returns></returns>
    public static bool StartSky()
    {
        logger.Info("StartSky");

        if (runningProgram != "Sky")
        {
            if (runningProgram == "Music" || runningProgram == "Photo")
            {
                ExitJRMC();
            }

            DesktopClient.ExitAllPrograms();
            DesktopClient.SendSpecialkey("ClearDesktop");
            Zoom.Stop();
            DvbViewer.Stop();
            if (spotifyRunning)
            {
                Spotify.Stop();
            }
        }

        runningProgram = "Sky";
        return(true);
    }
Beispiel #31
0
        public override void Start()
        {
            AppJournal.Write("Pipe server lictening stating.");

            DesktopClient.StartListening("EventsPipe", ClientRequest);
        }
Beispiel #32
0
 static void client_OnErrorReceived(DesktopClient c, string errorMessage)
 {
     MessageBox.Show(errorMessage);
 }
Beispiel #33
0
 void client_OnClientDisconnected(DesktopClient c)
 {
     //we call invoke to made change on Window due to cross-thread issues
     this.Invoke(new DConnectionChanged(ConnectionChanged), false); 
 }
Beispiel #34
0
 public void Setup()
 {
     _desktopMessageHandler = new DesktopClient();
 }
Beispiel #35
0
 void client_OnClientConnected(DesktopClient c)
 {
     this.Invoke(new DConnectionChanged(ConnectionChanged), true); 
 }
Beispiel #36
0
 public frmPwd(DesktopClient client)
 {
     InitializeComponent();
     this.client        = client;
     client.Conn2Event += Client_Conn2Event;
 }