Ejemplo n.º 1
0
 public Model()
 {
     DiscoverredDevices = new IndependentList <ConnectableDevice>();
     Apps           = new IndependentList <AppInfo>();
     Channels       = new List <ChannelInfo>();
     selectedDevice = new ConnectableDevice();
 }
Ejemplo n.º 2
0
        private void StartEmulatorSynchronous(object id)
        {
            ConnectableDevice connectableDevice = _multiTargetingConnectivity.GetConnectableDevice((string)id);

            _device = connectableDevice.Connect();
            EmulatorConnected(this, null);
        }
Ejemplo n.º 3
0
        public Deployer81(string desiredDevice, string appPath)
        {
            this.appPath = appPath;

            var devices = Utils.GetDevices();

            this.deviceInfo =
                devices.FirstOrDefault(
                    x =>
                    x.ToString().StartsWith(desiredDevice, StringComparison.OrdinalIgnoreCase)
                    && !x.ToString().Equals("Device"));

            // Exclude device
            if (this.deviceInfo == null)
            {
                Logger.Warn("Desired target {0} not found. Using default instead.", desiredDevice);

                this.deviceInfo = devices.First(x => !x.ToString().Equals("Device"));
            }

            var propertyInfo = this.deviceInfo.GetType().GetTypeInfo().GetDeclaredProperty("DeviceId");
            var deviceId = (string)propertyInfo.GetValue(this.deviceInfo);
            this.connectableDevice =
                new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID).GetConnectableDevice(deviceId);

            Logger.Info("Target emulator: {0}", this.DeviceName);
        }
 public Model()
 {
     DiscoverredDevices = new IndependentList<ConnectableDevice>();
     Apps = new IndependentList<AppInfo>();
     Channels = new List<ChannelInfo>();
     selectedDevice = new ConnectableDevice();
 }
 public void OnDeviceReady(ConnectableDevice device)
 {
     if (Paired != null)
     {
         Paired(this, device);
     }
 }
 public void OnDeviceDisconnected(ConnectableDevice device)
 {
     App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (App.ApplicationModel.Connected)
             App.ApplicationModel.OnDeviceDisconnected(EventArgs.Empty);
     });
 }
 public void OnDeviceAdded(DiscoveryManager manager, ConnectableDevice device)
 {
     App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (App.ApplicationModel.DiscoverredDevices.All(x => x.Id != device.Id))
         {
             App.ApplicationModel.AddDevice(device);
         }
     });
 }
 public void OnDeviceDisconnected(ConnectableDevice device)
 {
     App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (App.ApplicationModel.Connected)
         {
             App.ApplicationModel.OnDeviceDisconnected(EventArgs.Empty);
         }
     });
 }
 public void OnDeviceAdded(DiscoveryManager manager, ConnectableDevice device)
 {
     App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (App.ApplicationModel.DiscoverredDevices.All(x => x.Id != device.Id))
         {
             App.ApplicationModel.AddDevice(device);
         }
      });
 }
 public void OnDeviceUpdated(DiscoveryManager manager, ConnectableDevice device)
 {
     App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (App.ApplicationModel.DiscoverredDevices.Contains(device))
         {
             App.ApplicationModel.DiscoverredDevices.Remove(device);
             App.ApplicationModel.DiscoverredDevices.Add(device);
             device.OnPropertyChanged("ServiceNames");
         }
     });
 }
Ejemplo n.º 11
0
        static void ListDevices()
        {
            MultiTargetingConnectivity     mtConn     = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
            Collection <ConnectableDevice> deviceList = mtConn.GetConnectableDevices();

            for (int index = 0; index < deviceList.Count; index++)
            {
                ConnectableDevice d    = deviceList[index];
                string            info = string.Format("{0} : {1} : {2}", index.ToString(), d.Id, d.Name);
                Log(info);
            }
        }
 public void OnDeviceUpdated(DiscoveryManager manager, ConnectableDevice device)
 {
     App.MainDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
         if (App.ApplicationModel.DiscoverredDevices.Contains(device))
         {
             App.ApplicationModel.DiscoverredDevices.Remove(device);
             App.ApplicationModel.DiscoverredDevices.Add(device);
             device.OnPropertyChanged("ServiceNames");
         }
     });
 }
Ejemplo n.º 13
0
        public Deployer(string desiredDevice, bool strict, string appPath)
        {
            this.appPath = appPath;

            this.deviceInfo = Devices.Instance.GetMatchingDevice(desiredDevice, strict);

            if (this.deviceInfo == null)
            {
                throw new AutomationException(
                    string.Format(
                        "Could not find a device to launch. You requested '{0}', but the available devices were:\n{1}", 
                        desiredDevice, 
                        Devices.Instance));
            }

            var propertyInfo = this.deviceInfo.GetType().GetTypeInfo().GetDeclaredProperty("DeviceId");
            var deviceId = (string)propertyInfo.GetValue(this.deviceInfo);
            this.connectableDevice =
                new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID).GetConnectableDevice(deviceId);

            Logger.Info("Target emulator: '{0}'", this.DeviceName);
        }
Ejemplo n.º 14
0
        public Deployer(string desiredDevice, bool strict, string appPath)
        {
            this.appPath = appPath;

            this.deviceInfo = Devices.Instance.GetMatchingDevice(desiredDevice, strict);

            if (this.deviceInfo == null)
            {
                throw new AutomationException(
                          string.Format(
                              "Could not find a device to launch. You requested '{0}', but the available devices were:\n{1}",
                              desiredDevice,
                              Devices.Instance));
            }

            var propertyInfo = this.deviceInfo.GetType().GetTypeInfo().GetDeclaredProperty("DeviceId");
            var deviceId     = (string)propertyInfo.GetValue(this.deviceInfo);

            this.connectableDevice =
                new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID).GetConnectableDevice(deviceId);

            Logger.Info("Target emulator: '{0}'", this.DeviceName);
        }
