Ejemplo n.º 1
0
        private bool DeleteYoutubeVideo(string youtubeVideoCode)
        {
            String clientsecretkeypath = HttpContext.Current.Server.MapPath("~/client_secrets.json");
            var    cred           = GetUserCredential(clientsecretkeypath);
            var    youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = cred,
                ApplicationName       = Assembly.GetExecutingAssembly().GetName().Name
            });

            try
            {
                var parameters = new Dictionary <string, object>();
                parameters.Add("id", youtubeVideoCode);
                var videosDeleteRequest = youtubeService.Videos.Delete(parameters["id"].ToString());
                videosDeleteRequest.Execute();
            }
            catch (Exception ex)
            {
                CreateLog err = new CreateLog();
                CreateLog.CreateLogFiles();
                err.ErrorLog(Server.MapPath("/Logs/ErrorLog.txt"), ex.Message);
            }
            return(true);
        }
Ejemplo n.º 2
0
 protected void btnupload_Click(object sender, EventArgs e)
 {
     try
     {
         Upldmtrl.Visible = false;
         string fileext  = System.IO.Path.GetExtension(Upldmtrl.FileName).ToLower(); // stores extension of the uploaded file.
         string filename = Upldmtrl.FileName;                                        // store name of the uploade file in filename.
         filename         = filename.Remove(filename.Length - 4);
         Session["title"] = filename;
         Upldmtrl.SaveAs(Server.MapPath("/Upload/Videos/") + Upldmtrl.FileName);
         string filepath = Server.MapPath("/Upload/Videos/") + Upldmtrl.FileName;
         Session["file"] = filepath;
         UploadVideos(Upldmtrl.FileContent, Upldmtrl.PostedFile.ContentType, Upldmtrl.FileName, filepath);
         int    lessonid  = (int)Session["lessonid"];
         int    subjectid = (int)Session["subjectid"];
         int    classid   = (int)Session["classid"];
         string title     = Convert.ToString(Session["title"]);
         int    filesize  = Upldmtrl.PostedFile.ContentLength;
         if (Session["uploadcompleted"] != null)
         {
             string videoid = Session["videoid"].ToString();
             if (UserBL.VideoMaterial(2, classid, subjectid, lessonid, videoid, title))
             {
                 string FileToDelete = Convert.ToString(Session["file"]);
                 //Delete temporary video after uploading to youtube.
                 System.IO.File.Delete(FileToDelete);
                 Label lbl = new Label();
                 lbl.Text = Convert.ToString(Session["uploadcompleted"]);
                 fillVidgrid();
                 show = "upload";
                 Response.Redirect(Request.RawUrl, false);
             }
             else
             {
                 show = "failure";
                 Response.Redirect(Request.RawUrl);
             }
         }
     }
     catch (Exception ex)
     {
         CreateLog err = new CreateLog();
         CreateLog.CreateLogFiles();
         err.ErrorLog(Server.MapPath("/Logs/ErrorLog.txt"), ex.Message);
     }
     finally
     {
         lblclassname.Visible      = false;
         ddlClass.Visible          = false;
         lblSubject.Visible        = false;
         ddlsubject.Visible        = false;
         lblchapter.Visible        = false;
         ddllesson.Visible         = false;
         lblbrowseFile.Visible     = false;
         Upldmtrl.Visible          = false;
         btnupload.Visible         = false;
         lblVidDescription.Visible = false;
         txtVidDescription.Visible = false;
     }
 }
