public static string downloadFile(iControl.Interfaces interfaces, string remote_file) { long chunk_size = 64 * 1024; long file_offset = 0; bool bContinue = true; string file_contents = ""; System.IO.StringWriter sw = new System.IO.StringWriter(); if (interfaces.initialized) { iControl.SystemConfigSyncFileTransferContext ftc = new iControl.SystemConfigSyncFileTransferContext(); while (bContinue) { ftc = interfaces.SystemConfigSync.download_file(remote_file, chunk_size, ref file_offset); file_contents += System.Text.ASCIIEncoding.ASCII.GetString(ftc.file_data); if ((ftc.chain_type == iControl.CommonFileChainType.FILE_LAST) || (ftc.chain_type == iControl.CommonFileChainType.FILE_FIRST_AND_LAST)) { bContinue = false; } } } return(file_contents); }
public static bool uploadFile(iControl.Interfaces interfaces, string remote_file_path, string file_contents) { bool bUploaded = false; bool bContinue = true; long chunk_size = 64 * 1024; iControl.SystemConfigSyncFileTransferContext ftc = new iControl.SystemConfigSyncFileTransferContext(); ftc.chain_type = iControl.CommonFileChainType.FILE_FIRST; long total_bytes = 0; System.Text.ASCIIEncoding encoding = new ASCIIEncoding(); string chunk = null; long chunk_length = 0; long file_length = file_contents.Length; if (interfaces.initialized) { while (bContinue) { chunk_length = chunk_size; if (chunk_length > file_length - total_bytes) { chunk_length = file_length - total_bytes; } chunk = file_contents.Substring((int)total_bytes, (int)chunk_length); if (chunk.Length != chunk_size) { if (0 == total_bytes) { ftc.chain_type = iControl.CommonFileChainType.FILE_FIRST_AND_LAST; } else { ftc.chain_type = iControl.CommonFileChainType.FILE_LAST; } bContinue = false; } ftc.file_data = encoding.GetBytes(chunk); total_bytes += chunk.Length; // Upload bytes interfaces.SystemConfigSync.upload_file(remote_file_path, ftc); ftc.chain_type = iControl.CommonFileChainType.FILE_MIDDLE; } } bUploaded = (total_bytes > 0); return(bUploaded); }
private void OKLinkLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { if (0 == HostnameComboBox.Text.Length) { MessageBox.Show("Please enter a hostname.", "Missing information"); HostnameComboBox.Focus(); } else if (0 == PortTextBox.Text.Length) { MessageBox.Show("Please enter a port.", "Missing information"); PortTextBox.Text = "443"; PortTextBox.Focus(); } else if (0 == EndpointTextBox.Text.Length) { MessageBox.Show("Please enter a endpoint (default of /iControl/iControlPortal.cgi).", "Missing information"); EndpointTextBox.Text = "/iControl/iControlPortal.cgi"; EndpointTextBox.Focus(); } else if (0 == UsernameTextBox.Text.Length) { MessageBox.Show("Please enter a username.", "Missing information"); UsernameTextBox.Focus(); } else if (0 == PasswordTextBox.Text.Length) { MessageBox.Show("Please enter a password.", "Missing information"); PasswordTextBox.Focus(); } else if (UseProxyCheckBox.Checked && (ProxyAddressTextBox.Text.Length == 0)) { MessageBox.Show("If you are using a proxy server, please specify the address"); ProxyAddressTextBox.Focus(); } else if (UseProxyCheckBox.Checked && (ProxyPortTextBox.Text.Length == 0)) { MessageBox.Show("If you are using a proxy server, please specify the port"); ProxyPortTextBox.Focus(); } else { bool bInitialized = false; Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; m_ci.setEndpoint(HostnameComboBox.Text, Convert.ToInt32(PortTextBox.Text), EndpointTextBox.Text); m_ci.setCredentials(UsernameTextBox.Text, PasswordTextBox.Text); // Now verify if we can connect to the host if (null == m_interfaces) { m_interfaces = new iControl.Interfaces(); } if (UseProxyCheckBox.Checked) { bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text, ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPassTextBox.Text, m_ci.useHttps); } else { bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text, m_ci.useHttps); } if (bInitialized) { try { //sysInfo.Url = m_ci.buildURL(); iControl.SystemProductInformation prodInfo = m_interfaces.SystemSystemInfo.get_product_information(); if (null != prodInfo.product_code) { m_ci.setHostType(prodInfo.product_code); } // Check for GTM Support bool bGTMLicensed = false; for (int i = 0; i < prodInfo.product_features.Length; i++) { if (prodInfo.product_features[i].Equals("GTM Rules")) { bGTMLicensed = true; break; } } m_ci.setGTMLicensed(bGTMLicensed); //sysInfo.Dispose(); Cursor.Current = System.Windows.Forms.Cursors.Default; this.DialogResult = DialogResult.OK; // Update proxy info in connection info class if (UseProxyCheckBox.Checked) { m_ci.setWebProxy(ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPortTextBox.Text); } if (SaveConfigCheckBox.Checked) { m_ci.saveToRegistry(HostnameComboBox.Text); } if (UseProxyCheckBox.Checked) { m_ci.setWebProxy(ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPassTextBox.Text); } this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Net.WebException) { MessageBox.Show(this, "Connection could not be established to specified host", "Error"); } catch (System.UriFormatException) { MessageBox.Show(this, "Connection could not be established to specified host", "Error"); } } else { MessageBox.Show(this, "Invalid Connection Information...", "Error"); } //sysInfo.Dispose(); Cursor.Current = System.Windows.Forms.Cursors.Default; } }
private void OKLinkLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { if (0 == HostnameComboBox.Text.Length) { MessageBox.Show("Please enter a hostname.", "Missing information"); HostnameComboBox.Focus(); } else if (0 == PortTextBox.Text.Length) { MessageBox.Show("Please enter a port.", "Missing information"); PortTextBox.Text = "443"; PortTextBox.Focus(); } else if (0 == EndpointTextBox.Text.Length) { MessageBox.Show("Please enter a endpoint (default of /iControl/iControlPortal.cgi).", "Missing information"); EndpointTextBox.Text = "/iControl/iControlPortal.cgi"; EndpointTextBox.Focus(); } else if (0 == UsernameTextBox.Text.Length) { MessageBox.Show("Please enter a username.", "Missing information"); UsernameTextBox.Focus(); } else if (0 == PasswordTextBox.Text.Length) { MessageBox.Show("Please enter a password.", "Missing information"); PasswordTextBox.Focus(); } else if (UseProxyCheckBox.Checked && (ProxyAddressTextBox.Text.Length == 0)) { MessageBox.Show("If you are using a proxy server, please specify the address"); ProxyAddressTextBox.Focus(); } else if (UseProxyCheckBox.Checked && (ProxyPortTextBox.Text.Length == 0)) { MessageBox.Show("If you are using a proxy server, please specify the port"); ProxyPortTextBox.Focus(); } else { bool bInitialized = false; Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; m_ci.setEndpoint(HostnameComboBox.Text, Convert.ToInt32(PortTextBox.Text), EndpointTextBox.Text); m_ci.setCredentials(UsernameTextBox.Text, PasswordTextBox.Text); // Now verify if we can connect to the host if (null == m_interfaces) { m_interfaces = new iControl.Interfaces(); } if (UseProxyCheckBox.Checked) { bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text, ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPassTextBox.Text); } else { bInitialized = m_interfaces.initialize(HostnameComboBox.Text, Convert.ToUInt32(PortTextBox.Text), UsernameTextBox.Text, PasswordTextBox.Text); } if (bInitialized) { try { //sysInfo.Url = m_ci.buildURL(); iControl.SystemProductInformation prodInfo = m_interfaces.SystemSystemInfo.get_product_information(); if (null != prodInfo.product_code) { m_ci.setHostType(prodInfo.product_code); } // Check for GTM Support bool bGTMLicensed = false; for (int i = 0; i < prodInfo.product_features.Length; i++) { if (prodInfo.product_features[i].Equals("GTM Rules")) { bGTMLicensed = true; break; } } m_ci.setGTMLicensed(bGTMLicensed); //sysInfo.Dispose(); Cursor.Current = System.Windows.Forms.Cursors.Default; this.DialogResult = DialogResult.OK; // Update proxy info in connection info class if (UseProxyCheckBox.Checked) { m_ci.setWebProxy(ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPortTextBox.Text); } if (SaveConfigCheckBox.Checked) { m_ci.saveToRegistry(HostnameComboBox.Text); } if (UseProxyCheckBox.Checked) { m_ci.setWebProxy(ProxyAddressTextBox.Text, Convert.ToInt32(ProxyPortTextBox.Text), ProxyUserTextBox.Text, ProxyPassTextBox.Text); } this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Net.WebException) { MessageBox.Show(this, "Connection could not be established to specified host", "Error"); } catch (System.UriFormatException) { MessageBox.Show(this, "Connection could not be established to specified host", "Error"); } } else { MessageBox.Show(this, "Invalid Connection Information...", "Error"); } //sysInfo.Dispose(); Cursor.Current = System.Windows.Forms.Cursors.Default; } }
public iControlPSDriveInfo(PSDriveInfo driveInfo) : base(driveInfo) { _interfaces = new iControl.Interfaces(); }