Esempio n. 1
0
        public async Task <ProfileManagerClient> GetLoggedInClient()
        {
            string serverUrl            = GetGlobal("SERVER", "http://localhost");
            ProfileManagerClient client = clients.GetValueOrDefault(serverUrl, null);


            if (client == null)
            {
                Console.WriteLine("Using server '{0}'", serverUrl);
                client = new ProfileManagerClient(serverUrl);

                string username = GetGlobal("USERNAME", null);

                while (string.IsNullOrWhiteSpace(username))
                {
                    Console.Write("Username: "******"USERNAME", username);

                string password = GetGlobal("PASSWORD", null);

                while (string.IsNullOrWhiteSpace(password))
                {
                    Console.Write("Password: "******"");
                }

                SetGlobal("USERNAME", password);

                await client.Login(username, password);

                clients.Add(serverUrl, client);
            }

            return(client);
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            // Collect info from JitBit
            var JitBitClient = new JitBitClient("https://newpointe.JitBit.com/helpdesk/");

            Console.Write("JitBit Username: "******"JitBit Password: "******"");

            await JitBitClient.Login(JitBitUsername, JitBitPassword);

            var JitBitAssets = await JitBitClient.GetAllAssets();

            var JitBitAssetsById           = JitBitAssets.ToDictionary(a => a.ItemId);
            var JitBitAssetsBySerialNumber = JitBitAssets.Where(a => a.SerialNumber != null).ToDictionary(a => a.SerialNumber.ToLowerInvariant());

            Console.WriteLine("Found {0} Assets in JitBit", JitBitAssets.Length);

            // Collect info from Profile Manager
            var ProfileManagerClient = new ProfileManagerClient("https://npmdm.newpointe.org/");

            Console.Write("Profile Manager Username: "******"Profile Manager Password: "******"");

            await ProfileManagerClient.Login(ProfileManagerUsername, ProfileManagerPassword);

            var ProfileManagerDeviceIds = await ProfileManagerClient.GetDeviceIds();

            var ProfileManagerDevices = await ProfileManagerClient.GetDevices(ProfileManagerDeviceIds.ToArray());

            var ProfileManagerDevicesById           = ProfileManagerDevices.ToDictionary(d => d.Id);
            var ProfileManagerDevicesBySerialNumber = ProfileManagerDevices.Where(d => d.SerialNumber != null).ToDictionary(d => d.SerialNumber.ToLowerInvariant());

            Console.WriteLine("Found {0} Devices in Profile Manager", ProfileManagerDevices.Length);

            Console.WriteLine("Syncing Devices from Profile Manager to JitBit...", JitBitAssets.Length);

            foreach (var pmDevice in ProfileManagerDevices)
            {
                JitBitRest.Asset jbAsset = null;

                // Try matching by serial number
                if (pmDevice.SerialNumber != null)
                {
                    jbAsset = JitBitAssetsBySerialNumber.GetValueOrDefault(pmDevice.SerialNumber.ToLowerInvariant());

                    // If we got a match, update the JitBit asset
                    if (jbAsset != null)
                    {
                        Console.WriteLine("Syncing device {0}", pmDevice.SerialNumber);

                        var assetUpdate = new JitBitRest.UpdateAssetParameters {
                            Id           = jbAsset.ItemId,
                            ModelName    = string.Format("{0} ({1})", pmDevice.ModelName, pmDevice.DeviceName),
                            Manufacturer = "Apple",
                            Quantity     = 1,
                            SerialNumber = pmDevice.SerialNumber
                        };

                        await JitBitClient.UpdateAsset(assetUpdate);
                    }
                    // Otherwise, create an new asset fot it
                    else
                    {
                        Console.WriteLine("Creating device {0}", pmDevice.SerialNumber);

                        var assetUpdate = new JitBitRest.CreateAssetParameters {
                            ModelName    = string.Format("{0} ({1})", pmDevice.ModelName, pmDevice.DeviceName),
                            Manufacturer = "Apple",
                            Type         = "",
                            Supplier     = "",
                            Quantity     = 1,
                            SerialNumber = pmDevice.SerialNumber
                        };

                        await JitBitClient.CreateAsset(assetUpdate);
                    }

                    Thread.Sleep(1000);
                }
                else
                {
                    Console.WriteLine("Skipping {0} because it has no serial number", pmDevice.DeviceName);
                }
            }
        }