Ejemplo n.º 3
0
        void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
        {
            switch (progress.Status)
            {
            case UploadStatus.Uploading:
                lblprogress.Text    = "Status : Uploading... " + progress.BytesSent.ToString();
                Session["progress"] = progress.BytesSent.ToString();
                break;

            case UploadStatus.Failed:
                //  Response.Write(String.Format("{0}<br/>", progress.Exception.Message));
                //Response.Write(String.Format("{0}<br/>", progress.Exception.StackTrace));
                lbluploadfailed.Text = "Status : " + progress.Exception.Message.ToString();
                CreateLog err = new CreateLog();
                CreateLog.CreateLogFiles();
                err.ErrorLog(Server.MapPath("/Logs/ErrorLog.txt"), progress.Exception.Message.ToString());
                break;

            case UploadStatus.Completed:
                Session["uploadcompleted"] = UploadStatus.Completed;
                break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Author : Mir Bilal

        /// Remark : Event driven to store questions set for the examination ..
        /// </summary>
        protected void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                string    text      = Server.HtmlEncode(txtquestion.Text);
                DataTable dtpaperId = new DataTable();
                dtpaperId = UserBL.FetchObjectivePaperId(ddlclass.SelectedItem.Text, ddlsubject.SelectedItem.Text, ddlchapter.SelectedItem.Text);
                int       count   = Convert.ToInt32(dtpaperId.Rows.Count);
                int       paperid = Convert.ToInt32(dtpaperId.Rows[count - 1][0]);
                DataTable dtques  = new DataTable();
                dtques = UserBL.FetchQuestionId(paperid);      //  event driven to get qustion-id to check marks utilized for the questions-set...
                int questionid;
                int.TryParse(dtques.Rows[0][0].ToString(), out questionid);

                if (Session["image"] != null)
                {
                    string filename = Session["filename"].ToString();

                    if (UserBL.SetObjectiveQuestion("Q", text, txtanswer1.Text, txtanswer2.Text, txtanswer3.Text, txtanswer4.Text, txtanswerkey.Text, paperid, int.Parse(txtmarks.Text), "/Upload/QuestionPapers/" + filename))
                    {
                        txtquestion.Text = "";
                        //FreeTextBox1.Text = "";
                        //CKEditor1.Text = "";
                        txtmarks.Text       = "";
                        txtanswer1.Text     = "";
                        txtanswer2.Text     = "";
                        txtanswer3.Text     = "";
                        txtanswer4.Text     = "";
                        txtanswerkey.Text   = "";
                        lblmarks.Visible    = false;
                        txtmarks.Visible    = false;
                        txtquestion.Visible = false;

                        lnkhlp.Visible = false;
                        //FreeTextBox1.Visible = false;
                        //CKEditor1.Visible = false;
                        lblanswer1.Visible     = false;
                        txtanswer1.Visible     = false;
                        lblanswer2.Visible     = false;
                        txtanswer2.Visible     = false;
                        lblanswer3.Visible     = false;
                        txtanswer3.Visible     = false;
                        lblanswer4.Visible     = false;
                        txtanswer4.Visible     = false;
                        lblanswerkey.Visible   = false;
                        txtanswerkey.Visible   = false;
                        imgquest.Visible       = false;
                        imgquest.ImageUrl      = "";
                        upldQuest.Visible      = false;
                        btnQuestUpload.Visible = false;
                        lblmsgques.Text        = "Question saved successfully";
                    }
                }
                else
                {
                    if (UserBL.SetObjectiveQuestion("Q", text, txtanswer1.Text, txtanswer2.Text, txtanswer3.Text, txtanswer4.Text, txtanswerkey.Text, paperid, int.Parse(txtmarks.Text), null))
                    {
                        txtquestion.Text = "";
                        //FreeTextBox1.Text = "";
                        //CKEditor1.Text = "";
                        txtmarks.Text       = "";
                        txtanswer1.Text     = "";
                        txtanswer2.Text     = "";
                        txtanswer3.Text     = "";
                        txtanswer4.Text     = "";
                        txtanswerkey.Text   = "";
                        lblmarks.Visible    = false;
                        txtmarks.Visible    = false;
                        txtquestion.Visible = false;

                        lnkhlp.Visible = false;
                        //FreeTextBox1.Visible = false;
                        //CKEditor1.Visible = false;
                        lblanswer1.Visible     = false;
                        txtanswer1.Visible     = false;
                        lblanswer2.Visible     = false;
                        txtanswer2.Visible     = false;
                        lblanswer3.Visible     = false;
                        txtanswer3.Visible     = false;
                        lblanswer4.Visible     = false;
                        txtanswer4.Visible     = false;
                        lblanswerkey.Visible   = false;
                        txtanswerkey.Visible   = false;
                        imgquest.Visible       = false;
                        imgquest.ImageUrl      = "";
                        upldQuest.Visible      = false;
                        btnQuestUpload.Visible = false;
                        lblmsgques.Text        = "Question saved successfully";
                    }
                }

                fillgrid();
            }
            catch (Exception ex)
            {
                CreateLog.CreateLogFiles();
                CreateLog err = new CreateLog();
                err.ErrorLog(HttpContext.Current.Server.MapPath("/Logs/ErrorLog.txt"), ex.Message);
            }
        }
