Exemple #1
0
        static void Main(string[] args)
        {
            string userName = String.Empty;
            string password = String.Empty;
            string domain   = String.Empty;

            if (args.Length >= 2)
            {
                userName = args[0];
                password = args[1];

                if (args.Length > 2)
                {
                    domain = args[2];
                }

                WebCredentials credentials = new WebCredentials
                {
                    userName = userName,
                    password = password,
                    domain   = domain
                };
                credentials.Encrypt();

                Console.WriteLine(credentials.encryptedToken);
            }
            else if (args.Length >= 1)
            {
                string value          = args[0];
                string encryptedValue = Encryption.EncryptString(value);
                Console.WriteLine(encryptedValue);
            }
            else
            {
                Console.WriteLine(HELP_MESSAGE);
            }
        }
Exemple #2
0
        void UpdateCommandExecute()
        {
            try
            {
                bool isValid = true;
                if (_registeryParams.ServicesWebConfig == "")
                {
                    isValid = false;
                    OnPropertyChanged("ServicesWebConfig");
                }

                if (!isValid)
                {
                    MessageBox.Show("One or more parameters invalid.", "Validation Failed", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                XDocument adminConfig = XDocument.Load(_registeryParams.ServicesWebConfig);

                if (String.IsNullOrEmpty(_registeryParams.ProxyHost))
                {
                    adminConfig.RemoveSetting("RegistryCredentialToken");
                    // adminConfig.RemoveSetting("ProxyHost");
                    // adminConfig.RemoveSetting("ProxyPort");
                }
                else
                {
                    if (!String.IsNullOrEmpty(_registeryParams.Username))
                    {
                        WebCredentials credentials = new WebCredentials
                        {
                            userName = _registeryParams.Username,
                            password = _registeryParams.Password,
                            domain   = _registeryParams.Domain
                        };
                        credentials.Encrypt();

                        adminConfig.UpdateSetting("RegistryCredentialToken", credentials.encryptedToken);
                    }
                    else
                    {
                        adminConfig.RemoveSetting("MCraftFileServer");
                    }

                    string proxyPort = _registeryParams.ProxyPort;
                    if (String.IsNullOrEmpty(proxyPort))
                    {
                        proxyPort = "8080";
                    }
                    _registeryParams.ProxyPort = proxyPort;
                    OnPropertyChanged("ProxyPort");

                    // adminConfig.UpdateSetting("ProxyHost", _registeryParams.ProxyHost);
                    // adminConfig.UpdateSetting("ProxyPort", proxyPort);
                }

                adminConfig.Save(_registeryParams.ServicesWebConfig);

                MessageBox.Show("Update complete.", "Update Complete", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error occurred while getting updating proxy configuration. " + exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            // sample code
            //bool isupdated = true;

            //if (_registeryParams.iRingToolsFolder!="")
            //{
            //    isupdated = false;
            //}
            //if (isupdated)
            //{
            //    BackgroundBrush = new SolidColorBrush(Colors.Green);
            //}
            //else
            //{
            //    BackgroundBrush = new SolidColorBrush(Colors.White);
            //}
        }
        private void buttonPull_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _messages.Clear();

                _messages.Add(new StatusMessage {
                    Message = "Pulling Graph from remote Façade...", ImageName = "Resources/info_22.png"
                });

                WebClient client = new WebClient();
                bool      adapterConnect;
                bool      facadeConnect;

                if (chkboxAdapterCredentials.IsChecked == true)
                {
                    adapterConnect = ShowLoginDialog(CredentialType.Adapter) == true;
                }
                else
                {
                    adapterConnect = true;
                }

                if (chkboxFacadeCredentials.IsChecked == true)
                {
                    facadeConnect = ShowLoginDialog(CredentialType.Facade) == true;
                }
                else
                {
                    facadeConnect = true;
                }

                if (adapterConnect && facadeConnect)
                {
                    #region Prepare proxy and facade credentials if required
                    if (!String.IsNullOrEmpty(_proxyHost) && !String.IsNullOrEmpty(_proxyPort))
                    {
                        WebProxy proxy = new WebProxy(_proxyHost, Convert.ToInt16(_proxyPort));
                        proxy.Credentials = CredentialCache.DefaultCredentials;
                        client.Proxy      = proxy;
                    }
                    else
                    {
                        client.Proxy.Credentials = CredentialCache.DefaultCredentials;
                    }
                    if (chkboxAdapterCredentials.IsChecked == true)
                    {
                        NetworkCredential credential = new NetworkCredential(_adapterCredentialUsername, _adapterCredentialPassword, _adapterCredentialDomain);
                        client.Credentials = credential;
                    }
                    else
                    {
                        client.Credentials = CredentialCache.DefaultCredentials;
                    }
                    #endregion

                    //client.Credentials = CredentialCache.DefaultCredentials;

                    //client.Proxy.Credentials = CredentialCache.DefaultCredentials;

                    client.UploadStringCompleted  += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
                    client.Headers["Content-type"] = "application/xml";
                    client.Encoding = Encoding.UTF8;

                    string rootUrl        = textBoxAdapterURL.Text.Substring(0, textBoxAdapterURL.Text.LastIndexOf("/"));
                    string localFacadeUrl = rootUrl + "/facade/svc";

                    Uri pullURI = new Uri(
                        localFacadeUrl + "/" +
                        _project.Name + "/" +
                        _application.Name + "/" +
                        _graph.name + "/pull");

                    Request        request           = new Request();
                    WebCredentials targetCredentials = new WebCredentials();
                    if (chkboxFacadeCredentials.IsChecked == true)
                    {
                        targetCredentials.domain   = _facadeCredentialDomain;
                        targetCredentials.userName = _facadeCredentialUsername;
                        targetCredentials.password = _facadeCredentialPassword;
                        targetCredentials.Encrypt();
                    }
                    string targetCredentialsXML = Utility.Serialize <WebCredentials>(targetCredentials, true);
                    request.Add("targetEndpointUri", textBoxTargetURL.Text);
                    request.Add("targetCredentials", targetCredentialsXML);
                    request.Add("targetGraphBaseUri", comboBoxGraphUri.Text);

                    string message = Utility.SerializeDataContract <Request>(request);

                    client.UploadStringAsync(pullURI, message);
                }
                else
                {
                    _messages.Add(new StatusMessage {
                        Message = "User cancelled operation.", ImageName = "Resources/info_22.png"
                    });
                }
            }
            catch (Exception ex)
            {
                _messages.Clear();

                _messages.Add(new StatusMessage {
                    Message = ex.ToString(), ImageName = "Resources/error_22.png"
                });
            }
        }