private DirectoryInfo SetUpVideoFolderStructure(string courseTitle, string moduleTitle, CourseSimpleClip clip)
 {
     return(Directory.CreateDirectory(GetVideoFolderStructure(courseTitle, moduleTitle, clip)));
 }
        private async void SaveCourseInformation(CourseSimpleClip clip)
        {
            String courseName = clip.ID.Substring(0, clip.ID.IndexOf("|"));
            Course course     = null;

            courses.TryGetValue(courseName, out course);
            if (course == null)
            {
                return;
            }
            var descriptionFile = GetBaseFolderStructure(course.Title) + "\\description.txt";
            var levelFile       = GetBaseFolderStructure(course.Title) + "\\level.txt";
            var authorsFile     = GetBaseFolderStructure(course.Title) + "\\authors.txt";
            var dateFile        = GetBaseFolderStructure(course.Title) + "\\date.txt";
            var excerciceFile   = GetBaseFolderStructure(course.Title) + "\\" + course.Title.ToValidFileName() + "-excercice.zip";

            if (!File.Exists(descriptionFile))
            {
                File.WriteAllText(descriptionFile, course.Description);
            }
            if (!File.Exists(levelFile))
            {
                File.WriteAllText(levelFile, course.Level);
            }
            if (!File.Exists(dateFile))
            {
                File.WriteAllText(dateFile, DateTime.Parse(course.ReleaseDate).ToString("dd/MM/yyyy"));
            }
            if (!File.Exists(authorsFile))
            {
                String separator = "";
                String authors   = "";
                foreach (Author author in course.Authors)
                {
                    authors   = separator + author.FirstName + " " + author.LastName;
                    separator = ", ";
                }
                File.WriteAllText(authorsFile, String.Join(", ", authors));
            }
            if (!File.Exists(excerciceFile))
            {
                if (course.ExerciseFiles != null)
                {
                    try
                    {
                        using (var client = new WebClient())
                            using (var regStream = await client.OpenReadTaskAsync(course.ExerciseFiles.exerciseFilesUrl))
                                using (var stream = new ThrottledStream(regStream, 115200))
                                {
                                    byte[] buffer = new byte[1024];

                                    using (var fileStream = File.OpenWrite(excerciceFile))
                                    {
                                        for (;;)
                                        {
                                            int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);

                                            if (bytesRead == 0)
                                            {
                                                await Task.Yield();

                                                break;
                                            }

                                            fileStream.Write(buffer, 0, bytesRead);
                                        }
                                    }
                                }
                    } catch
                    {
                    }
                }
            }
        }
 private string GetVideoFolderStructure(string courseTitle, string moduleTitle, CourseSimpleClip clip)
 {
     return(GetBaseFolderStructure(courseTitle) + "\\" + (clip.ModuleIndex + 1).ToString("D2") + " - " + moduleTitle.ToValidFileName());
 }
        // ToDo: videos location should be configurable from client.
        private string GetVideoFolderStructure(string courseTitle, string moduleTitle, CourseSimpleClip clip)
        {
            Directory.CreateDirectory(Constants.DOWNLOAD_FOLDER_PATH);
            Directory.CreateDirectory(Constants.DOWNLOAD_FOLDER_PATH + "\\" + courseTitle.ToValidFileName());

            return(Constants.DOWNLOAD_FOLDER_PATH + "\\" + courseTitle.ToValidFileName() + "\\" + (clip.ModuleIndex + 1).ToString("D2") + " - " + moduleTitle.ToValidFileName());
        }