Ejemplo n.º 15
0
        private static bool IsXapApplicableForMdilGeneration(
            ConnectableDevice connectableDevice,
            Version deviceVersion,
            bool isNative,
            string xapFile)
        {
            if (connectableDevice.IsEmulator() || deviceVersion < WindowsPhone8Dot0Version || isNative)
            {
                return(false);
            }

            var fileStream = (FileStream)null;

            try
            {
                fileStream = new FileStream(xapFile, FileMode.Open, FileAccess.Read);
                using (var zipArchive = new ZipArchive(fileStream))
                {
                    fileStream = null;
                    var flag = MdilListFileNames.Any(entryName => zipArchive.GetEntry(entryName) != null);

                    if (flag)
                    {
                        return(false);
                    }
                }
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }

            return(true);
        }
Ejemplo n.º 16
0
        internal static bool IsTargetApplicableforMdilGeneration(
            ConnectableDevice connectableDevice,
            Version deviceVersion,
            IAppManifestInfo info,
            string appFile)
        {
            switch (info.PackageType)
            {
            case PackageType.UnknownAppx:
                return(IsXapApplicableForMdilGeneration(connectableDevice, deviceVersion, info.IsNative, appFile));

            case PackageType.Main:
            case PackageType.Resource:
            case PackageType.Bundle:
                return(IsAppxApplicableForMdilGeneration(connectableDevice, deviceVersion));

            case PackageType.Framework:
                return(false);

            default:
                throw new NotImplementedException(
                          "MDIL generation applicability cannot be determined for unexpected file type.");
            }
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            int deviceIndex = 0;

            string iconFilePath = "";
            string xapFilePath  = "";
            Guid   appID        = Guid.Empty;

            string root = Directory.GetCurrentDirectory();

            if (args.Length < 1)
            {
                Usage();
                ReadWait();
                return;
            }
            else if (args[0] == "-devices")
            {
                ListDevices();
                ReadWait();
                return;
            }
            else if (args.Length > 1 && args[1].StartsWith("-d:"))
            {
                deviceIndex = int.Parse(args[1].Substring(3));
            }


            if (Directory.Exists(args[0]))
            {
                DirectoryInfo info = new DirectoryInfo(args[0]);
                root = info.FullName;
            }

            appID = ReadAppId(root);
            if (appID == Guid.Empty)
            {
                return;    // Logging of errors is done in ReadAppId
            }

            if (File.Exists(root + @"\ApplicationIcon.png"))
            {
                iconFilePath = root + @"\ApplicationIcon.png";
            }
            else
            {
                Log(string.Format("Error: could not find application icon at {0}", root + @"\ApplicationIcon.png"), true);
                ReadWait();
                return;
            }

            xapFilePath = Directory.GetFiles(root + @"\Bin\Debug", "*.xap").FirstOrDefault();
            if (string.IsNullOrEmpty(xapFilePath))
            {
                Log(string.Format("Error: could not find application .xap in folder {0}", root), true);
                ReadWait();
                return;
            }

            ConnectableDevice deviceConn = GetDeviceAtIndex(deviceIndex);

            Log("Connecting to device :: " + deviceConn.Id + " : " + deviceConn.Name);
            try
            {
                IDevice            device = deviceConn.Connect();
                IRemoteApplication app    = null;
                if (device.IsApplicationInstalled(appID))
                {
                    Log("Uninstalling XAP from " + deviceConn.Name);
                    app = device.GetApplication(appID);
                    app.Uninstall();
                }

                Log("Installing app on " + deviceConn.Name);
                app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);

                Log("Launching app on " + deviceConn.Name);
                app.Launch();

                // To Stop :
                //app.TerminateRunningInstances();

                device.Disconnect();

                ReadWait();
            }
            catch (Exception ex)
            {
                Log("Error :: " + ex.Message, true);
            }
        }
        public void RemoveDevice(ConnectableDevice device)
        {
            if (device == null)
                return;

            activeDevices.Remove(device.Id);
            storedDevices.Remove(device.Id);

            Store();
        }
 public void OnDeviceReady(ConnectableDevice device)
 {
 }
 public void OnConnectionFailed(ConnectableDevice device, ServiceCommandError error)
 {
 }
 public void HandleDeviceUpdate(ConnectableDevice device)
 {
     if (DeviceIsCompatible(device))
     {
         if (device.IpAddress != null && compatibleDevices.ContainsKey(device.IpAddress))
         {
             foreach (var listenter in discoveryListeners)
             {
                 listenter.OnDeviceUpdated(this, device);
             }
         }
         else
         {
             HandleDeviceAdd(device);
         }
     }
     else
     {
         ConnectableDevice c;
         compatibleDevices.TryRemove(device.IpAddress,out c);
         HandleDeviceLoss(device);
     }
 }
        public void HandleDeviceAdd(ConnectableDevice device)
        {
            if (!DeviceIsCompatible(device))
                return;

            if (!compatibleDevices.ContainsKey(device.IpAddress))
                compatibleDevices.TryAdd(device.IpAddress, device);

            foreach (var listenter in discoveryListeners)
            {
                listenter.OnDeviceAdded(this, device);
            }
        }
 public void OnCapabilityUpdated(ConnectableDevice device, List<string> added, List<string> removed)
 {
     //throw new NotImplementedException();
 }
