Exemple #1
0
        public static IExercise CreateObject(string code)
        {
            IExercise exercise = null;

            switch (code.ToUpper())
            {
            case "STRING":
                exercise = new ExerciseString();
                break;

            case "NULL":
                exercise = new ExerciseNull();
                break;

            case "COMMENT":
                exercise = new ExerciseComment();
                break;

            case "FILE":
                exercise = new ExerciseFile();
                break;

            case "ARRAY":
                exercise = new ExerciseArrays();
                break;

            case "TYPE_CONVERT":
                exercise = new ExerciseTypeConvert();
                break;

            case "LOOP":
                exercise = new ExerciseLoop();
                break;

            case "CONDITION":
                exercise = new ExerciseConditions();
                break;

            case "ENUM":
                exercise = new ExerciseEnum();
                break;

            case "BOXING":
                exercise = new ExerciseBoxingAndUnboxing();
                break;

            case "GC":
                exercise = new ExerciseGC();
                break;

            case "OVERLOAD":
                exercise = new ExerciseOverload();
                break;

            case "CONSTRUCTOR":
                exercise = new ExerciseConstructorAndFinalizer();
                break;

            case "COLLECTION":
                exercise = new ExerciseCollection();
                break;
            }

            return(exercise);
        }
 private static void DownloadExerciseFile(DirectoryInfo courseDirectory, ProgressBar pbarCourse, ExerciseFile exerciseFile)
 {
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
     using (pbarExerciseFiles = pbarCourse.Spawn(100, $"Downloading Video {currentIndex} : {currentVideo}", optionsVideo))
     {
         Retry.Do(() =>
         {
             using (var downloadClient = new WebClient())
             {
                 downloadClient.DownloadProgressChanged += ExerciseFileDownloadClient_DownloadProgressChanged;
                 downloadClient.DownloadFileCompleted   += ExerciseFileDownloadClient_DownloadFileCompleted;
                 currentExerciseFile = exerciseFile.FileName;
                 downloadClient.DownloadFileTaskAsync(new Uri(exerciseFile.DownloadUrl), Path.Combine(courseDirectory.FullName, exerciseFile.FileName)).Wait();
             }
         },
                  exceptionMessage: "Failed to download exerciseFile with name " + exerciseFile.FileName,
                  actionOnError: () =>
         {
             var progress = pbarExerciseFiles.AsProgress <float>();
             progress?.Report(0);
         });
     }
 }