public DocumentSharingEx(WebMeeting.Common.DocumentMessageType type,int session,string ServerIP,string ServerUsername,string ServerPassword,string meetingID)
 {
     m_DocumentType = type;
     sessionID = session;
     m_serverIP = ServerIP;
     m_username = ServerUsername;
     m_password = ServerPassword;
     m_meetingID = meetingID;
 }
        public DocumentSharingEx(WebMeeting.Common.DocumentMessageType type, int session, string ServerIP, string ServerUsername, string ServerPassword, string meetingID)

        {
            m_DocumentType = type;
            sessionID      = session;
            m_serverIP     = ServerIP;
            m_username     = ServerUsername;
            m_password     = ServerPassword;
            m_meetingID    = meetingID;
        }
 public DocumentSharingEx(WebMeeting.Common.DocumentMessageType type,int session)
 {
     m_DocumentType = type;
     sessionID = session;
 }
        public void StartDocumentSharingInitiaterManageContent(string strFileName,string strextension)
        {
            try
            {
                ScrollingThread = new Thread(new ThreadStart(scrollThreadFunction));
                ScrollingThread.Name = "StartDocumentSharingInitiater Thread: scrollThreadFunction()";
                ScrollingThread.Start();
                sendingThread = new Thread(new ThreadStart(threadFunction));
                sendingThread.Name="StartDocumentSharingInitiater Thread: sendingThread() ";
                sendingThread.Start();

                annotationBrowser.IsAttendee = false;
                annotationBrowser.OnMouseMoveEx +=new OnMouseMoveDelegate(annotationBrowser_OnMouseMoveEx);

                string Extension =this.strExtension;// Path.GetExtension(strFileName);
                Extension = Extension.ToLower();
                m_bIsAllowedToAddAnnotations = true;
                m_bOwnerofthisControl = true;
                if(Extension == ".doc" || Extension == ".docx")
                    documentType = DocumentMessageType.typeDocument;
                else if(Extension == ".xls" || Extension == ".xlsx")
                    documentType = DocumentMessageType.typeExcel;
                else if(Extension == ".ppt" ||Extension == ".pptx")
                {
                    documentType = DocumentMessageType.typePresentation;
                    this.panelAnnotations.Width=80;
                }
                else if(Extension == ".pdf")
                    documentType = DocumentMessageType.typePDF;

                switch(this.documentType)
                {
                    case DocumentMessageType.typeDocument:
                    {
                        SetDocumentAndPDFInterface();

                    }
                        break;
                    case DocumentMessageType.typePDF:
                        SetDocumentAndPDFInterface();
                        break;
                    case DocumentMessageType.typeExcel:
                    {
                        SetPresentationAndExcelInterface();
                        panelAnnotations.Visible = false;
                        nsButton1.Visible = false;
                        buttonDown.Visible = false;
                    }
                        break;
                    case DocumentMessageType.typePresentation:
                        SetPresentationAndExcelInterface();
                        this.panelAnnotations.Width=80;
                        break;
                }
                SetControls(false);
                m_bTerminated = false;
                IntializationCompleted = false;

                //DocumentFilePath = strFileName;		 // make file path here for manage COntant

                RecieveThread = new Thread(new ThreadStart(RecieveThreadFunction));
                RecieveThread.Name = "StartDocumentSharingInitiater Thread: RecieveThreadFunction()";
                RecieveThread.Start();
                //Thread uploadThread = new Thread(new ThreadStart(DocumentSharingThread));
                uploadThread = new Thread(new ThreadStart(DocumentSharingThread));
                uploadThread.Name = "StartDocumentSharingInitiater Thread: DocumentSharingThread()";
                uploadThread.Start();
            }
            catch (WebException exp)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("documentSharingControl.cs ==> StartDocumentSharingInitiaterManageContent( line==> 1961",exp,null,false);
                //MeetingAlerts alert=new MeetingAlerts();
                //alert.ShowMessage(Alerts.MeetingAlerts.AlertType.NonFatal,this.Name + " Class : StartDocumentSharingInitiater() function ," + ex.Source + " Source ," + ex.Message ,true,false);
            }
        }
        private void DocumentSharingThread()
        {
            //string strExt=".ppt";
            int no_of_RemoteFiles=8;
            string strPostRemoteUrl="";
            bool isRemoteUrlExist=false;
            string recordid="";
            MessageObject objMsg ;
            FileInfo theinfo;

            try
            {
                if(!this.IsLaunchFromMangeContent)
                {//in case false-----check manage content slideshow
                    //run when document is shared using menus.
                    //string Extension =strExt;//Path.GetExtension(DocumentFilePath);
                    string filename=Path.GetFileName(DocumentFilePath);
                    filenamed=Path.GetFileNameWithoutExtension(DocumentFilePath);
                    DocumentFilePath_temp=DocumentFilePath;
                    string Extension =Path.GetExtension(DocumentFilePath_temp);

                    theFile=new FileInfo(filename);

                    // 10 Mb Check
                    if((theFile.Length/1048576)>10)
                    {
                        MeetingAlerts alert=new MeetingAlerts();
                        alert.ShowMessage(Alerts.MeetingAlerts.AlertType.Info,"The size of this file is greater then 10Mb which may take time to Upload ",true,false);

                    }
                    //filenamed+=theFile.LastAccessTime.ToFileTime().ToString();

                    filenamed+=theFile.LastWriteTime.ToFileTime().ToString();
                    filenamed=filenamed.Replace('.','z');
                    filenamed=filenamed+Extension;
                    theFile.CopyTo(filenamed,true);
                    DocumentFilePath=Path.GetDirectoryName(DocumentFilePath)+@"\"+filenamed;
                    //DocumentFilePath=Path.GetFullPath(DocumentFilePath)+@"\"+filenamed;
                    Extension =Path.GetExtension(DocumentFilePath_temp);
                    //DocumentFilePath+=Extension
                    Extension = Extension.ToLower();

                    if(Extension == ".doc" ||Extension == ".docx")
                    {
                        documentType = DocumentMessageType.typeDocument;
                        strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+".htm";
                    }
                    else if(Extension == ".xls" ||Extension == ".xlsx")
                    {
                        documentType = DocumentMessageType.typeExcel;
                        if(no_of_RemoteFiles==1)
                            strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+".htm";
                        else
                            strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+"_files/sheet";
                    }
                    else if(Extension == ".ppt" || Extension == ".pptx")
                    {
                        documentType = DocumentMessageType.typePresentation;
                        // German PPT
                        //strPostRemoteUrl="/Folie";
                        strPostRemoteUrl="/slide";
                    }
                    else if(Extension == ".pdf")
                    {
                        documentType = DocumentMessageType.typePDF;
                        strPostRemoteUrl="/index.htm";
                    }

                    theinfo=new FileInfo(this.DocumentFilePath);
                    recordid=Client.ClientUI.getInstance().findRecord(Path.GetFileName(this.DocumentFilePath),theinfo.LastWriteTime.ToShortDateString().ToString());
                    if(recordid!="-1")
                        isRemoteUrlExist=true;
                    else
                    {
                        strLocalPath="";
                        isRemoteUrlExist=false;
                    }

                    //         Zaeem
                    if(isRemoteUrlExist==false)
                    {
                        DocumentSharingEx docEx = new WebMeeting.Client.DocumentSharingEx(
                            documentType,this.sessionID,Info.getInstance().FtpIP,Info.getInstance().UserName,
                            Info.getInstance().Password,Info.getInstance().ConferenceID);

                        docEx.OnStatusUpdateFunction = new WebMeeting.Client.DocumentSharingEx.OnStatusUpdate(OnStatusUpdate);
                        //MessageObject objMsg ;

                        //			docEx.DocumentShareStart(DocumentFilePath,out objMsg);

                        if(!docEx.DocumentShareStart(DocumentFilePath,out objMsg))
                        {
                            //Handle the failure;
                            MeetingAlerts alert=new MeetingAlerts();
                            alert.ShowMessage(Alerts.MeetingAlerts.AlertType.Info,"Unable to upload document to webserver",true,false);
                            return;
                        }
                        //						if(WebMeeting.Client.ClientUI.getInstance().InsertNewRecord(filename,((DocumentSharing)objMsg).DownloadURL,this.DocumentFilePath,((DocumentSharing)objMsg).TotalPages,((DocumentSharing)objMsg).DocumentType.ToString(),this.sessionID))
                        //							MessageBox.Show("Record Inserted");
                        //						else
                        //							MessageBox.Show("Record Not Inserted");
                        //
                        if(Extension == ".doc" ||Extension == ".docx")
                        {
                            documentType = DocumentMessageType.typeDocument;
                            strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+".htm";
                        }
                        else if(Extension == ".xls" || Extension == ".xlsx")
                        {
                            documentType = DocumentMessageType.typeExcel;

                            if(((DocumentSharing)objMsg).TotalPages==1)
                                //if()
                                strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+".htm";
                            else
                                strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+"_files/sheet";
                        }
                        else if(Extension == ".ppt" || Extension == ".pptx")
                        {
                            documentType = DocumentMessageType.typePresentation;
                            // German PPT
                            //strPostRemoteUrl="/Folie";
                            strPostRemoteUrl="/slide";
                        }
                        else if(Extension == ".pdf")
                        {
                            documentType = DocumentMessageType.typePDF;
                            strPostRemoteUrl="/index.htm";
                        }

                        IntializationCompleted = true;
                        //((DocumentSharing)objMsg).TotalPages=no_of_RemoteFiles;

                        ((DocumentSharing)objMsg).DownloadURL+=strPostRemoteUrl;
                        //MessageBox.Show("==>((DocumentSharing)objMsg).DownloadURL"+((DocumentSharing)objMsg).DownloadURL);
                        this.pictureCount = ((DocumentSharing)objMsg).TotalPages;
                        //theinfo=new FileInfo(this.DocumentFilePath);
                        Client.ClientUI.getInstance().InsertNewRecord(Path.GetFileName(DocumentFilePath),((DocumentSharing)objMsg).DownloadURL, Application.StartupPath +"\\" + this.sessionID.ToString()  ,((DocumentSharing)objMsg).TotalPages,((DocumentSharing)objMsg).DocumentType.ToString(),this.sessionID,theinfo.LastWriteTime.ToShortDateString().ToString());
                        theinfo=null;
                    }
                        ////////////               BY Zaeem                     ///////
                    else
                    {
                        DocumentSharing msg=new DocumentSharing();
                        objMsg=msg;
                        DataRow drShareMessage;
                        drShareMessage=Client.ClientUI.getInstance().getRecord(Convert.ToInt32(recordid));
                        string Extsion =Path.GetExtension(drShareMessage["FileName"].ToString());
                        this.strLocalPath=drShareMessage["LocalPath"].ToString();
                        if(Extsion == ".doc" ||Extsion == ".docx")
                        {
                            ((DocumentSharing)objMsg).DocumentType= DocumentMessageType.typeDocument;
                            //strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+".htm";
                        }
                        else if(Extsion == ".xls" || Extsion == ".xlsx")
                        {
                            ((DocumentSharing)objMsg).DocumentType= DocumentMessageType.typeExcel;
                            //							if(no_of_RemoteFiles==1)
                            //								strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+".htm";
                            //							else
                            //								strPostRemoteUrl="/"+Path.GetFileNameWithoutExtension(DocumentFilePath)+"_files/sheet";
                        }
                        else if(Extsion == ".ppt" || Extsion == ".pptx")
                        {
                            ((DocumentSharing)objMsg).DocumentType= DocumentMessageType.typePresentation;
                            //	strPostRemoteUrl="/slide";
                        }
                        else if(Extsion == ".pdf")
                        {
                            ((DocumentSharing)objMsg).DocumentType= DocumentMessageType.typePDF;
                            //	strPostRemoteUrl="/index.htm";
                        }
                        this.documentType=((DocumentSharing)objMsg).DocumentType;
                        //drShareMessage["LocalPath"]
                        ((DocumentSharing)objMsg).SenderID= NetworkManager.getInstance().profile.ClientId;
                        ((DocumentSharing)objMsg).ConferenceID=NetworkManager.getInstance().profile.ConferenceID;
                        ((DocumentSharing)objMsg).senderProfile=NetworkManager.getInstance().profile;
                        //((DocumentSharing)objMsg).ConferenceID=Info.getInstance().ConferenceID;
                        ((DocumentSharing)objMsg).sessionID=Convert.ToInt32(drShareMessage["Session"].ToString());
                        ((DocumentSharing)objMsg).DocumentSharingSessionId=Convert.ToInt32(drShareMessage["Session"].ToString());
                        ((DocumentSharing)objMsg).CurrentPage=1;
                        //						((DocumentSharing)objMsg).MessageType=
                        ((DocumentSharing)objMsg).nScrollX=0;
                        ((DocumentSharing)objMsg).nScrollY=0;
                        this.sessionID=	Convert.ToInt32(drShareMessage["Session"].ToString());
                        IntializationCompleted = true;
                        //drShareMessage["Session"]
                        ((DocumentSharing)objMsg).TotalPages=Convert.ToInt32(drShareMessage["TotalPages"]);
                        ((DocumentSharing)objMsg).DownloadURL=drShareMessage["RemoteURL"].ToString();

                        this.pictureCount = ((DocumentSharing)objMsg).TotalPages;
                        drShareMessage=null;
                    }

                    ProcessMessage(objMsg); //TODO:: optimized way is to add this mssg to poll and let thread do it
                    //but this causses file sharing error while same machine testing

                    //MessagePool.Add(objMsg);
                    NetworkManager.getInstance().SendMessage(objMsg);
                }//end if
                else
                {//start else
                    //runs when document sharing starts from manage content slideshow page

                    string Extension = this.strExtension;//Path.GetExtension(DocumentFilePath);
                    Extension = Extension.ToLower();

                    if(Extension == ".doc" || Extension == ".docx")
                        documentType = DocumentMessageType.typeDocument;
                    else if(Extension == ".xls" || Extension == ".xlsx")
                        documentType = DocumentMessageType.typeExcel;
                    else if(Extension == ".ppt" || Extension == ".pptx")
                        documentType = DocumentMessageType.typePresentation;
                    else if(Extension == ".pdf")
                        documentType = DocumentMessageType.typePDF;

                    //					DocumentSharingEx docEx = new WebMeeting.Client.DocumentSharingEx(
                    //						documentType,this.sessionID,Info.getInstance().FtpIP,Info.getInstance().UserName,
                    //						Info.getInstance().Password,Info.getInstance().ConferenceID);

                    //					docEx.OnStatusUpdateFunction = new WebMeeting.Client.DocumentSharingEx.OnStatusUpdate(OnStatusUpdate);
                    //					MessageObject objMsg ;

                    //			docEx.DocumentShareStart(DocumentFilePath,out objMsg);

                    NetworkManager networkMngr = NetworkManager.getInstance();
                    WebMeeting.Common.DocumentSharing message = new WebMeeting.Common.DocumentSharing();
                    message.SenderID = networkMngr.profile.ClientId;
                    message.senderProfile = networkMngr.profile;
                    message.sessionID = this.sessionID;
                    message.DocumentSharingSessionId = this.sessionID;
                    message.DownloadURL = "Already Downloaded," + this.strRemoteUrl;
                    message.DocumentType = documentType;
                    message.CurrentPage=1;
                    message.TotalPages=this.no_of_pages;

                    /*if(!docEx.DocumentShareStart(DocumentFilePath,out objMsg))
                    {
                        //Handle the failure;
                        MeetingAlerts alert=new MeetingAlerts();
                        alert.ShowMessage(Alerts.MeetingAlerts.AlertType.Info,"Unable to upload document to webserver",true,false);
                        return;
                    }*/

                    IntializationCompleted = true;
                    //this.pictureCount = ((DocumentSharing)objMsg).TotalPages; //  by junaid for now
                    this.m_DocumentDownloaded=true;
                    this.ProcessMessageManageContent(message); //TODO:: optimized way is to add this mssg to poll and let thread do it
                    //but this causses file sharing error while same machine testing
                    this.m_DocumentMessage=	message;
                    message.DownloadURL="Already Downloaded," + message.DownloadURL;
                    //MessagePool.Add(objMsg);
                    NetworkManager.getInstance().SendMessage(message);
                }//end else

            }
            catch (WebException err)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("documentSharingControl.cs ==> DocumentSharingThread() line==> 1773",err,null,false);
                //MeetingAlerts alert=new MeetingAlerts();
                //alert.ShowMessage(Alerts.MeetingAlerts.AlertType.NonFatal,this.Name + " Class : DocumentSharingThread() function ," + ex.Source + " Source ," + ex.Message ,true,false);
            }

            finally
            {
                try
                {
                    theFile=new FileInfo(filenamed);
                    theFile.Delete();
                }
                catch(Exception exp){}
            }
        }
 public DocumentSharingEx(WebMeeting.Common.DocumentMessageType type, int session)
 {
     m_DocumentType = type;
     sessionID      = session;
 }