Ejemplo n.º 1
0
        public override void Begin(ArgumentList args)
        {
            SourceUrl      = args.GetAfter("-source");
            TargetFile     = args.GetAfter("-target");
            ExistsBehavour = args.GetAfter("-existsbehaviour");

            switch (ExistsBehavour.ToLower())
            {
            case "skip":
                if (File.Exists(TargetFile))
                {
                    HasExited = true;
                    ExitCode  = 0;
                    return;
                }
                break;

            case "fail":
                if (File.Exists(TargetFile))
                {
                    HasExited = true;
                    ExitCode  = 1;
                    throw new SystemException("Target file exists.");
                }
                break;
            }
            HasExited = false;
            Action    = DownloadString;
            Action.BeginInvoke(SourceUrl, TargetFile, CompletedCallback, null);
        }
Ejemplo n.º 2
0
        private void DownloadStringDialog_Load(object sender, EventArgs e)
        {
            cboFileExistsBehaviour.Items.Add("Skip - do not download anything");
            cboFileExistsBehaviour.Items.Add("Overwrite the existing file");
            cboFileExistsBehaviour.Items.Add("Fail");
            cboFileExistsBehaviour.SelectedIndex = 0;

            var args = new ArgumentList(Arguments ?? "");

            if (args.Count <= 0)
            {
                return;
            }

            var deleteFileArguments = new DownloadStringArguments(args);

            txtSourceUrl.Text  = deleteFileArguments.SourceUrl;
            txtTargetFile.Text = deleteFileArguments.TargetFile;
            var existsBehaviour = args.GetAfter(DownloadStringArguments.ExistsBehaviour);

            cboFileExistsBehaviour.SelectedIndex = existsBehaviour.ToLower() switch
            {
                DownloadStringArguments.ExistsBehaviourOverwrite => 1,
                DownloadStringArguments.ExistsBehaviourFail => 2,
                _ => 0
            };
        }