Ejemplo n.º 24
0
        static int Main(string[] args)
        {
            MultiTargetingConnectivity UWPSDK = new MultiTargetingConnectivity(CultureInfo.CurrentCulture.LCID, false);

            bool useEmulator            = true;
            ConnectableDevice cDevice   = null;
            IDevice           UWPDevice = null;

            if (args.Length < 5)
            {
                Console.WriteLine("Invalid parameters");
                return(1);
            }

            args[2] = args[2].Replace('/', '\\');
            args[3] = args[3].Replace('/', '\\');
            if (args.Length > 5)
            {
                args[5] = args[5].Replace('/', '\\');
            }

            if (args[4] == "dev")
            {
                useEmulator = false;
            }

            try
            {
                if (useEmulator)
                {
                    cDevice = UWPSDK.GetConnectableDevices(false).Last(d => (d.Name.StartsWith("Mobile ") && d.Name.Contains("2GB") && d.IsEmulator()));
                }
                else
                {
                    cDevice = UWPSDK.GetConnectableDevices(false).First(d => d.Name.StartsWith("Device") || d.Name.StartsWith("Windows Phone 10 Device") ||
                                                                        d.Name.StartsWith("Windows Phone Device") || d.Name.StartsWith("Windows phone"));
                }
            }
            catch
            {
                Console.WriteLine("Cannot find Windows Phone Emulator/Device.");
                return(3);
            }

            Console.WriteLine("Connecting to " + cDevice.Name);
            try
            {
                UWPDevice = cDevice.Connect(true);
            }
            catch
            {
                Console.WriteLine("Failed to connect to Windows Phone Emulator/Device.");
                return(4);
            }
            Console.WriteLine("Windows Phone Emulator/Device Connected...");

            Guid appID = Guid.Parse(args[0]);

            IRemoteApplication app;

            if (UWPDevice.IsApplicationInstalled(appID))
            {
                if (args[4] == "emulibs")
                {
                    Console.WriteLine("Library is already installed");
                    return(0);
                }
                Console.WriteLine("Updating sample APPX to Windows Phone Emulator/Device...");

                app = UWPDevice.GetApplication(appID);

                if (args.Length == 6)
                {
                    var    remoteIso             = app.GetIsolatedStore();
                    string targetDesktopFilePath = @args[5];
                    try
                    {
                        remoteIso.ReceiveFile(Path.DirectorySeparatorChar + "rho" + Path.DirectorySeparatorChar + "rholog.txt", targetDesktopFilePath, true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Can't receive rholog.txt from the " + (useEmulator ? "emulator" : "device") + ": " + e.Message);
                        return(2);
                    }
                    return(0);
                }

                app.Uninstall();
            }

            Console.WriteLine("Installing sample APPX to Windows Phone Emulator/Device...");
            try
            {
                app = UWPDevice.InstallApplication(appID, appID, args[1], args[2], args[3]);
                Console.WriteLine("Sample APPX installed to Windows Phone Emulator...");

                Console.WriteLine("Launching sample app on Windows Phone Emulator...");
                app.Launch();
                Console.WriteLine("Launched sample app on Windows Phone Emulator...");
            }
            catch (Exception e)
            {
                Console.WriteLine("Launching error: " + e.Message);
            }

            return(0);
        }
Ejemplo n.º 25
0
 private static bool IsAppxApplicableForMdilGeneration(
     ConnectableDevice connectableDevice,
     Version deviceVersion)
 {
     return(!connectableDevice.IsEmulator() && !(deviceVersion < WindowsPhone8Dot1Version));
 }
 public void OnConnectionFailed(ConnectableDevice device, ServiceCommandError error)
 {
     throw new NotImplementedException();
 }
 public void OnCapabilityUpdated(ConnectableDevice device, List <string> added, List <string> removed)
 {
     //throw new NotImplementedException();
 }
 public void OnPairingRequired(ConnectableDevice device, DeviceService service, PairingType pairingType)
 {
 }
        public void AddServiceDescriptionToDevice(ServiceDescription desc, ConnectableDevice device)
        {
            Logger.Current.AddMessage(string.Format("Adding service: {0} to device with address {1} and id {2}", desc.ServiceId, device.IpAddress, device.Id));
            var deviceServiceClass = deviceClasses[desc.ServiceId];

            if (deviceServiceClass == null)
                return;

            if (deviceServiceClass == typeof (DlnaService))
            {
                if (desc.LocationXml == null)
                    return;
            }
            else if (deviceServiceClass == typeof (NetcastTvService))
            {
                if (!IsNetcast(desc))
                    return;
            }

            ServiceConfig serviceConfig = null;

            if (connectableDeviceStore != null)
                serviceConfig = connectableDeviceStore.GetServiceConfig(desc);

            if (serviceConfig == null)
                serviceConfig = new ServiceConfig(desc);

            serviceConfig.Listener = this;

            var hasType = false;
            var hasService = false;

            foreach (DeviceService service in device.Services)
            {
                if (!service.ServiceDescription.ServiceId.Equals(desc.ServiceId)) continue;
                hasType = true;
                if (service.ServiceDescription.Uuid.Equals(desc.Uuid))
                {
                    hasService = true;
                }
                break;
            }

            if (hasType)
            {
                if (hasService)
                {
                    device.ServiceDescription = desc;

                    var alreadyAddedService = device.GetServiceByName(desc.ServiceId);

                    if (alreadyAddedService != null)
                        alreadyAddedService.SetServiceDescription(desc);

                    return;
                }

                device.RemoveServiceByName(desc.ServiceId);
            }

            var deviceService = DeviceService.GetService(deviceServiceClass, desc, serviceConfig);

            if (deviceService == null) return;

            deviceService.SetServiceDescription(desc);
            device.AddService(deviceService);

            //    Type deviceServiceClass;

            //    if (IsNetcast(desc))
            //    {
            //        deviceServiceClass = typeof(NetcastTvService);
            //        var m = deviceServiceClass.GetRuntimeMethod("discoveryParameters", new Type[] { });
            //        var result = m.Invoke(null, new object[0]);

            //        if (result == null)
            //            return;

            //        var discoveryParameters = (JsonObject)result;
            //        var serviceId = discoveryParameters.GetNamedString("serviceId");

            //        if (serviceId.Length == 0)
            //            return;

            //        desc.ServiceId = serviceId;
            //    }
            //    else
            //    {
            //        deviceServiceClass = deviceClasses[desc.ServiceId];
            //    }

            //    if (deviceServiceClass == null)
            //        return;

            //    if (typeof(DlnaService) == deviceServiceClass)
            //    {
            //        const string netcast = "netcast";
            //        const string webos = "webos";

            //        var locNet = desc.LocationXml.IndexOf(netcast, StringComparison.Ordinal);
            //        var locWeb = desc.LocationXml.IndexOf(webos, StringComparison.Ordinal);

            //        if (locNet == -1 && locWeb == -1)
            //            return;
            //    }

            //    var serviceConfig = new ServiceConfig(desc) {Listener = this};

            //    var hasType = false;
            //    var hasService = false;

            //    foreach (var service in device.GetServices().Where(service => service.ServiceDescription.ServiceId.Equals(desc.ServiceId)))
            //    {
            //        hasType = true;
            //        if (service.ServiceDescription.Uuid.Equals(desc.Uuid))
            //        {
            //            hasService = true;
            //        }
            //        break;
            //    }

            //    if (hasType)
            //    {
            //        if (hasService)
            //        {
            //            device.SetServiceDescription(desc);

            //            var alreadyAddedService = device.GetServiceByName(desc.ServiceId);

            //            if (alreadyAddedService != null)
            //                alreadyAddedService.ServiceDescription = desc;

            //            return;
            //        }

            //        device.RemoveServiceByName(desc.ServiceId);
            //    }

            //    var deviceService = DeviceService.GetService(deviceServiceClass, desc, serviceConfig);
            //    deviceService.ServiceDescription = desc;
            //    device.AddService(deviceService);
            //}
        }
Ejemplo n.º 30
0
 public void AddDevice(ConnectableDevice device)
 {
     discoverredDevices.Add(device);
 }
        public bool DeviceIsCompatible(ConnectableDevice device)
        {
            if (capabilityFilters == null || capabilityFilters.Count == 0)
            {
                return true;
            }

            return capabilityFilters.Any(filter => device.HasCapabilities(filter.Capabilities));
        }
 public void OnDeviceReady(ConnectableDevice device)
 {
     if (Paired != null)
         Paired(this, device);
 }
        public void HandleDeviceLoss(ConnectableDevice device)
        {
            foreach (var listenter in discoveryListeners)
            {
                listenter.OnDeviceRemoved(this, device);
            }

            device.Disconnect();
        }
        public void UpdateDevice(ConnectableDevice device)
        {
            if (device == null || device.Services.Count == 0)
                return;

            var storedDevice = GetStoredDevice(device.Id);

            if (storedDevice == null)
                return;

            storedDevice.SetNamedValue(ConnectableDevice.KeyLastIp, JsonValue.CreateStringValue(device.LastKnownIpAddress));
            if (device.LastSeenOnWifi != null)
                storedDevice.SetNamedValue(ConnectableDevice.KeyLastSeen, JsonValue.CreateStringValue(device.LastSeenOnWifi));
            if (device.LastConnected > 0)
                storedDevice.SetNamedValue(ConnectableDevice.KeyLastConnected, JsonValue.CreateNumberValue(device.LastConnected));
            if (device.LastDetection > 0)
                storedDevice.SetNamedValue(ConnectableDevice.KeyLastDetected, JsonValue.CreateNumberValue(device.LastDetection));

            var tempServices = storedDevice.GetNamedObject(ConnectableDevice.KeyServices) ?? new JsonObject();

            foreach (var service in device.Services)
            {
                var serviceInfo = service.ToJsonObject();

                if (serviceInfo != null)
                    tempServices.SetNamedValue(service.ServiceDescription.Uuid, serviceInfo);
            }

            storedDevice.SetNamedValue(ConnectableDevice.KeyServices, tempServices);

            storedDevices.SetNamedValue(device.Id, storedDevice);
            if (activeDevices.ContainsKey(device.Id))
                activeDevices.Remove(device.Id);
            activeDevices.Add(device.Id, device);

            Store();
        }
 public void OnCapabilityUpdated(ConnectableDevice device, List<string> added, List<string> removed)
 {
     HandleDeviceUpdate(device);
 }
        public ConnectableDevice GetDevice(string uuidParam)
        {
            if (string.IsNullOrEmpty(uuidParam))
                return null;

            var foundDevice = GetActiveDevice();

            if (foundDevice == null)
            {
                var foundDeviceInfo = GetStoredDevice(uuidParam);

                if (foundDeviceInfo != null)
                    foundDevice = new ConnectableDevice(foundDeviceInfo);
            }

            return foundDevice;
        }
 public void OnDeviceDisconnected(ConnectableDevice device)
 {
 }
Ejemplo n.º 38
0
 public void AddDevice(ConnectableDevice device)
 {
     discoverredDevices.Add(device);
 }
        public void OnServiceAdded(IDiscoveryProvider provider, ServiceDescription serviceDescription)
        {
            Logger.Current.AddMessage(string.Format("Service added: {0}({1})", serviceDescription.FriendlyName, serviceDescription.ServiceId));
            var deviceIsNew = !allDevices.ContainsKey(serviceDescription.IpAddress);

            var device =
                (from d in allDevices where d.Key == serviceDescription.IpAddress select d.Value).FirstOrDefault();

            if (device == null)
            {
                device = new ConnectableDevice(serviceDescription) {IpAddress = serviceDescription.IpAddress};
                allDevices.TryAdd(serviceDescription.IpAddress, device);
                deviceIsNew = true;
            }

            device.LastDetection = Util.GetTime();
            device.LastKnownIpAddress = serviceDescription.IpAddress;
            //  TODO: Implement the currentSSID Property in DiscoveryManager
            //		device.setLastSeenOnWifi(currentSSID);

            AddServiceDescriptionToDevice(serviceDescription, device);

            if (device.Services.Count == 0)
                return; // we get here when a non-LG DLNA TV is found

            if (deviceIsNew)
                HandleDeviceAdd(device);
            else
                HandleDeviceUpdate(device);
        }
 public void OnDeviceRemoved(DiscoveryManager manager, ConnectableDevice device)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 41
0
        static void Main(string[] args)
        {
            int deviceIndex = 0;

            string iconFilePath   = "";
            string xapFilePath    = "";
            Guid   appID          = Guid.Empty;
            bool   uninstallFirst = args.Contains("-uninstall");
            bool   awaitAppClose  = args.Contains("-wait");

            string root = Directory.GetCurrentDirectory();

            if (args.Length < 1)
            {
                Usage();
                ReadWait();
                return;
            }
            else if (args.Contains("-devices"))
            {
                ListDevices();
                ReadWait();
                return;
            }
            else if (args.Length > 1 && args[1].StartsWith("-d:"))
            {
                deviceIndex = int.Parse(args[1].Substring(3));
            }

            if (Directory.Exists(args[0]))
            {
                var info = new DirectoryInfo(args[0]);
                root = info.FullName;

                try
                {
                    xapFilePath = Directory.GetFiles(root + @"\Bin\Debug", "*.xap").FirstOrDefault();
                }
                catch (DirectoryNotFoundException)
                {
                    try
                    {
                        xapFilePath = Directory.GetFiles(root + @"\Bin\Release", "*.xap").FirstOrDefault();
                    }
                    catch (DirectoryNotFoundException)
                    {
                        Log(string.Format("Error: could not find project build directoy in {0}", root), true);
                        Log("make sure your app has been successfully built before deploying.", true);
                    }
                }
            }

            if (File.Exists(args[0]))
            {
                var info = new FileInfo(args[0]);
                if (info.Extension == ".xap")
                {
                    root        = info.DirectoryName;
                    xapFilePath = info.FullName;
                }
            }

            appID = ReadAppId(root);
            if (appID == Guid.Empty)
            {
                return;    // Logging of errors is done in ReadAppId
            }

            if (File.Exists(root + @"\ApplicationIcon.png"))
            {
                iconFilePath = root + @"\ApplicationIcon.png";
            }
            else
            {
                Log(string.Format("Error: could not find application icon at {0}", root + @"\ApplicationIcon.png"), true);
                ReadWait();
                return;
            }

            if (string.IsNullOrEmpty(xapFilePath))
            {
                Log(string.Format("Error: could not find application .xap in folder {0}", root), true);
                ReadWait();
                return;
            }

            ConnectableDevice deviceConn = GetDeviceAtIndex(deviceIndex);

            Log("Connecting to device :: " + deviceConn.Id + " : " + deviceConn.Name);
            try
            {
                IDevice            device = deviceConn.Connect();
                IRemoteApplication app    = null;
                if (device.IsApplicationInstalled(appID))
                {
                    app = device.GetApplication(appID);
                    if (uninstallFirst)
                    {
                        Log("Uninstalling app on " + deviceConn.Name);
                        app.Uninstall();
                        Log("Installing app on " + deviceConn.Name);
                        app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);
                    }
                    else
                    {
                        Log("Updating app on " + deviceConn.Name);
                        app.UpdateApplication("NormalApp", iconFilePath, xapFilePath);
                    }
                }
                else
                {
                    Log("Installing app on " + deviceConn.Name);
                    app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);
                }

                Log("Launching app on " + deviceConn.Name);
                app.Launch();

                if (awaitAppClose)
                {
                    // wait for the app to launch
                    Thread.Sleep(4000);

                    bool isExiting = false;

                    string tempFileName = Path.GetTempFileName();

                    try
                    {
                        IRemoteIsolatedStorageFile isoFile = app.GetIsolatedStore();
                        int index = 0;
                        while (!isExiting) //app.IsRunning()) // not implemented ... wtf?
                        {
                            char[] buffer = new char[1000];

                            isoFile.ReceiveFile((object)Path.DirectorySeparatorChar + "debugOutput.txt", tempFileName, true);
                            using (StreamReader reader = System.IO.File.OpenText(tempFileName))
                            {
                                try
                                {
                                    int newLinesRead = 0;
                                    for (int lineNum = 0; ; lineNum++)
                                    {
                                        if (reader.Peek() > -1)
                                        {
                                            string str = reader.ReadLine();
                                            if (lineNum >= index)
                                            {
                                                newLinesRead++;
                                                if (str == "EXIT")
                                                {
                                                    isExiting = true;
                                                }
                                                Log(str);
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    index += newLinesRead;
                                }
                                catch (Exception)
                                {
                                    // at end of stream most likely, no worries, ... move along.
                                }
                            }

                            Thread.Sleep(1000);
                        }

                        System.IO.File.Delete(tempFileName);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                    }
                }

                // To Stop :
                //app.TerminateRunningInstances();

                device.Disconnect();

                ReadWait();
            }
            catch (Exception ex)
            {
                Log("Error :: " + ex.Message, true);
            }
        }
Ejemplo n.º 42
0
 internal static bool IsTargetApplicableforMdilGeneration(
     ConnectableDevice connectableDevice, 
     Version deviceVersion, 
     IAppManifestInfo info, 
     string appFile)
 {
     switch (info.PackageType)
     {
         case PackageType.UnknownAppx:
             return IsXapApplicableForMdilGeneration(connectableDevice, deviceVersion, info.IsNative, appFile);
         case PackageType.Main:
         case PackageType.Resource:
         case PackageType.Bundle:
             return IsAppxApplicableForMdilGeneration(connectableDevice, deviceVersion);
         case PackageType.Framework:
             return false;
         default:
             throw new NotImplementedException(
                 "MDIL generation applicability cannot be determined for unexpected file type.");
     }
 }
Ejemplo n.º 43
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                return(showHelp());
            }

            string command = null;
            string wpsdk   = null;
            string udid    = null;
            Guid   appid   = Guid.Empty;
            int    i;

            for (i = 0; i < args.Length; i++)
            {
                if (args[i] == "--wpsdk")
                {
                    if (i + 1 < args.Length)
                    {
                        wpsdk = args[++i];
                    }
                }
                else if (command == null)
                {
                    command = args[i];
                    if (command == "connect" && i + 1 < args.Length)
                    {
                        udid = args[++i];
                    }
                    else if (command == "launch" && i + 1 < args.Length)
                    {
                        udid = args[++i];
                        string rawAppId = args[++i];
                        try
                        {
                            appid = Guid.Parse(rawAppId);
                        } catch (FormatException fe)
                        {
                            return(showHelp("Invalid app GUID format: " + rawAppId));
                        }
                    }
                }
            }

            if (wpsdk == null)
            {
                wpsdk = "10.0";
            }
            else
            {
                // trim whatever version number they pass in to 2 digits
                string[] parts = wpsdk.Split(new Char [] { '.' });
                wpsdk = "";
                i     = 0;
                while (i < 2)
                {
                    if (wpsdk.Length > 0)
                    {
                        wpsdk += '.';
                    }
                    if (i < parts.Length)
                    {
                        wpsdk += parts[i];
                    }
                    else
                    {
                        wpsdk += '0';
                    }
                    i++;
                }
            }
            if (!wpsdk.Equals("10.0") && !wpsdk.Equals("8.1"))
            {
                return(showHelp("Unsupported wpsdk value. Please use '10.0' or '8.1'."));
            }

            int localeId = CultureInfo.CurrentUICulture.LCID;
            MultiTargetingConnectivity     multiTargetingConnectivity = new MultiTargetingConnectivity(localeId);
            Collection <ConnectableDevice> devices = multiTargetingConnectivity.GetConnectableDevices();

            List <ConnectableDevice> deviceList = new List <ConnectableDevice>();

            i = 0;
            foreach (ConnectableDevice dev in devices)
            {
                // Filter to device and emulators that match the given SDK. We use 6.3 Version as the marker for 8.1 emus, assume rest are 10.0
                string versionString = dev.Version.ToString();
                if (!dev.IsEmulator() || (wpsdk == "8.1" && versionString.Equals("6.3")) || (wpsdk == "10.0" && !versionString.Equals("6.3")))
                {
                    deviceList.Add(dev);
                    i++;
                }
            }

            if (command == "enumerate")
            {
                int id = 0;
                int j  = 0;

                Console.WriteLine("{");

                Console.WriteLine("\t\"devices\": [");
                foreach (ConnectableDevice dev in deviceList)
                {
                    string versionString = dev.Version.ToString();
                    if (!dev.IsEmulator())
                    {
                        if (j > 0)
                        {
                            Console.WriteLine(",");
                        }
                        string sdk = "null";
                        if (versionString == "6.3")
                        {
                            sdk = "\"8.1\"";
                        }
                        else if (versionString == "10.0")
                        {
                            sdk = "\"10.0\"";
                        }
                        Console.WriteLine("\t\t{\n");
                        Console.WriteLine("\t\t\t\"name\": \"" + dev.Name.Replace("\"", "\\\"") + "\",");
                        Console.WriteLine("\t\t\t\"udid\": " + id + ",");
                        Console.WriteLine("\t\t\t\"index\": " + id + ",");
                        Console.WriteLine("\t\t\t\"version\": \"" + versionString + "\",");                         // windows 8.1: "6.3", windows 10: "10.0"
                        Console.WriteLine("\t\t\t\"wpsdk\": " + sdk);
                        Console.Write("\t\t}");
                        j++;
                    }
                    id++;
                }
                Console.WriteLine("\n\t],");

                id = 0;
                j  = 0;

                Console.WriteLine("\t\"emulators\": [");
                foreach (ConnectableDevice dev in deviceList)
                {
                    if (dev.IsEmulator())
                    {
                        if (j > 0)
                        {
                            Console.WriteLine(",");
                        }

                        Console.WriteLine("\t\t{\n");
                        Console.WriteLine("\t\t\t\"name\": \"" + dev.Name.Replace("\"", "\\\"") + "\",");
                        Console.WriteLine("\t\t\t\"udid\": \"" + wpsdk.Replace('.', '-') + "-" + id + "\",");
                        Console.WriteLine("\t\t\t\"index\": " + id + ",");
                        Console.WriteLine("\t\t\t\"guid\": \"" + dev.Id + "\",");
                        Console.WriteLine("\t\t\t\"version\": \"" + dev.Version + "\",");                         // 6.3 for 8.1 emulators, 6.4 for 10 emulators, 2147483647.2147483647.2147483647.2147483647 for device
                        Console.WriteLine("\t\t\t\"uapVersion\": \"" + dev.UapVersion + "\",");                   // blank/empty for 8.1 emulators and device, 10.0.10586.0 for win 10 emulators
                        Console.WriteLine("\t\t\t\"wpsdk\": \"" + wpsdk + "\"");
                        Console.Write("\t\t}");
                        j++;
                    }
                    id++;
                }
                Console.WriteLine("\n\t]");

                Console.WriteLine("}");
                return(0);
            }

            // This won't just connect, it will launch the emulator!
            if (command == "connect" || command == "launch")
            {
                if (udid == null)
                {
                    return(showHelp("Missing device/emulator UDID"));
                }
                // TODO Validate that the udid is either our generated udid (i.e. 10-0-1), or it's GUID, or it's an integer index value!

                int id = 0;
                // Search devices for udid!
                ConnectableDevice connectableDevice = null;
                foreach (ConnectableDevice dev in deviceList)
                {
                    // Is it a matching GUID, matching UDID or matching Index value?
                    if (dev.Id.Equals(udid) || (wpsdk.Replace('.', '-') + "-" + id).Equals(udid) || udid.Equals(id.ToString()))
                    {
                        connectableDevice = dev;
                        break;
                    }
                    id++;
                }
                if (connectableDevice == null)
                {
                    return(showHelp(String.Format("Invalid device UDID '{0:D}'", udid)));
                }

                // ConnectableDevice throws an error when connecting to a physical Windows 10 device
                // physical Windows 10 devices can be connected to using 127.0.0.1
                if (command == "connect" && connectableDevice.Version.Major == 10 && !connectableDevice.IsEmulator())
                {
                    Console.WriteLine("{");
                    Console.WriteLine("\t\"success\": true,");
                    Console.WriteLine("\t\"ip\": \"127.0.0.1\",");
                    Console.WriteLine("\t\"osVersion\": \"" + connectableDevice.Version.ToString() + "\"");
                    Console.WriteLine("}");
                    return(0);
                }

                try {
                    IDevice device = connectableDevice.Connect();

                    if (command == "launch")
                    {
                        IRemoteApplication app = device.GetApplication(appid);
                        app.Launch();
                        Console.WriteLine("{");
                        Console.WriteLine("\t\"success\": true");
                        Console.WriteLine("}");
                    }
                    else
                    {
                        string destinationIp;
                        string sourceIp;
                        int    destinationPort;
                        device.GetEndPoints(0, out sourceIp, out destinationIp, out destinationPort);
                        var         address    = IPAddress.Parse(destinationIp);
                        ISystemInfo systemInfo = device.GetSystemInfo();

                        Version version = new Version(systemInfo.OSMajor, systemInfo.OSMinor, systemInfo.OSBuildNo);
                        Console.WriteLine("{");
                        Console.WriteLine("\t\"success\": true,");
                        Console.WriteLine("\t\"ip\": \"" + address.ToString() + "\",");
                        Console.WriteLine("\t\"port\": " + destinationPort.ToString() + ",");
                        Console.WriteLine("\t\"osVersion\": \"" + version.ToString() + "\",");
                        Console.WriteLine("\t\"availablePhysical\": " + systemInfo.AvailPhys.ToString() + ",");
                        Console.WriteLine("\t\"totalPhysical\": " + systemInfo.TotalPhys.ToString() + ",");
                        Console.WriteLine("\t\"availableVirtual\": " + systemInfo.AvailVirtual.ToString() + ",");
                        Console.WriteLine("\t\"totalVirtual\": " + systemInfo.TotalVirtual.ToString() + ",");
                        Console.WriteLine("\t\"architecture\": \"" + systemInfo.ProcessorArchitecture.ToString() + "\",");
                        Console.WriteLine("\t\"instructionSet\": \"" + systemInfo.InstructionSet.ToString() + "\",");
                        Console.WriteLine("\t\"processorCount\": " + systemInfo.NumberOfProcessors.ToString() + "");
                        Console.WriteLine("}");
                    }
                    return(0);
                } catch (Exception ex) {
                    Console.WriteLine("{");
                    Console.WriteLine("\t\"success\": false,");
                    Console.WriteLine("\t\"message\": \"" + ex.Message.Trim().Replace("\"", "\\\"") + "\"");
                    Console.WriteLine("}");
                    return(1);
                }
            }

            if (command != null)
            {
                return(showHelp(String.Format("Invalid command '{0}'", command)));
            }

            return(showHelp());
        }