Ejemplo n.º 5
0
        private void UploadVideos(Stream uploadedStream, String contenttype, string filename, string path)
        {
            try
            {
                String clientsecretkeypath = HttpContext.Current.Server.MapPath("~/client_secrets.json");
                //  GoogleAuthorizationCodeFlow flow;
                ////  string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                ////  credPath = Path.Combine(credPath, ".credentials/", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
                //  var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");
                //  using (var stream = new FileStream(clientsecretkeypath, FileMode.Open, FileAccess.Read))
                //  {
                //      flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                //      {
                //          DataStore = new FileDataStore(folder),
                //          ClientSecretsStream = stream,
                //          Scopes = new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload }
                //      });
                //  }
                //  var uri = Request.Url.ToString();
                //  var code = Request["code"];
                //  string userId = "sidza";
                //  var youtubeService = new YouTubeService();
                //  if (code != null)
                //  {
                //      var token = flow.ExchangeCodeForTokenAsync(userId, code,
                //          uri.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result;

                //  //    Extract the right state.
                //      var oauthState = AuthWebUtility.ExtracRedirectFromState(
                //          flow.DataStore, userId, Request["state"]).Result;
                //      Response.Redirect(oauthState, false);
                //  }
                //  else
                //  {
                //      var result = new AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync(userId,
                //          CancellationToken.None).Result;
                //      if (result.RedirectUri != null)
                //      {
                //    //      Redirect the user to the authorization server.
                //         Response.Redirect(result.RedirectUri, false);
                //      }
                //      else
                //      {
                //      //    The data store contains the user credential, so the user has been already authenticated.
                //         youtubeService = new YouTubeService(new BaseClientService.Initializer()
                //         {
                //             HttpClientInitializer = result.Credential,
                //             ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
                //         });
                //      }
                //  }



                var cred = GetUserCredential(clientsecretkeypath);

                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = cred,
                    ApplicationName       = Assembly.GetExecutingAssembly().GetName().Name
                });

                youtubeService.HttpClient.Timeout = TimeSpan.FromMinutes(15.00);
                var video = new Google.Apis.YouTube.v3.Data.Video();
                video.Snippet             = new VideoSnippet();
                video.Snippet.Title       = Session["title"].ToString();
                video.Snippet.Description = txtVidDescription.Text;
                video.Snippet.Tags        = new string[] { "Autos" };
                //video.Snippet.CategoryId = "2";
                video.Status = new VideoStatus();
                video.Status.PrivacyStatus = "public";
                var       filePath         = path;
                const int KB               = 0x400;
                var       minimumChunkSize = 256 * KB;
                // tmr.Enabled = true;
                using (var fileStream = new FileStream(filePath, FileMode.Open))
                {
                    var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
                    videosInsertRequest.ProgressChanged  += videosInsertRequest_ProgressChanged;
                    videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
                    videosInsertRequest.ChunkSize         = minimumChunkSize * 8;
                    //await  videosInsertRequest.UploadAsync();
                    videosInsertRequest.Upload();
                }
            }
            catch (Exception ex)
            {
                CreateLog err = new CreateLog();
                CreateLog.CreateLogFiles();
                err.ErrorLog(Server.MapPath("/Logs/ErrorLog.txt"), ex.Message);
            }
            finally
            {
            }
        }
