private void btnFinish_Click(object sender, System.EventArgs e)
        {
            try
            {
                foreach (DataRowView row in dataView1)
                {
                    string key = row.Row.ItemArray[0].ToString();
                    string value = row.Row.ItemArray[1].ToString();
                    if (!String.IsNullOrEmpty(key) &&
                        !String.IsNullOrEmpty(value))
                    {
                        ResourceFile resFile = new ResourceFile();
                        resFile.FilePath = key;
                        resFile.BlobSource = value;                        

                        resourceFiles.Add(resFile);
                    }
                }

                if (resourceFiles != null &&
                    resourceFiles.Count > 0)
                {
                    if (task != null)
                    {
                        task.ResourceFiles = resourceFiles.ToArray();
                    }
                    else if (pool != null)
                    {
                        pool.StartTask.ResourceFiles = resourceFiles.ToArray();
                    }
                    else if (workitem != null && code.Equals("1"))
                    {
                        workitem.JobSpecification.JobManager.ResourceFiles =
                            resourceFiles.ToArray();
                    }
                    else if (workitem != null && code.Equals("2"))
                    {
                        workitem.JobExecutionEnvironment.AutoPoolSpecification.Pool.
                            StartTask.ResourceFiles = resourceFiles.ToArray();
                    }
                    else if (starttask != null)
                    {
                        starttask.ResourceFiles = resourceFiles.ToArray();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("FilesEnv resource files:\n{0}", ex));
            }

            try
            {
                List<EnvironmentSetting> envSettings = new List<EnvironmentSetting>();
                foreach (DataRowView row in dataView2)
                {
                    string key = row.Row.ItemArray[0].ToString();
                    string value = row.Row.ItemArray[1].ToString();
                    if (!String.IsNullOrEmpty(key) &&
                        !String.IsNullOrEmpty(value))
                    {
                        EnvironmentSetting setting = new EnvironmentSetting();
                        setting.Name = key;
                        setting.Value = value;
                        envSettings.Add(setting);
                    }
                }
                if (envSettings.Count > 0)
                {
                    if (task != null)
                    {
                        task.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (pool != null)
                    {
                        pool.StartTask.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (workitem != null && code.Equals("1"))
                    {
                        workitem.JobSpecification.JobManager.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (workitem != null && code.Equals("2"))
                    {
                        workitem.JobExecutionEnvironment.AutoPoolSpecification.Pool.
                            StartTask.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (starttask != null)
                    {
                        starttask.EnvironmentSettings = envSettings.ToArray();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("FilesEnv envSettings:\n{0}", ex));
            }

            try
            {
                if (task != null)
                {
                    (Sender as BatchTreeViewItem).AddTask(task, TaskName);
                    (this.Parent as NavigationWindow).Close();
                }
                else if (pool != null)
                {
                    (Sender as BatchTreeViewItem).AddPool(pool, pool.Name);
                    (this.Parent as NavigationWindow).Close();
                }
                else if (workitem != null && code.Equals("1"))
                {
                    CreateWIP5 p5 = new CreateWIP5(this.Sender, workitem);
                    NavigationService.Navigate(p5);
                }
                else if (workitem != null && code.Equals("2"))
                {
                    (Sender as BatchTreeViewItem).AddWorkItem(workitem);
                    (this.Parent as NavigationWindow).Close();
                }
                else if (starttask != null)
                {
                    //TODO::Certificates and metadata
                    ((Sender as BatchTreeViewItem).Item as PoolViewModel).UpdatePool(starttask, null, null);
                    (this.Parent as NavigationWindow).Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Utils.ExtractExceptionMessage(ex));
            }
        }        
        private void btnNext_Click(object sender, System.EventArgs e)
        {
            workitem.JobSpecification = new JobSpecification();

            try
            {
                if (txtRetry.Text != "")
                {
                    workitem.JobSpecification.Priority = int.Parse(txtPriority.Text);
                }
                else
                {
                    workitem.JobSpecification.Priority = 0;
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(string.Format(
                                                   "{0} Caught", ex));
            }

            workitem.JobSpecification.JobConstraints = new JobConstraints();

            try
            {
                if (txtRetry.Text != "")
                {
                    workitem.JobSpecification.JobConstraints.MaxTaskRetryCount = int.Parse(txtRetry.Text);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(string.Format(
                                                   "Max Task Retry Count:\n{0}", ex));
            }

            try
            {
                if (Time.CanParse(dataTableWallClock))
                {
                    TimeSpan span = Time.ParseTimeSpan(dataTableWallClock);
                    workitem.JobSpecification.JobConstraints.MaxWallClockTime = span;
                }
                else
                {
                    workitem.JobSpecification.JobConstraints.MaxWallClockTime = null;
                }
            }
            catch (Exception) { }

            if (chkJobManager.IsChecked == true)
            {
                CreateWIP3 p3 = new CreateWIP3(Sender, workitem);
                NavigationService.Navigate(p3);
            }
            else
            {
                CreateWIP5 p5 = new CreateWIP5(Sender, workitem);
                NavigationService.Navigate(p5);
            }
        }
        private void btnFinish_Click(object sender, System.EventArgs e)
        {
            try
            {
                foreach (DataRowView row in dataView1)
                {
                    string key   = row.Row.ItemArray[0].ToString();
                    string value = row.Row.ItemArray[1].ToString();
                    if (!String.IsNullOrEmpty(key) &&
                        !String.IsNullOrEmpty(value))
                    {
                        ResourceFile resFile = new ResourceFile();
                        resFile.FilePath   = key;
                        resFile.BlobSource = value;

                        resourceFiles.Add(resFile);
                    }
                }

                if (resourceFiles != null &&
                    resourceFiles.Count > 0)
                {
                    if (task != null)
                    {
                        task.ResourceFiles = resourceFiles.ToArray();
                    }
                    else if (pool != null)
                    {
                        pool.StartTask.ResourceFiles = resourceFiles.ToArray();
                    }
                    else if (workitem != null && code.Equals("1"))
                    {
                        workitem.JobSpecification.JobManager.ResourceFiles =
                            resourceFiles.ToArray();
                    }
                    else if (workitem != null && code.Equals("2"))
                    {
                        workitem.JobExecutionEnvironment.AutoPoolSpecification.Pool.
                        StartTask.ResourceFiles = resourceFiles.ToArray();
                    }
                    else if (starttask != null)
                    {
                        starttask.ResourceFiles = resourceFiles.ToArray();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("FilesEnv resource files:\n{0}", ex));
            }

            try
            {
                List <EnvironmentSetting> envSettings = new List <EnvironmentSetting>();
                foreach (DataRowView row in dataView2)
                {
                    string key   = row.Row.ItemArray[0].ToString();
                    string value = row.Row.ItemArray[1].ToString();
                    if (!String.IsNullOrEmpty(key) &&
                        !String.IsNullOrEmpty(value))
                    {
                        EnvironmentSetting setting = new EnvironmentSetting();
                        setting.Name  = key;
                        setting.Value = value;
                        envSettings.Add(setting);
                    }
                }
                if (envSettings.Count > 0)
                {
                    if (task != null)
                    {
                        task.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (pool != null)
                    {
                        pool.StartTask.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (workitem != null && code.Equals("1"))
                    {
                        workitem.JobSpecification.JobManager.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (workitem != null && code.Equals("2"))
                    {
                        workitem.JobExecutionEnvironment.AutoPoolSpecification.Pool.
                        StartTask.EnvironmentSettings = envSettings.ToArray();
                    }
                    else if (starttask != null)
                    {
                        starttask.EnvironmentSettings = envSettings.ToArray();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("FilesEnv envSettings:\n{0}", ex));
            }

            try
            {
                if (task != null)
                {
                    (Sender as BatchTreeViewItem).AddTask(task, TaskName);
                    (this.Parent as NavigationWindow).Close();
                }
                else if (pool != null)
                {
                    (Sender as BatchTreeViewItem).AddPool(pool, pool.Name);
                    (this.Parent as NavigationWindow).Close();
                }
                else if (workitem != null && code.Equals("1"))
                {
                    CreateWIP5 p5 = new CreateWIP5(this.Sender, workitem);
                    NavigationService.Navigate(p5);
                }
                else if (workitem != null && code.Equals("2"))
                {
                    (Sender as BatchTreeViewItem).AddWorkItem(workitem);
                    (this.Parent as NavigationWindow).Close();
                }
                else if (starttask != null)
                {
                    //TODO::Certificates and metadata
                    ((Sender as BatchTreeViewItem).Item as PoolViewModel).UpdatePool(starttask, null, null);
                    (this.Parent as NavigationWindow).Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Utils.ExtractExceptionMessage(ex));
            }
        }
        private void btnNext_Click(object sender, System.EventArgs e)
        {
            workitem.JobSpecification = new JobSpecification();

            try
            {
                if (txtRetry.Text != "")
                {
                    workitem.JobSpecification.Priority = int.Parse(txtPriority.Text);
                }
                else
                {
                    workitem.JobSpecification.Priority = 0;
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(string.Format(
                    "{0} Caught", ex));
            }

            workitem.JobSpecification.JobConstraints = new JobConstraints();

            try
            {
                if (txtRetry.Text != "")
                {
                    workitem.JobSpecification.JobConstraints.MaxTaskRetryCount = int.Parse(txtRetry.Text);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(string.Format(
                    "Max Task Retry Count:\n{0}", ex));
            }

            try
            {
                if (Time.CanParse(dataTableWallClock))
                {
                    TimeSpan span = Time.ParseTimeSpan(dataTableWallClock);
                    workitem.JobSpecification.JobConstraints.MaxWallClockTime = span;
                }
                else
                {
                    workitem.JobSpecification.JobConstraints.MaxWallClockTime = null;
                }
            }
            catch (Exception) { }

            if (chkJobManager.IsChecked == true)
            {
                CreateWIP3 p3 = new CreateWIP3(Sender, workitem);
                NavigationService.Navigate(p3);
            }
            else
            {
                CreateWIP5 p5 = new CreateWIP5(Sender, workitem);
                NavigationService.Navigate(p5);
            }
        }