Ejemplo n.º 44
0
 private static bool IsAppxApplicableForMdilGeneration(
     ConnectableDevice connectableDevice, 
     Version deviceVersion)
 {
     return !connectableDevice.IsEmulator() && !(deviceVersion < WindowsPhone8Dot1Version);
 }
 public void OnConnectionFailed(ConnectableDevice device, ServiceCommandError error)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 46
0
        private static bool IsXapApplicableForMdilGeneration(
            ConnectableDevice connectableDevice, 
            Version deviceVersion, 
            bool isNative, 
            string xapFile)
        {
            if (connectableDevice.IsEmulator() || deviceVersion < WindowsPhone8Dot0Version || isNative)
            {
                return false;
            }

            var fileStream = (FileStream)null;
            try
            {
                fileStream = new FileStream(xapFile, FileMode.Open, FileAccess.Read);
                using (var zipArchive = new ZipArchive(fileStream))
                {
                    fileStream = null;
                    var flag = MdilListFileNames.Any(entryName => zipArchive.GetEntry(entryName) != null);

                    if (flag)
                    {
                        return false;
                    }
                }
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }

            return true;
        }
Ejemplo n.º 47
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                return(showHelp());
            }

            int localeId = CultureInfo.CurrentUICulture.LCID;
            MultiTargetingConnectivity     multiTargetingConnectivity = new MultiTargetingConnectivity(localeId);
            Collection <ConnectableDevice> devices = multiTargetingConnectivity.GetConnectableDevices(false);

            string command = null;
            string wpsdk   = null;
            int    udid    = -1;
            int    i;

            for (i = 0; i < args.Length; i++)
            {
                if (args[i] == "--wpsdk")
                {
                    if (i + 1 < args.Length)
                    {
                        wpsdk = args[++i];
                    }
                }
                else if (command == null)
                {
                    command = args[i];
                    if (command == "connect" && i + 1 < args.Length)
                    {
                        try {
                            udid = int.Parse(args[++i]);
                        } catch (Exception ex) {
                            return(showHelp(String.Format("Invalid device UDID '{0}'", args[i])));
                        }
                    }
                }
            }

            if (wpsdk == null)
            {
                wpsdk = "8.1";
            }
            else
            {
                // trim whatever version number they pass in to 2 digits
                string[] parts = wpsdk.Split(new Char [] { '.' });
                wpsdk = "";
                i     = 0;
                while (i < 2)
                {
                    if (wpsdk.Length > 0)
                    {
                        wpsdk += '.';
                    }
                    if (i < parts.Length)
                    {
                        wpsdk += parts[i];
                    }
                    else
                    {
                        wpsdk += '0';
                    }
                    i++;
                }
            }

            List <ConnectableDevice> deviceList = new List <ConnectableDevice>();

            i = 0;
            foreach (ConnectableDevice dev in multiTargetingConnectivity.GetConnectableDevices(false))
            {
                if (!dev.IsEmulator() || (wpsdk == "8.0" && dev.IsLegacyEmulator()) || (wpsdk != "8.0" && !dev.IsLegacyEmulator()))
                {
                    deviceList.Add(dev);
                    i++;
                }
            }

            if (command == "enumerate")
            {
                int id = 0;
                int j  = 0;

                Console.WriteLine("{");

                Console.WriteLine("\t\"devices\": [");
                foreach (ConnectableDevice dev in deviceList)
                {
                    if (!dev.IsEmulator())
                    {
                        if (j > 0)
                        {
                            Console.WriteLine(",");
                        }
                        Console.WriteLine("\t\t{\n");
                        Console.WriteLine("\t\t\t\"name\": \"" + dev.Name.Replace("\"", "\\\"") + "\",");
                        Console.WriteLine("\t\t\t\"udid\": " + id + ",");
                        Console.WriteLine("\t\t\t\"index\": " + id + ",");
                        Console.WriteLine("\t\t\t\"wpsdk\": null");
                        Console.Write("\t\t}");
                        j++;
                    }
                    id++;
                }
                Console.WriteLine("\n\t],");

                id = 0;
                j  = 0;

                Console.WriteLine("\t\"emulators\": [");
                foreach (ConnectableDevice dev in deviceList)
                {
                    if (dev.IsEmulator())
                    {
                        if (j > 0)
                        {
                            Console.WriteLine(",");
                        }
                        Console.WriteLine("\t\t{\n");
                        Console.WriteLine("\t\t\t\"name\": \"" + dev.Name.Replace("\"", "\\\"") + "\",");
                        Console.WriteLine("\t\t\t\"udid\": \"" + wpsdk.Replace('.', '-') + "-" + id + "\",");
                        Console.WriteLine("\t\t\t\"index\": " + id + ",");
                        Console.WriteLine("\t\t\t\"wpsdk\": \"" + wpsdk + "\"");
                        Console.Write("\t\t}");
                        j++;
                    }
                    id++;
                }
                Console.WriteLine("\n\t]");

                Console.WriteLine("}");
                return(0);
            }

            if (command == "connect")
            {
                // validate the id
                if (udid == -1)
                {
                    return(showHelp("Missing device/emulator UDID"));
                }
                if (udid < 0 || udid >= deviceList.Count)
                {
                    return(showHelp(String.Format("Invalid device UDID '{0:D}'", udid)));
                }

                ConnectableDevice connectableDevice = deviceList[udid];
                try {
                    IDevice     device     = connectableDevice.Connect();
                    ISystemInfo systemInfo = device.GetSystemInfo();
                    Version     version    = new Version(systemInfo.OSMajor, systemInfo.OSMinor);
                    Console.WriteLine("{\"success\":true}");
                    return(0);
                } catch (Exception ex) {
                    Console.WriteLine("{");
                    Console.WriteLine("\t\"success\": false,");
                    Console.WriteLine("\t\"message\": \"" + ex.Message.Trim().Replace("\"", "\\\"") + "\"");
                    Console.WriteLine("}");
                    return(1);
                }
            }

            if (command != null)
            {
                return(showHelp(String.Format("Invalid command '{0}'", command)));
            }

            return(showHelp());
        }
