I'm setting up a Scheduled Task where I was the user to supply their own credentials and I want the task to be
TaskLogonType.Password
But if the user cancels that dialog box after pressing ok on the Main TaskEditDialog, then a Null password exception bubbles out to the calling application.
I downloaded the source to investigate and saw a couple of small tweaks to be made, but I'm not sure about how to make them available.
In TaskEditDialog.CS
private DialogResults InvokeCredentialDialog(string userName)
{
CredentialsDialog dlg = new CredentialsDialog(EditorProperties.Resources.TaskSchedulerName,
EditorProperties.Resources.CredentialPromptMessage, userName);
dlg.Options |= CredentialsDialogOptions.Persist;
dlg.ValidatePassword = true;
DialogResults dr = new DialogResults();
dr.Result = dlg.ShowDialog(this.ParentForm);
if (dr.Result == DialogResult.OK)
{
dr.Password = dlg.Password;
}
else
{
dr.Password = null;
}
return dr;
}
private void okBtn_Click(object sender, System.EventArgs e)
{
if (this.TaskDefinition.Actions.Count == 0)
{
MessageBox.Show(EditorProperties.Resources.TaskMustHaveActionsError, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (this.TaskDefinition.Settings.DeleteExpiredTaskAfter != TimeSpan.Zero && !ValidateOneTriggerExpires())
{
MessageBox.Show(EditorProperties.Resources.Error_TaskDeleteMustHaveExpiringTrigger, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
bool okToSave = true;
if (RegisterTaskOnAccept)
{
if (this.Task != null)
this.Task.RegisterChanges();
else
{
string user = this.TaskDefinition.Principal.ToString();
string pwd = null;
TaskFolder fld = this.TaskService.GetFolder(this.TaskFolder);
if (this.TaskDefinition.Principal.LogonType == TaskLogonType.InteractiveTokenOrPassword || this.TaskDefinition.Principal.LogonType == TaskLogonType.Password)
{
if (InvokeCredentialDialog(user).Result == System.Windows.Forms.DialogResult.OK)
{
fld.RegisterTaskDefinition(this.taskPropertiesControl1.TaskName, this.TaskDefinition, TaskCreation.CreateOrUpdate,
user, pwd, this.TaskDefinition.Principal.LogonType);
}
else
{
okToSave = false;
}
}
}
}
if (okToSave)
{
this.DialogResult = DialogResult.OK;
Close();
}
}
and added this class
private class DialogResults
{
public DialogResult Result { get; set; }
public String Password { get; set; }
}
Comments:
TaskLogonType.Password
But if the user cancels that dialog box after pressing ok on the Main TaskEditDialog, then a Null password exception bubbles out to the calling application.
I downloaded the source to investigate and saw a couple of small tweaks to be made, but I'm not sure about how to make them available.
In TaskEditDialog.CS
private DialogResults InvokeCredentialDialog(string userName)
{
CredentialsDialog dlg = new CredentialsDialog(EditorProperties.Resources.TaskSchedulerName,
EditorProperties.Resources.CredentialPromptMessage, userName);
dlg.Options |= CredentialsDialogOptions.Persist;
dlg.ValidatePassword = true;
DialogResults dr = new DialogResults();
dr.Result = dlg.ShowDialog(this.ParentForm);
if (dr.Result == DialogResult.OK)
{
dr.Password = dlg.Password;
}
else
{
dr.Password = null;
}
return dr;
}
private void okBtn_Click(object sender, System.EventArgs e)
{
if (this.TaskDefinition.Actions.Count == 0)
{
MessageBox.Show(EditorProperties.Resources.TaskMustHaveActionsError, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (this.TaskDefinition.Settings.DeleteExpiredTaskAfter != TimeSpan.Zero && !ValidateOneTriggerExpires())
{
MessageBox.Show(EditorProperties.Resources.Error_TaskDeleteMustHaveExpiringTrigger, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
bool okToSave = true;
if (RegisterTaskOnAccept)
{
if (this.Task != null)
this.Task.RegisterChanges();
else
{
string user = this.TaskDefinition.Principal.ToString();
string pwd = null;
TaskFolder fld = this.TaskService.GetFolder(this.TaskFolder);
if (this.TaskDefinition.Principal.LogonType == TaskLogonType.InteractiveTokenOrPassword || this.TaskDefinition.Principal.LogonType == TaskLogonType.Password)
{
if (InvokeCredentialDialog(user).Result == System.Windows.Forms.DialogResult.OK)
{
fld.RegisterTaskDefinition(this.taskPropertiesControl1.TaskName, this.TaskDefinition, TaskCreation.CreateOrUpdate,
user, pwd, this.TaskDefinition.Principal.LogonType);
}
else
{
okToSave = false;
}
}
}
}
if (okToSave)
{
this.DialogResult = DialogResult.OK;
Close();
}
}
and added this class
private class DialogResults
{
public DialogResult Result { get; set; }
public String Password { get; set; }
}
Comments:
Fixed in 1.8.4