Ejemplo n.º 6
0
        protected void btnupload_Click(object sender, EventArgs e)
        {
            try
            {
                int classid = (int)Session["classid"];
                int typeid  = Int32.Parse(ddlTypeUpload.SelectedValue);
                Session["typeid"] = typeid;
                string fileext  = System.IO.Path.GetExtension(Upldmtrl.FileName).ToLower(); // stores extension of the uploaded file.
                string filename = Upldmtrl.FileName;                                        // store name of the uploade file in filename.
                if (ddlTypeUpload.SelectedItem.ToString() == "QUESTION PAPER")
                {
                    int subjectid = (int)Session["subjectid"];
                    ddlTypeUpload.ClearSelection();
                    Upldmtrl.SaveAs(Server.MapPath("/Upload/QuestionPapers/") + Upldmtrl.FileName);
                    string str      = Server.MapPath("/Upload/QuestionPapers/") + Upldmtrl.FileName;
                    int    filesize = Upldmtrl.PostedFile.ContentLength;
                    if (UserBL.QuestionPaperUpload(typeid, classid, subjectid, filesize, ("/Upload/QuestionPapers/") + filename))
                    {
                        fillQgrid();
                        show = "upload";
                        Response.Redirect(Request.RawUrl);
                    }
                    else
                    {
                        show = "failure";
                        Response.Redirect(Request.RawUrl);
                    }
                }

                else if (ddlTypeUpload.SelectedItem.ToString() == "SYLLABUS")
                {
                    int subjectid = (int)Session["subjectid"];
                    ddlTypeUpload.ClearSelection();
                    Upldmtrl.SaveAs(Server.MapPath("/Upload/Syllabus/") + Upldmtrl.FileName);
                    string str      = Server.MapPath("/Upload/Syllabus/") + Upldmtrl.FileName;
                    int    filesize = Upldmtrl.PostedFile.ContentLength;
                    if (UserBL.SyllabusUpload(typeid, classid, subjectid, filesize, ("/Upload/Syllabus/") + filename))
                    {
                        fillQgrid();
                        show = "upload";
                        Response.Redirect(Request.RawUrl);
                    }
                    else
                    {
                        show = "failure";
                        Response.Redirect(Request.RawUrl);
                    }
                }

                else if (ddlTypeUpload.SelectedItem.ToString() == "DOCUMENT")
                {
                    int lessonid  = (int)Session["lessonid"];
                    int subjectid = (int)Session["subjectid"];

                    Upldmtrl.SaveAs(Server.MapPath("/Upload/pdf/") + Upldmtrl.FileName);
                    string file = Server.MapPath("/Upload/pdf/") + Upldmtrl.FileName;
                    string f    = Upldmtrl.FileName;

                    Session["Docfile"] = file;
                    int filesize = Upldmtrl.PostedFile.ContentLength;

                    var    fname = Path.ChangeExtension(f, "html");
                    string path  = Server.MapPath("/Upload/pdf/") + fname;
                    Htmlconversion(file, path, fname);
                    // replaceinFile(path);

                    if (UserBL.Material(typeid, classid, subjectid, lessonid, filesize, ("/Upload/pdf/") + fname))
                    {
                        string FileToDelete = Session["Docfile"].ToString();
                        File.Delete(FileToDelete);
                        ddlTypeUpload.ClearSelection();
                        fillgrid();
                        show = "upload";
                        Response.Redirect(Request.RawUrl);
                    }
                    else
                    {
                        // lblmsg.Text = " Upload UnSucessful";
                        ddlTypeUpload.ClearSelection();
                        show = "failure";
                        Response.Redirect(Request.RawUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                CreateLog err = new CreateLog();
                CreateLog.CreateLogFiles();
                err.ErrorLog(Server.MapPath("/Logs/ErrorLog.txt"), ex.Message);
            }
            finally
            {
                ddlTypeUpload.ClearSelection();
                lblclassname.Visible  = false;
                ddlClass.Visible      = false;
                lblSubject.Visible    = false;
                ddlsubject.Visible    = false;
                lblchapter.Visible    = false;
                ddllesson.Visible     = false;
                lbltitle.Visible      = false;
                ddltitle.Visible      = false;
                lblbrowseFile.Visible = false;
                Upldmtrl.Visible      = false;
                btnupload.Visible     = false;
                lbltype.Visible       = false;
                ddlTypeUpload.Visible = false;
            }
        }
Ejemplo n.º 7
0
        private void Htmlconversion(string doc, string destination, string Title)
        {
            try
            {
                FileInfo fileInfo  = new FileInfo(doc);
                byte[]   byteArray = File.ReadAllBytes(fileInfo.FullName);
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    memoryStream.Write(byteArray, 0, byteArray.Length);
                    using (WordprocessingDocument wDoc = WordprocessingDocument.Open(memoryStream, true))
                    {
                        int imageCounter = 0;
                        //var pageTitle = fileInfo.FullName;
                        var pageTitle = Title;
                        var part      = wDoc.CoreFilePropertiesPart;
                        if (part != null)
                        {
                            pageTitle = (string)part.GetXDocument().Descendants(DC.title).FirstOrDefault() ?? Title;
                        }



                        WmlToHtmlConverterSettings settings = new WmlToHtmlConverterSettings()
                        {
                            AdditionalCss                       = "body { margin: 1cm auto; max-width: 20cm; padding: 0; }",
                            PageTitle                           = pageTitle,
                            FabricateCssClasses                 = true,
                            CssClassPrefix                      = "pt-",
                            RestrictToSupportedLanguages        = false,
                            RestrictToSupportedNumberingFormats = false,
                            ImageHandler                        = imageInfo =>
                            {
                                ++imageCounter;
                                string      extension   = imageInfo.ContentType.Split('/')[1].ToLower();
                                ImageFormat imageFormat = null;
                                if (extension == "png")
                                {
                                    imageFormat = ImageFormat.Png;
                                }
                                else if (extension == "gif")
                                {
                                    imageFormat = ImageFormat.Gif;
                                }
                                else if (extension == "bmp")
                                {
                                    imageFormat = ImageFormat.Bmp;
                                }
                                else if (extension == "jpeg")
                                {
                                    imageFormat = ImageFormat.Jpeg;
                                }
                                else if (extension == "tiff")
                                {
                                    extension   = "gif";
                                    imageFormat = ImageFormat.Gif;
                                }
                                else if (extension == "x-wmf")
                                {
                                    extension   = "wmf";
                                    imageFormat = ImageFormat.Wmf;
                                }

                                if (imageFormat == null)
                                {
                                    return(null);
                                }

                                string base64 = null;
                                try
                                {
                                    using (MemoryStream ms = new MemoryStream())
                                    {
                                        imageInfo.Bitmap.Save(ms, imageFormat);
                                        var ba = ms.ToArray();
                                        base64 = System.Convert.ToBase64String(ba);
                                    }
                                }
                                catch (Exception)
                                { }

                                ImageFormat    format = imageInfo.Bitmap.RawFormat;
                                ImageCodecInfo codec  = ImageCodecInfo.GetImageDecoders()
                                                        .First(c => c.FormatID == format.Guid);
                                string mimeType = codec.MimeType;

                                string imageSource =
                                    string.Format("data:{0};base64,{1}", mimeType, base64);

                                XElement img = new XElement(Xhtml.img,
                                                            new XAttribute(NoNamespace.src, imageSource),
                                                            imageInfo.ImgStyleAttribute,
                                                            imageInfo.AltText != null ?
                                                            new XAttribute(NoNamespace.alt, imageInfo.AltText) : null);
                                return(img);
                            }
                        };

                        XElement htmlElement = WmlToHtmlConverter.ConvertToHtml(wDoc, settings);
                        var      html        = new XDocument(new XDocumentType("html", null, null, null), htmlElement);
                        html.Save(destination, SaveOptions.DisableFormatting);
                    }
                }
            }
            catch (Exception ex)
            {
                CreateLog err = new CreateLog();
                CreateLog.CreateLogFiles();
                err.ErrorLog(Server.MapPath("/Logs/ErrorLog.txt"), ex.Source);
            }
        }