Exemplo n.º 1
0
        public string ImportQuizDocument(QuizDocument doc)
        {
            Logger.Log("Importing Document {0} ...", doc.Name);

            Dictionary<string, object> properties = SerializeDoc(doc);
            StringBuilder builder = new StringBuilder();
            BuildData(builder, "presentation", properties);
            string docId = ExecuteImport(builder.ToString());

            Logger.Log("Document Imported with docId: {0}", docId);

            return docId;
        }
Exemplo n.º 2
0
        public void BulkImportQuizSlides(string docId, QuizDocument doc)
        {
            StringBuilder builder = new StringBuilder();

            foreach(var slide in doc.Slides)
            {
                Logger.Log("Import Slide {0} of document {1}", slide.SlideIndex, docId);
                Dictionary<string, object> properties = SerializeSlide(docId, slide);
                BuildData(builder, "slide", properties);
                builder.Append("&");
            }
            string slideResult = ExecuteImport(builder.ToString());
            Logger.Log(slideResult);
        }
Exemplo n.º 3
0
        public static QuizDocument Parse(string filePath)
        {
            QuizDocument doc = new QuizDocument();
            PPT.Application pptApp = new PPT.Application();
            PPT.Presentation ppt = pptApp.Presentations.Open(filePath);
            Directory.Delete(IMAGE_TEMP_PATH, true);
            ppt.SaveCopyAs(IMAGE_TEMP_PATH, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG);
            doc.ExtractDetails(filePath);

            foreach (PPT.Slide pptSlide in ppt.Slides)
            {
                QuizSlide docSlide = QuizSlide.Parse(pptSlide, IMAGE_TEMP_PATH);
                docSlide.QuizDoc = doc;
                doc.Slides.Add(docSlide);
                ImageHelper.ResaveImage(docSlide.ImagePath, 0.5m, IMAGE_RESIZED_TEMP_PATH);
                docSlide.ImagePath = docSlide.ImagePath.Replace(IMAGE_TEMP_PATH, IMAGE_RESIZED_TEMP_PATH);
            }
            ppt.Close();
            pptApp.Quit();

            return doc;
        }
Exemplo n.º 4
0
        public void UploadQuiz(QuizDocument doc, bool useAsync = false)
        {
            var credential = GetCredentials();
            StorageService service = new StorageService(
                new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Quiz Plus Uploader",
                });

            foreach(var slide in doc.Slides)
            {
                var fileobj = new GSD.Object() { Name = slide.CanonicalName };
                var uploadStream = new FileStream(slide.ImagePath, FileMode.Open, FileAccess.Read);
                var uploadRequest = service.Objects.Insert(
                    fileobj,
                    BUCKET_NAME,
                    uploadStream,
                    "image/jpeg");

                if (useAsync)
                {
                    var task = uploadRequest.UploadAsync();
                    task.ContinueWith(t =>
                    {
                        // Remeber to clean the stream.
                        Logger.Log("Uploaded image " + slide.ImagePath);
                        uploadStream.Dispose();
                    });
                }
                else
                {
                    uploadRequest.Upload();
                    Logger.Log("Uploaded image " + slide.ImagePath);
                    uploadStream.Dispose();
                }
            }
        }
Exemplo n.º 5
0
 private Dictionary<string, object> SerializeDoc(QuizDocument doc)
 {
     Dictionary<string, object> properties = new Dictionary<string, object>();
     properties.Add("Name", doc.Name);
     properties.Add("Date", doc.Date.ToShortDateString());
     properties.Add("Author", doc.Author);
     properties.Add("SlideCount", doc.Slides.Count);
     return properties;
 }