private void cancelBtn_Click(object sender, EventArgs e)
 {
     m_cmgr.DownloadFilesCancelAsync();
     cancelBtn.Enabled        = false;
     asyncCheckoutBtn.Enabled = false;
     syncCheckoutBtn.Enabled  = true;
     this.m_status            = CheckoutManagerState.idle;
 }
        private void asyncCheckoutBtn_Click(object sender, EventArgs e)
        {
            textBoxResult.Clear();

            if (this.m_status == CheckoutManagerState.idle)
            {
                string files = GetFiles();

                // Create configuration
                Item configuration = m_inn.newItem();
                configuration.loadAML(files);

                // Create Aras.IOME.CheckoutManager
                m_cmgr = new CheckoutManager(configuration);

                // Lock all items in the configuration (!File, !Vault, !Located)
                Item lockResult = m_cmgr.Lock();

                if (lockResult.isError())
                {
                    MessageBox.Show(lockResult.getErrorString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int    numberOfThreads = (int)thCount.Value;
                string targetFolder    = textBoxDestination.Text;

                // Event handlers are attached to Aras.IOME.CheckoutManager events.
                m_cmgr.DownloadFileCompleted        += new Aras.IOME.DownloadFileCompletedEventHandler(HandleDownloadFileCompleted);
                m_cmgr.DownloadFilesCompleted       += new Aras.IOME.DownloadFilesCompletedEventHandler(HandleDownloadFilesCompleted);
                m_cmgr.DownloadFilesProgressChanged += new Aras.IOME.DownloadFilesProgressChangedEventHandler(HandleDownloadFileProgressChanged);

                this.m_failed_count = 0;
                progressBar.Value   = 0;

                // Begin download files asynchronously
                m_cmgr.DownloadFilesAsync(targetFolder, numberOfThreads);

                // Toggle button state
                cancelBtn.Enabled     = true;
                asyncCheckoutBtn.Text = "Pause";
                this.m_status         = CheckoutManagerState.running;
            }
            else if (this.m_status == CheckoutManagerState.running)
            {
                m_cmgr.DownloadFilesPauseAsync();
                cancelBtn.Enabled     = false;
                asyncCheckoutBtn.Text = "Resume";
                this.m_status         = CheckoutManagerState.paused;
            }
            else if (this.m_status == CheckoutManagerState.paused)
            {
                m_cmgr.DownloadFilesResumeAsync();
                cancelBtn.Enabled     = true;
                asyncCheckoutBtn.Text = "Pause";
                this.m_status         = CheckoutManagerState.running;
            }
        }
        /// <summary>
        /// Handle syncCheckout
        /// </summary>
        private void HandleDownloadFilesCompleted(object sender, DownloadFilesCompletedEventArgs e)
        {
            // Toggle button state
            cancelBtn.Enabled     = false;
            asyncCheckoutBtn.Text = "Async Download";
            this.m_status         = CheckoutManagerState.idle;

            // If download was cancelled then e->Cancelled is true
            if (e.Cancelled)
            {
                progressBar.Value = 0;
                MessageBox.Show("Cancelled.", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // If general Exception(which is not related to File) happenned during download
            if (e.Error != null)
            {
                string error = "DownloadFilesProgressChanged: " + e.Error.ToString();
                MessageBox.Show(error, "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void SetInitialState()
        {
            textBoxURL.Text         = _url;
            cmbDatabase.Text        = _db;
            textBoxLogin.Text       = _user;
            textBoxPassword.Text    = _password;
            textBoxDestination.Text = _destination;
            textBoxItemID.Text      = _itemID;
            thCount.Value           = _threads;

            cmbResolution.DataSource    = structureResolution;
            cmbResolution.DisplayMember = "Name";
            cmbResolution.ValueMember   = "Name";

            cmbQueryAction.DataSource    = quaryAction;
            cmbQueryAction.DisplayMember = "Name";
            cmbQueryAction.ValueMember   = "Name";

            cmbSearchType.DataSource    = searchType;
            cmbSearchType.DisplayMember = "Name";
            cmbSearchType.ValueMember   = "Name";

            loginBtn.Enabled         = true;
            syncCheckoutBtn.Enabled  = false;
            cancelBtn.Enabled        = false;
            asyncCheckoutBtn.Enabled = false;
            sfLbl.Visible            = false;
            btnRunSearch.Enabled     = false;

            progressBar.Visible = true;
            progressBar.Minimum = 0;
            progressBar.Maximum = 100;

            m_status       = CheckoutManagerState.idle;
            m_failed_count = 0;
        }
        private void SetInitialState()
        {
            textBoxURL.Text = _url;
            cmbDatabase.Text = _db;
            textBoxLogin.Text = _user;
            textBoxPassword.Text = _password;
            textBoxDestination.Text = _destination;
            textBoxItemID.Text = _itemID;
            thCount.Value = _threads;

            cmbResolution.DataSource = structureResolution;
            cmbResolution.DisplayMember = "Name";
            cmbResolution.ValueMember = "Name";

            cmbQueryAction.DataSource = quaryAction;
            cmbQueryAction.DisplayMember = "Name";
            cmbQueryAction.ValueMember = "Name";

            cmbSearchType.DataSource = searchType;
            cmbSearchType.DisplayMember = "Name";
            cmbSearchType.ValueMember = "Name";

            loginBtn.Enabled = true;
            syncCheckoutBtn.Enabled = false;
            cancelBtn.Enabled = false;
            asyncCheckoutBtn.Enabled = false;
            sfLbl.Visible = false;
            btnRunSearch.Enabled = false;

            progressBar.Visible = true;
            progressBar.Minimum = 0;
            progressBar.Maximum = 100;

            m_status = CheckoutManagerState.idle;
            m_failed_count = 0;
        }
        /// <summary>
        /// Handle syncCheckout
        /// </summary>
        private void HandleDownloadFilesCompleted(object sender, DownloadFilesCompletedEventArgs e)
        {
            // Toggle button state
            cancelBtn.Enabled = false;
            asyncCheckoutBtn.Text = "Async Download";
            this.m_status = CheckoutManagerState.idle;

            // If download was cancelled then e->Cancelled is true
            if (e.Cancelled)
            {
                progressBar.Value = 0;
                MessageBox.Show("Cancelled.", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // If general Exception(which is not related to File) happenned during download
            if (e.Error != null)
            {
                string error = "DownloadFilesProgressChanged: " + e.Error.ToString();
                MessageBox.Show(error, "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void cancelBtn_Click(object sender, EventArgs e)
 {
     m_cmgr.DownloadFilesCancelAsync();
     cancelBtn.Enabled = false;
     asyncCheckoutBtn.Enabled = false;
     syncCheckoutBtn.Enabled = true;
     this.m_status = CheckoutManagerState.idle;
 }
        private void asyncCheckoutBtn_Click(object sender, EventArgs e)
        {
            textBoxResult.Clear();

            if (this.m_status == CheckoutManagerState.idle)
            {
                string files = GetFiles();

                // Create configuration
                Item configuration = m_inn.newItem();
                configuration.loadAML(files);

                // Create Aras.IOME.CheckoutManager
                m_cmgr = new CheckoutManager(configuration);

                // Lock all items in the configuration (!File, !Vault, !Located)
                Item lockResult = m_cmgr.Lock();

                if (lockResult.isError())
                {
                    MessageBox.Show(lockResult.getErrorString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int numberOfThreads = (int)thCount.Value;
                string targetFolder = textBoxDestination.Text;

                // Event handlers are attached to Aras.IOME.CheckoutManager events.
                m_cmgr.DownloadFileCompleted += new Aras.IOME.DownloadFileCompletedEventHandler(HandleDownloadFileCompleted);
                m_cmgr.DownloadFilesCompleted += new Aras.IOME.DownloadFilesCompletedEventHandler(HandleDownloadFilesCompleted);
                m_cmgr.DownloadFilesProgressChanged += new Aras.IOME.DownloadFilesProgressChangedEventHandler(HandleDownloadFileProgressChanged);

                this.m_failed_count = 0;
                progressBar.Value = 0;

                // Begin download files asynchronously
                m_cmgr.DownloadFilesAsync(targetFolder, numberOfThreads);

                // Toggle button state
                cancelBtn.Enabled = true;
                asyncCheckoutBtn.Text = "Pause";
                this.m_status = CheckoutManagerState.running;
            }
            else if (this.m_status == CheckoutManagerState.running)
            {
                m_cmgr.DownloadFilesPauseAsync();
                cancelBtn.Enabled = false;
                asyncCheckoutBtn.Text = "Resume";
                this.m_status = CheckoutManagerState.paused;
            }
            else if (this.m_status == CheckoutManagerState.paused)
            {
                m_cmgr.DownloadFilesResumeAsync();
                cancelBtn.Enabled = true;
                asyncCheckoutBtn.Text = "Pause";
                this.m_status = CheckoutManagerState.running;
            }
        }