示例#1
0
        static void Main(string[] args)
        {
            Stream fileStream = null;
            string user       = new string(
                (char)0, (int)CredUIHelper.CREDUI_MAX_BUFFER_LENGTH);
            string password = new string(
                (char)0, (int)CredUIHelper.CREDUI_MAX_BUFFER_LENGTH);
            StringBuilder userName     = new StringBuilder(user);
            StringBuilder userPassword = new StringBuilder(password);

            CredUIHelper.CREDUI_INFO credUiInfo =
                new CredUIHelper.CREDUI_INFO();

            //
            // Get credentials
            //

            bool save = false;

            credUiInfo.cbSize         = Marshal.SizeOf(credUiInfo);
            credUiInfo.pszCaptionText = "EC2 Console";
            credUiInfo.pszMessageText = "Please enter your credentials.";
            if (0 != CredUIHelper.CredUIPromptForCredentialsA(
                    ref credUiInfo,
                    "EC2 Server Instance",
                    System.IntPtr.Zero,
                    0,
                    userName,
                    CredUIHelper.CREDUI_MAX_BUFFER_LENGTH,
                    userPassword,
                    CredUIHelper.CREDUI_MAX_BUFFER_LENGTH,
                    ref save,
                    CredUIHelper.CREDUI_FLAGS.DO_NOT_PERSIST |
                    CredUIHelper.CREDUI_FLAGS.GENERIC_CREDENTIALS |
                    CredUIHelper.CREDUI_FLAGS.ALWAYS_SHOW_UI))
            {
                System.Console.WriteLine("Error: credential prompting failed");
                return;
            }

            //
            // Get the MSI file
            //

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "MSI files (*.msi)|*.msi";
            if (DialogResult.OK != ofd.ShowDialog())
            {
                System.Console.WriteLine("Error: open file dialog failed");
                return;
            }

            if (null == (fileStream = ofd.OpenFile()))
            {
                System.Console.WriteLine("Error: failed to open selected file");
                return;
            }

            byte[] fileBytes = new byte[fileStream.Length];
            fileStream.Read(fileBytes, 0, (int)fileStream.Length);

            //
            // Create the web service proxy
            //

            Ec2FileUploadProxy.Ec2FileUpload fileUpload =
                new Ec2FileUploadProxy.Ec2FileUpload();

            //
            // Get client credentials
            //

            CredentialCache cache = new CredentialCache();

            cache.Add(
                new Uri(fileUpload.Url),
                "Negotiate",
                new NetworkCredential(
                    userName.ToString(), userPassword.ToString()));
            fileUpload.Credentials = cache;

            //
            // Call the web service
            //

            if (false == fileUpload.UploadAndInstallMsiFile(
                    "Ec2Install.msi", Convert.ToBase64String(fileBytes)))
            {
                System.Console.WriteLine("Error: upload failed");
                return;
            }

            System.Console.WriteLine("Success");
        }
示例#2
0
        static void Main(string[] args)
        {
            Stream fileStream = null;
            string user = new string(
                (char) 0, (int) CredUIHelper.CREDUI_MAX_BUFFER_LENGTH);
            string password = new string(
                (char)0, (int)CredUIHelper.CREDUI_MAX_BUFFER_LENGTH);
            StringBuilder userName = new StringBuilder(user);
            StringBuilder userPassword = new StringBuilder(password);
            CredUIHelper.CREDUI_INFO credUiInfo =
                new CredUIHelper.CREDUI_INFO();

            //
            // Get credentials
            //

            bool save = false;
            credUiInfo.cbSize = Marshal.SizeOf(credUiInfo);
            credUiInfo.pszCaptionText = "EC2 Console";
            credUiInfo.pszMessageText = "Please enter your credentials.";
            if (0 != CredUIHelper.CredUIPromptForCredentialsA(
                ref credUiInfo,
                "EC2 Server Instance",
                System.IntPtr.Zero,
                0,
                userName,
                CredUIHelper.CREDUI_MAX_BUFFER_LENGTH,
                userPassword,
                CredUIHelper.CREDUI_MAX_BUFFER_LENGTH,
                ref save,
                CredUIHelper.CREDUI_FLAGS.DO_NOT_PERSIST |
                    CredUIHelper.CREDUI_FLAGS.GENERIC_CREDENTIALS |
                    CredUIHelper.CREDUI_FLAGS.ALWAYS_SHOW_UI))
            {
                System.Console.WriteLine("Error: credential prompting failed");
                return;
            }

            //
            // Get the MSI file
            //

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "MSI files (*.msi)|*.msi";
            if (DialogResult.OK != ofd.ShowDialog())
            {
                System.Console.WriteLine("Error: open file dialog failed");
                return;
            }

            if (null == (fileStream = ofd.OpenFile()))
            {
                System.Console.WriteLine("Error: failed to open selected file");
                return;
            }

            byte[] fileBytes = new byte[fileStream.Length];
            fileStream.Read(fileBytes, 0, (int) fileStream.Length);

            //
            // Create the web service proxy
            //

            Ec2FileUploadProxy.Ec2FileUpload fileUpload =
                new Ec2FileUploadProxy.Ec2FileUpload();

            //
            // Get client credentials
            //

            CredentialCache cache = new CredentialCache();
            cache.Add(
                new Uri(fileUpload.Url),
                "Negotiate",
                new NetworkCredential(
                    userName.ToString(), userPassword.ToString()));
            fileUpload.Credentials = cache;

            //
            // Call the web service
            //

            if (false == fileUpload.UploadAndInstallMsiFile(
                "Ec2Install.msi", Convert.ToBase64String(fileBytes)))
            {
                System.Console.WriteLine("Error: upload failed");
                return;
            }

            System.Console.WriteLine("Success");
        }