Ejemplo n.º 48
0
        static int Main(string[] args)
        {
            MultiTargetingConnectivity WP8SDK = new MultiTargetingConnectivity(CultureInfo.CurrentCulture.LCID, false);
            //foreach (ConnectableDevice device in WP8SDK.GetConnectableDevices(false))
            //    Console.WriteLine(device.Name);

            bool useEmulator            = true;
            ConnectableDevice cDevice   = null;
            IDevice           WP8Device = null;

            if (args.Length < 5)
            {
                Console.WriteLine("Invalid parameters");
                return(1);
            }

            args[2] = args[2].Replace('/', '\\');
            args[3] = args[3].Replace('/', '\\');
            if (args.Length > 5)
            {
                args[5] = args[5].Replace('/', '\\');
            }

            if (args[4] == "dev")
            {
                useEmulator = false;
            }

            try
            {
                if (useEmulator)
                {
                    cDevice = WP8SDK.GetConnectableDevices(false).First(d => d.Name.StartsWith("Emulator WVGA"));
                }
                else
                {
                    cDevice = WP8SDK.GetConnectableDevices(false).First(d => d.Name.StartsWith("Device") || d.Name.StartsWith("Windows Phone 8 Device") || d.Name.StartsWith("Windows Phone Device"));
                }
            }
            catch
            {
                Console.WriteLine("Cannot find Windows Phone 8.0 Emulator/Device.");
                return(3);
            }

            Console.WriteLine("Connecting to " + cDevice.Name);
            try
            {
                WP8Device = cDevice.Connect();
            }
            catch
            {
                Console.WriteLine("Failed to connect to Windows Phone 8 Emulator/Device.");
                return(4);
            }
            Console.WriteLine("Windows Phone 8 Emulator/Device Connected...");

            Guid appID = new Guid(args[0]);
            IRemoteApplication app;

            if (WP8Device.IsApplicationInstalled(appID))
            {
                Console.WriteLine("Updating sample XAP to Windows Phone 8 Emulator/Device...");

                app = WP8Device.GetApplication(appID);

                if (args.Length == 6)
                {
                    var    remoteIso             = app.GetIsolatedStore("Local");
                    string targetDesktopFilePath = @args[5];
                    try
                    {
                        remoteIso.ReceiveFile(Path.DirectorySeparatorChar + "rho" + Path.DirectorySeparatorChar + "rholog.txt", targetDesktopFilePath, true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Can't receive rholog.txt from the " + (useEmulator ? "emulator" : "device") + ": " + e.Message);
                        return(2);
                    }
                    return(0);
                }

                app.Uninstall();
            }

            Console.WriteLine("Installing sample XAP to Windows Phone 8 Emulator/Device...");

            app = WP8Device.InstallApplication(
                appID,
                appID,
                args[1],
                args[2],
                args[3]);

            Console.WriteLine("Sample XAP installed to Windows Phone 8 Emulator...");

            Console.WriteLine("Launching sample app on Windows Phone 8 Emulator...");
            app.Launch();
            Console.WriteLine("Launched sample app on Windows Phone 8 Emulator...");
            return(0);
        }
 public void OnDeviceRemoved(DiscoveryManager manager, ConnectableDevice device)
 {
     throw new NotImplementedException();
 }
 public DeviceEventArgs(ConnectableDevice device)
 {
     this._connectedDevice = device;
 }
 public void OnPairingRequired(ConnectableDevice device, DeviceService service, PairingType pairingType)
 {
 }
        public void AddDevice(ConnectableDevice device)
        {
            if (device == null || device.Services.Count == 0)
                return;

            if (!activeDevices.ContainsKey(device.Id))
                activeDevices.Add(device.Id, device);

            if (storedDevices == null)
            {
                storedDevices = new JsonObject();
            }
            var storedDevice = storedDevices.Keys.Contains(device.Id) ? storedDevices.GetNamedObject(device.Id) : null;

            if (storedDevice != null)
            {
                UpdateDevice(device);
            }
            else
            {
                storedDevices.Add(device.Id, device.ToJsonObject());
                Store();
            }
        }