Exemplo n.º 1
0
        /// <summary>
        //*** Bind DropBox Data Grid
        /// </summary>
        /// <param name="FolderPath">Folder Path in Array Format</param>
        /// <returns></returns>
        private async void DropBoxGridDataBind(List <string> FolderPath = null)
        {
            //*** Constract Path String
            string strFolderpath = "";

            if (FolderPath != null)
            {
                foreach (var item in FolderPath)
                {
                    strFolderpath += "/" + item;
                }
            }

            //*** Bind the Grid & Bread Crumb
            //*** Get Files & Folders List
            List <DropBoxFile> lstDropBoxFile = await DropBoxConnector.ListFolder(Application["dropBoxClientObj"], strFolderpath);

            if (DropBoxConnector.MsgError != "")    //*** If error
            {
                lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                //*** Show Error
                divDropBoxAlert.Visible = true;
            }
            else
            {
                grdVWFilesFolderList.DataSource = lstDropBoxFile;
                grdVWFilesFolderList.DataBind();
                rptFolderBreadCrumb.DataSource = (List <string>)Session["FolderPath"];
                rptFolderBreadCrumb.DataBind();
                divFileGrid.Visible = true;
            }
        }
Exemplo n.º 2
0
        //*** Upload File Button
        protected async void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)
        {
            //*** Construct Parent Folder + File Path String
            string strUploadedFilePath = "";

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strUploadedFilePath += "/" + item;
                }
            }
            strUploadedFilePath += "/" + args[0].FileName;

            //*** Upload File to DropBox Function
            bool blnUploadResult = await DropBoxConnector.Upload(Application["dropBoxClientObj"], strUploadedFilePath, args[0].OpenStream());

            if (!blnUploadResult)    //*** If error
            {
                lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                //*** Show Error
                divDropBoxAlert.Visible = true;

                //*** Exit from function
                return;
            }
            else   //**** Success
            {
                //*** Rebind Data Grid Again
                DropBoxGridDataBind(((List <string>)Session["FolderPath"]));
            }
        }
        protected async void Page_Load(object sender, EventArgs e)
        {
            //*** Check If it's called from Site Page
            if (Request.QueryString["Code"] == null)
            {
                //*** get access token
                Response.Redirect((DropBoxConnector.getAccessTokenURL(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["dropBoxReturnBackURL"].ToString())).ToLower(), false);
            }
            else   //**** Get Code from Auth Provider
            {
                //*** Check If Code returned into Connection String
                if (Application["dropBoxAccessToken"] == null && !String.IsNullOrEmpty(Request.QueryString["Code"]))
                {
                    //**** Initialize Session Folder Path
                    List <string> Dump = new List <string> {
                    };
                    Session["FolderPath"] = Dump;

                    await DropBoxConnector.getAccessTokenFromResponse(Request.QueryString["Code"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["dropBoxReturnBackURL"].ToString().ToLower());

                    if (DropBoxConnector.MsgError == "")
                    {
                        //*** Get Token
                        Application["dropBoxAccessToken"] = DropBoxConnector.dropBoxAccessToken;

                        //**** Close & Refresh parent
                        CodeReturned = "true";
                    }
                    else   //*** If Error returned
                    {
                        Response.Write(DropBoxConnector.MsgError);
                    }
                }
            }
        }
Exemplo n.º 4
0
        //**** Connect to dropBox Button Handler
        protected void lnkbtnConnectDropBox_Click(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["returnBackURL"] == null)
            {
                HttpContext.Current.Session["returnBackURL"] = HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("?") <= 0 ? HttpContext.Current.Request.Url.AbsoluteUri.ToLower() : HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("?") + 1).ToLower();
            }
            //*** get access token
            Response.Redirect(DropBoxConnector.getAccessTokenURL(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["returnBackURL"].ToString()));

            return;
        }
Exemplo n.º 5
0
        //**** Create Folder Button
        protected async void btnPanel2Yes_Click(object sender, EventArgs e)
        {
            //*** Check First if Folder Exist/ Fitsh
            foreach (GridViewRow row in grdVWFilesFolderList.Rows)
            {
                if (((Label)row.FindControl("lblFileName")).Text.ToLower() == txtFolderName.Text.ToLower() && bool.Parse(((Label)row.FindControl("lblisFolder")).Text.ToLower()))
                {
                    //*** Folder Already Exist
                    lblDropBoxMsg.Text = "Folder already exists with same name";

                    //*** Show Error with grid
                    divDropBoxAlert.Visible = true;
                    divFileGrid.Visible     = true;

                    //*** Exit from function
                    return;
                }
            }

            //*** Construct Parent Folder Path String
            string strFolderpath = "";

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strFolderpath += "/" + item;
                }
            }
            strFolderpath += "/" + txtFolderName.Text;

            //*** Create Folder Function
            bool fnResult = await DropBoxConnector.CreateFolder(Application["dropBoxClientObj"], strFolderpath);

            if (!fnResult)    //*** If error
            {
                lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                //*** Show Error
                divDropBoxAlert.Visible = true;
            }
            else
            {
                //*** Success & Rebind Data Grid Again & Initialize
                txtFolderName.Text = "";
                DropBoxGridDataBind(((List <string>)Session["FolderPath"]));
            }
        }
        // GET: DropBoxAuth
        public async System.Threading.Tasks.Task <ActionResult> Index()
        {
            //*** Initlaize
            Session["CodeReturned"] = "false";

            //*** Check If it's called from Site Page
            if (Request.QueryString["Code"] == null)
            {
                //*** get access token
                Response.Redirect((DropBoxConnector.getAccessTokenURL(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], Session["dropBoxReturnBackURL"].ToString())).ToLower(), false);
            }
            else   //**** Get Code from Auth Provider
            {
                //*** Check If Code returned into Connection String
                if (Session["dropBoxAccessToken"] == null && !String.IsNullOrEmpty(Request.QueryString["Code"]))
                {
                    //**** Initialize Session Folder Path
                    List <string> Dump = new List <string> {
                    };
                    Session["FolderPath"] = Dump;

                    await DropBoxConnector.getAccessTokenFromResponse(Request.QueryString["Code"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], Session["dropBoxReturnBackURL"].ToString().ToLower());

                    if (DropBoxConnector.MsgError == "")
                    {
                        //*** Get Token
                        Session["dropBoxAccessToken"] = DropBoxConnector.dropBoxAccessToken;

                        //**** Close & Refresh parent
                        Session["CodeReturned"] = "true";
                    }
                    else   //*** If Error returned
                    {
                        Response.Write(DropBoxConnector.MsgError);
                    }
                }
            }
            return(View());
        }
Exemplo n.º 7
0
        //*** Delete Button
        protected async void lnkbtnDelete_Click(object sender, ImageClickEventArgs e)
        {
            //*** Construct Parent Folder Path String
            string strParentFolderpath = "";

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strParentFolderpath += "/" + item;
                }
            }

            //*** Loop on Items to see who is checked to delete
            foreach (GridViewRow row in grdVWFilesFolderList.Rows)
            {
                if (((CheckBox)row.FindControl("chkItem")).Checked)
                {
                    string strPath = strParentFolderpath + "/" + ((Label)row.FindControl("lblFileName")).Text;

                    //*** Create Folder Function
                    bool fnResult = await DropBoxConnector.DeleteFileOrFolder(Application["dropBoxClientObj"], strPath);

                    if (!fnResult)    //*** If error
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;

                        //*** Exit loop function
                        break;
                    }
                }
            }

            //*** Rebind Data Grid Again
            DropBoxGridDataBind(((List <string>)Session["FolderPath"]));
        }
Exemplo n.º 8
0
        //*****************************************************************
        //*** Drop Box Files List Function
        //*****************************************************************
        /// <summary>
        /// *** Get DropBox Files List
        /// </summary>
        /// <param name="FolderPath">Folder Path in Array Format</param>
        /// <returns></returns>
        private async Task getDropBoxFilesList(List <string> FolderPath = null)
        {
            try
            {
                //*** Constract Path String
                string strFolderpath = "";
                string strFolderName = "";
                if (FolderPath != null)
                {
                    foreach (var item in FolderPath)
                    {
                        strFolderpath += "/" + item;
                        strFolderName  = item;
                    }
                }

                //*** Bind the Grid & Bread Crumb
                //*** Get Files & Folders List
                //var returnTask = DropBoxConnector.ListFolder(Session["dropBoxClientObj"], strFolderpath);
                //returnTask.Wait();
                //List<DropBoxFile> lstDropBoxFile = returnTask.Result;
                List <DropBoxFile> lstDropBoxFile = await DropBoxConnector.ListFolder(Session["dropBoxClientObj"], strFolderpath);

                if (DropBoxConnector.MsgError != "")    //*** If error
                {
                    Session["lblDropBoxMsg"] = DropBoxConnector.MsgError;
                }
                else
                {
                    //*** Set Session with All Dropbox List
                    Session["lstDropBoxFile"] = lstDropBoxFile;
                }
            }
            catch (Exception e)
            {
                Session["lblDropBoxMsg"] = "getDropBoxFilesList Error: " + e.ToString();
            }
        }
Exemplo n.º 9
0
        public async System.Threading.Tasks.Task <ActionResult> Index()

        {
            //*** Check Lock Variable First
            if (!(Boolean)HttpContext.Application["SyncInProgress"])
            {
                HttpContext.Application["SyncInProgress"] = true; //*** Set Lock Flag

                ViewBag.Title = "Sync Dropbox Files";

                //*** Initialization
                Session["lblDropBoxMsg"]      = "";
                Session["btnDropBoxbtnV"]     = "hidden";
                Session["btnExactOnlinebtnV"] = "hidden";
                Session["SyncAllNumbers"]     = "";
                Session["ResultNumbers"]      = "";

                strSiteBaseURL = Request.Url.Scheme + "://" + Request.Url.Host;
                if (Request.Url.Port > 0)
                {
                    strSiteBaseURL += ":" + Request.Url.Port.ToString();
                }
                ;

                //*** Adjust Drop Box Call Back URL for
                if (Session["dropBoxReturnBackURL"] == null)
                {
                    Session["dropBoxReturnBackURL"]  = strSiteBaseURL;
                    Session["dropBoxReturnBackURL"] += "/" + System.Configuration.ConfigurationManager.AppSettings["dropBoxAuthReturnPage"];
                }
                //******************************************************

                //*********************************************
                //*** Query on Files last Modified
                //*********************************************
                DateTime             dtLastModifiedDate      = new DateTime(2000, 1, 1);
                CloudStorageEntities objCloudStorageEntities = new CloudStorageEntities();

                //*** Check First if File Already exisit into DB
                DropboxWebhook objRecord = objCloudStorageEntities.DropboxWebhooks.Where(i => i.DW_Processed == 0).FirstOrDefault();
                if (objRecord != null)
                {
                    dtLastModifiedDate = Convert.ToDateTime(objRecord.DW_TimeStamp);
                }

                if (dtLastModifiedDate > Convert.ToDateTime("1/1/2000"))
                {
                    //******************************************************************************************************
                    //*** Dropbox Part
                    //******************************************************************************************************
                    //*** Check dropBox Aurhentication Token
                    if (Session["dropBoxAccessToken"] == null)
                    {
                        //***************************
                        //*** access token is empty
                        //***************************
                        //*** 1. Check first for dropBox App Key & App secret
                        if (String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"]) ||
                            String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"]))
                        {
                            //*** Show Error Message
                            Session["lblDropBoxMsg"] = "Please set app key and secret in this project's Web.config file and restart. " +
                                                       "App key/secret can be found in the Dropbox App Console, here: " +
                                                       "https://www.dropbox.com/developers/apps";
                            goto lnIndexEnd;
                        }
                        else   //*** AppKey & secret exist
                        {
                            //*** Show Connect to DropBox button
                            Session["btnDropBoxbtnV"] = "visible";
                        }
                    }
                    else
                    {
                        //*** Get DropBox Client Object
                        Session["dropBoxClientObj"] = DropBoxConnector.getDropboxClient(Session["dropBoxAccessToken"].ToString());

                        if (DropBoxConnector.MsgError != "")    //*** If error
                        {
                            Session["lblDropBoxMsg"] = "Dropbox Error: " + DropBoxConnector.MsgError;
                        }
                        else
                        {
                            //******************************************************************************************************
                            //*** Exact Online Part
                            //******************************************************************************************************
                            //*** Adjust Drop Box Call Back URL for
                            if (Session["exactOnlineReturnBackURL"] == null)
                            {
                                Session["exactOnlineReturnBackURL"] = Request.Url.Scheme + "://" + Request.Url.Host;
                                if (Request.Url.Port > 0)
                                {
                                    Session["exactOnlineReturnBackURL"] += ":" + Request.Url.Port.ToString();
                                }
                                ;
                                Session["exactOnlineReturnBackURL"] += "/" + System.Configuration.ConfigurationManager.AppSettings["exactOnlineReturnPage"];
                            }

                            //*** Check If Code returned into Connection String
                            if (Session["ExactOnlineAccessToken"] == null && Session["ExactOnlineReturnCode"] != null)
                            {
                                //**** Initialize Session Folder Path
                                List <string> Dump = new List <string> {
                                };
                                Session["ExactOnlineFolderPath"] = Dump;

                                //**** Construct Exact Online Class
                                ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                                Session["ExactOnlineAccessToken"] = objExactOnlineConnector.GetAccessToken();

                                if (objExactOnlineConnector.MsgError != "")
                                {   //*** If Error returned
                                    Session["lblDropBoxMsg"] = "Exact Online Error: " + objExactOnlineConnector.MsgError;

                                    goto lnIndexEnd;
                                }
                            }

                            //*** Check ExactOnline Aurhentication Token
                            if (Session["ExactOnlineAccessToken"] == null && Session["ExactOnlineReturnCode"] == null)
                            {
                                //***************************
                                //*** access token is empty
                                //***************************
                                //*** 1. Check first for ExactOnline App Key & App secret
                                if (String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"]) ||
                                    String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"]) ||
                                    String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"]))
                                {
                                    //*** Show Error Message
                                    Session["lblDropBoxMsg"] = "Please set client id, client secret and end point URL into this project's Web.config file and restart. " +
                                                               "client id/secret can be found in the ExactOnline App Console, here: " +
                                                               "https://start.exactonline.co.uk";

                                    goto lnIndexEnd;
                                }
                                else   //*** AppKey & secret exist
                                {
                                    //*** Show Connect to ExactOnline button
                                    Session["btnExactOnlinebtnV"] = "visible";
                                }
                            }

                            if (Session["ExactOnlineReturnCode"] != null)
                            {
                                //*** 1. List all Dropbox Files
                                await getDropBoxFilesList((List <string>) Session["FolderPath"]);

                                //*** 2. Call Sync Function which Sync all Modified files with Exact Online Store
                                await SyncAllFilesFolders((List <DropBoxFile>) Session["lstDropBoxFile"]);

                                if (objRecord != null)
                                {
                                    //*** Update Flag of WebHook Table
                                    objRecord.DW_Processed        = 1;
                                    objRecord.DW_ProcessTimeStamp = DateTime.Now;
                                    objCloudStorageEntities.SaveChanges();
                                }
                            }
                        }
                    }
                }

lnIndexEnd:
                //*** GC
                objCloudStorageEntities.Dispose();
            }

            HttpContext.Application["SyncInProgress"] = false; //*** Release Lock Flag

            //*** Display Results
            if (Session["SyncAllNumbers"].ToString() != "")
            {
                string[] strAllResultNumbers = Session["SyncAllNumbers"].ToString().Split(',');

                Session["ResultNumbers"] = "Dropbox Files= " + strAllResultNumbers[0] + " ,Files Processed= " + strAllResultNumbers[1] + " ,Files Replaced Successfully= " + strAllResultNumbers[2] + " ,Failure= " + strAllResultNumbers[3];
            }

            try
            {
                return(View());
            }
            finally
            {
            }
        }
Exemplo n.º 10
0
        //*****************************************************************
        //*** Major Sync Function with Exact online store
        //*****************************************************************
        /// <summary>
        /// *** Sync Function which Sync all Modified files with Exact Online Store
        /// </summary>
        /// <param name="lstDropBoxFile">Dropbox files in List Format</param>
        /// <returns></returns>
        private async Task SyncAllFilesFolders(List <DropBoxFile> lstDropBoxFile)
        {
            //System.Threading.Thread.Sleep(30000);

            try
            {
                //*** Set Variables
                int intCount = 0, intSuccess = 0, intFailed = 0;
                Session["SyncAllNumbers"] = "";
                string strExactFileGUID    = "";
                string strFolderpath       = "";
                string strParentFolderpath = "";
                CloudStorageEntities objCloudStorageEntities = new CloudStorageEntities();

                //**** Construct Exact Online Class
                ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                //*** First Reset All "FileStillAlive" Flag into DB
                (from p in objCloudStorageEntities.DropBoxExactOnlines
                 where p.Id >= 0
                 select p).ToList().ForEach(x => x.FileStillAlive = 0);
                objCloudStorageEntities.SaveChanges();

                //*** Loop on All Objects on DropBox Grid View
                foreach (var DropBoxFile in lstDropBoxFile)
                {
                    strFolderpath = "";

                    //*** Refresh Counts
                    intCount += 1;

                    //**** Check If File item exist into DB with same Modified Date or not
                    //*** 1. Exist with Same Modified Date, Do Nothing
                    //*** 2. Not Exist, So Add File to Exact Online and DB
                    //*** 3. Exist with Different Modified Date, So Update File into Exact Online and Modified Date into DB

                    DropBoxExactOnline objRecord = objCloudStorageEntities.DropBoxExactOnlines.Where(i => i.DropBoxPath == DropBoxFile.FileName).FirstOrDefault();
                    if (objRecord == null || (objRecord != null && DropBoxFile.ModificationDate != objRecord.DropBoxFileModifiedDate))   //*** Not Exist Or File Exist with Different Modification Date
                    {
                        //********************************************************************
                        //*** Add File to Exact Online
                        //********************************************************************

                        //**** Get File Stream then upload it to ExactOnline & Flush
                        //*** Construct Parent Folder Path String
                        strParentFolderpath = "";
                        if ((List <string>)Session["FolderPath"] != null)
                        {
                            foreach (var item in (List <string>)Session["FolderPath"])
                            {
                                strParentFolderpath += "/" + item;
                            }
                        }

                        string strPath = strParentFolderpath + "/" + DropBoxFile.FileName;
                        strFolderpath = strPath;

                        //*** Create Folder Function
                        Stream fnStreamResult = await DropBoxConnector.Download(Session["dropBoxClientObj"], strPath);

                        if (DropBoxConnector.MsgError != "")    //*** If error
                        {
                            intFailed += 1;
                        }
                        else
                        {
                            //*************************************************************
                            //*** Convert File to Byte Array and upload it to Exact Online
                            //*************************************************************
                            if (Session["ExactOnlineAccessToken"] != null)
                            {
                                objExactOnlineConnector.AccessToken = Session["ExactOnlineAccessToken"].ToString();
                            }

                            //**** Get Document Folder GUID
                            Session["CurrentExactFolderGUID"] = string.Empty;       //*** Root Folder

                            //*** If File already exisit then Delete it first
                            if (objRecord != null && DropBoxFile.ModificationDate != objRecord.DropBoxFileModifiedDate)
                            {
                                objExactOnlineConnector.DeleteDocument(objRecord.ExactOnlineGUID);  //**** Call Delete Document
                            }

                            strExactFileGUID = objExactOnlineConnector.CreateDocumentWithAttachment(DropBoxFile.FileName, Session["CurrentExactFolderGUID"].ToString(), Common.ConvertStreamtoByteArr(fnStreamResult));
                            if (strExactFileGUID == "")
                            {
                                intFailed += 1;
                            }
                            else
                            {
                                intSuccess += 1;
                            }
                        }
                        //******************************************************************

                        if (objRecord == null)
                        {
                            //*** add to DB
                            DropBoxExactOnline objRecordNew = new DropBoxExactOnline();
                            objRecordNew.DropBoxPath             = DropBoxFile.FileName;
                            objRecordNew.DropBoxFileModifiedDate = DropBoxFile.ModificationDate;
                            objRecordNew.ExactOnlineGUID         = strExactFileGUID;
                            objRecordNew.isFile         = 1;
                            objRecordNew.FileStillAlive = 1;

                            objCloudStorageEntities.DropBoxExactOnlines.Add(objRecordNew);
                            objCloudStorageEntities.SaveChanges();
                        }
                        else
                        {
                            //**** Update DB
                            objRecord.DropBoxFileModifiedDate = DropBoxFile.ModificationDate;
                            objRecord.ExactOnlineGUID         = strExactFileGUID;
                            objRecord.FileStillAlive          = 1;

                            objCloudStorageEntities.SaveChanges();
                        }
                    }

                    //*** If File still exit and not changed
                    if (objRecord != null && DropBoxFile.ModificationDate == objRecord.DropBoxFileModifiedDate)
                    {
                        objRecord.FileStillAlive = 1;

                        objCloudStorageEntities.SaveChanges();
                    }

                    //*** set Session Variable (Shared Variable)
                    Session["SyncAllNumbers"] = lstDropBoxFile.Count.ToString() + "," + intCount.ToString() + "," + intSuccess.ToString() + "," + intFailed.ToString();
                }   //*** For Loop

                //***************************************************************************************
                //*** Then Check For Not Alive Files to Delete from DB and Exact Online
                //***************************************************************************************
                List <DropBoxExactOnline> lstFiles = objCloudStorageEntities.DropBoxExactOnlines.Where(item => item.FileStillAlive == 0).ToList();

                foreach (var file in lstFiles)
                {
                    //****************************************************************
                    //**** Delete File from Exact Online
                    //****************************************************************
                    if (file.ExactOnlineGUID != "")
                    {
                        //*** Delete File on Exact Online also
                        if (Session["ExactOnlineAccessToken"] != null)
                        {
                            objExactOnlineConnector.AccessToken = Session["ExactOnlineAccessToken"].ToString();
                        }

                        //**** Call Delete Document
                        objExactOnlineConnector.DeleteDocument(file.ExactOnlineGUID);
                    }
                    //***************************************************************************

                    //*** Delete From DB
                    objCloudStorageEntities.DropBoxExactOnlines.Remove(file);
                }   //*** For Loop

                //*** Submit Delete from DB
                objCloudStorageEntities.SaveChanges();
                //***************************************************************************************
            }
            catch (Exception e)
            {
                Session["lblDropBoxMsg"] = "SyncAllFilesFolders Error: " + e.ToString();
            }
        }
Exemplo n.º 11
0
        //*** Download Button
        protected async void lnkbtnDownload_Click(object sender, ImageClickEventArgs e)
        {
            //*** Construct Parent Folder Path String
            string strParentFolderpath = "";

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strParentFolderpath += "/" + item;
                }
            }

            //*** Loop on Items to see file is checked to download
            foreach (GridViewRow row in grdVWFilesFolderList.Rows)
            {
                if (((CheckBox)row.FindControl("chkItem")).Checked)
                {
                    //*** Check if Selected is Folder
                    if (bool.Parse(((Label)row.FindControl("lblisFolder")).Text))
                    {
                        //*** Folder Already Exist
                        lblDropBoxMsg.Text = "Only Files can be downloaded";

                        //*** Show Error with grid
                        divDropBoxAlert.Visible = true;
                        divFileGrid.Visible     = true;

                        //*** Exit from function
                        return;
                    }
                    else
                    {
                        //*** Checked is Files
                        string strPath = strParentFolderpath + "/" + ((Label)row.FindControl("lblFileName")).Text;

                        //*** Create Folder Function
                        Stream fnStreamResult = await DropBoxConnector.Download(Application["dropBoxClientObj"], strPath);

                        if (DropBoxConnector.MsgError != "")    //*** If error
                        {
                            lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                            //*** Show Error
                            divDropBoxAlert.Visible = true;

                            //*** Exit from function
                            return;
                        }
                        else
                        {
                            //*** Save file to tmp Folder and direct user to it
                            // Create a FileStream object to write a stream to a file
                            using (var fileStream = new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + System.Configuration.ConfigurationManager.AppSettings["downloadFolderRelPath"] + ((Label)row.FindControl("lblFileName")).Text, FileMode.Create, FileAccess.Write))
                            {
                                fnStreamResult.CopyTo(fileStream);
                            }

                            //*** Then redirect to that file to download it
                            DownloadFilePath = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host;
                            if (HttpContext.Current.Request.Url.Port > 0)
                            {
                                DownloadFilePath += ":" + HttpContext.Current.Request.Url.Port.ToString();
                            }
                            ;
                            DownloadFilePath   += "/" + System.Configuration.ConfigurationManager.AppSettings["downloadFolderRelPath"].Replace("\\", "/") + ((Label)row.FindControl("lblFileName")).Text;
                            divFileGrid.Visible = true;
                            pnlDownload.Visible = true;

                            //*** Exit from function
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        protected async void Page_Load(object sender, EventArgs e)
        {
            //*** Initialization
            divDropBoxAlert.Visible         = false;
            lnkbtnConnectDropBox.Visible    = false;
            lnkbtnDisconnectDropBox.Visible = false;
            divFileGrid.Visible             = false;
            pnlDownload.Visible             = false;

            //*** First Time
            if (!Page.IsPostBack)
            {
                //*** Check If Code returned into Connection String
                if (Application["dropBoxAccessToken"] == null && !String.IsNullOrEmpty(Request.QueryString["Code"]))
                {
                    //**** Initialize Session Folder Path
                    List <string> Dump = new List <string> {
                    };
                    Session["FolderPath"] = Dump;

                    await DropBoxConnector.getAccessTokenFromResponse(Request.QueryString["Code"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"], System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"], HttpContext.Current.Session["returnBackURL"].ToString());

                    if (DropBoxConnector.MsgError == "")
                    {
                        //*** Get Token
                        Application["dropBoxAccessToken"] = DropBoxConnector.dropBoxAccessToken;
                    }
                    else   //*** If Error returned
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;
                    }
                }
                //******************************************************


                //*** Check dropBox Aurhentication Token
                if (Application["dropBoxAccessToken"] == null)
                {
                    //***************************
                    //*** access token is empty
                    //***************************
                    //*** 1. Check first for dropBox App Key & App secret
                    if (String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"]) ||
                        String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"]))
                    {
                        //*** Show Error Message
                        lblDropBoxMsg.Text = "Please set app key and secret in this project's Web.config file and restart. " +
                                             "App key/secret can be found in the Dropbox App Console, here: " +
                                             "https://www.dropbox.com/developers/apps";

                        //*** Show Error
                        divDropBoxAlert.Visible = true;

                        return;
                    }
                    else   //*** AppKey & secret exist
                    {
                        //*** Show Connect to DropBox button
                        lnkbtnConnectDropBox.Visible = true;
                    }
                }
                else
                {
                    //*** Get DropBox Client Object
                    Application["dropBoxClientObj"] = DropBoxConnector.getDropboxClient(Application["dropBoxAccessToken"].ToString());

                    if (DropBoxConnector.MsgError != "")    //*** If error
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;
                    }
                    else
                    {
                        //*** Get User Info
                        await DropBoxConnector.getUserInfo(Application["dropBoxClientObj"]);

                        lblAccountName.Text = DropBoxConnector.objDropBoxUser.AccountDisplayName;

                        DropBoxGridDataBind((List <string>)Session["FolderPath"]);
                    }
                }
            }
        }
Exemplo n.º 13
0
        //*****************************************************************
        //*** Drop Box Files Grid Functions
        //*****************************************************************
        /// <summary>
        //*** Bind DropBox Data Grid
        /// </summary>
        /// <param name="FolderPath">Folder Path in Array Format</param>
        /// <returns></returns>
        private async void DropBoxGridDataBind(List <string> FolderPath = null)
        {
            //*** Constract Path String
            string strFolderpath = "";
            string strFolderName = "";

            if (FolderPath != null)
            {
                foreach (var item in FolderPath)
                {
                    strFolderpath += "/" + item;
                    strFolderName  = item;
                }
            }

            //*** Bind the Grid & Bread Crumb
            //*** Get Files & Folders List
            List <DropBoxFile> lstDropBoxFile = await DropBoxConnector.ListFolder(Application["dropBoxClientObj"], strFolderpath);

            if (DropBoxConnector.MsgError != "")    //*** If error
            {
                lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                //*** Show Error
                divDropBoxAlert.Visible = true;
            }
            else
            {
                grdVWDropBoxFilesFolderList.DataSource = lstDropBoxFile;
                grdVWDropBoxFilesFolderList.DataBind();
                rptDropBoxFolderBreadCrumb.DataSource = (List <string>)Session["FolderPath"];
                rptDropBoxFolderBreadCrumb.DataBind();
                DivDropBoxFileGrid.Visible = true;
                if (divExactOnlineFileGrid.Visible)
                {
                    divSync.Visible = true;
                }

                //****************************************************************
                //**** Bind Exact Rebind Online Part
                //****************************************************************
                string strFolderGUID = "";
                if (divExactOnlineFileGrid.Visible)     //**** If Exact Online Grid Shown
                {
                    //*** 1. Get Folder Guid (If not root)
                    if (strFolderName != "")
                    {
                        //*** Fitch Grid to get GUID
                        foreach (GridViewRow row in grdVWExactOnlineFilesFolderList.Rows)
                        {
                            //*** Check if name & Is Folcder
                            if (bool.Parse(((Label)row.FindControl("lblisFolder")).Text) && ((Label)row.FindControl("lblFileName")).Text.ToLower() == strFolderName.ToLower())
                            {
                                strFolderGUID = ((Label)row.FindControl("lblFolderID")).Text;
                                break;
                            }
                        }
                    }

                    Session["CurrentExactFolderGUID"] = strFolderGUID;

                    //*** Then Rebind ExactOnline Grid
                    ExactOnlineGridDataBind(strFolderGUID);
                }
                //****************************************************************
            }
        }
Exemplo n.º 14
0
        private async Task SyncAllFilesFolders()
        {
            try
            {
                //*** Set Variables
                int intCount = 0, intSuccess = 0, intFailed = 0;
                Session["SyncAllNumbers"] = "";
                string strFolderGUID = "";
                string strFolderpath = "";

                //*** Loop on All Objects on DropBox Grid View
                foreach (GridViewRow itemRow in grdVWDropBoxFilesFolderList.Rows)
                {
                    strFolderpath = "";

                    //*** Refresh Counts
                    intCount += 1;

                    //*** set Session Variable (Shared Variable)
                    Session["SyncAllNumbers"] = grdVWDropBoxFilesFolderList.Rows.Count.ToString() + "," + intCount.ToString() + "," + intSuccess.ToString() + "," + intFailed.ToString();

                    //*** Check on Drop Box Enity
                    if (bool.Parse(((Label)itemRow.FindControl("lblisFolder")).Text))   //**** If Folder
                    {
                        //************************************
                        //**** Create Folder on ExactOnline
                        //************************************
                        //**** Construct Exact Online Class
                        ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                        if (Application["ExactOnlineAccessToken"] != null)
                        {
                            objExactOnlineConnector.AccessToken = Application["ExactOnlineAccessToken"].ToString();
                        }

                        strFolderGUID = objExactOnlineConnector.CreateDocumentFolder(((Label)itemRow.FindControl("lblFileName")).Text, Session["CurrentExactFolderGUID"].ToString());
                        if (strFolderGUID == "")
                        {
                            //*** If Error returned
                            intFailed += 1;
                        }
                        else
                        {
                            intSuccess += 1;
                        }
                    }
                    else  //**** If File
                    {
                        //******************************************************************
                        //**** Get File Stream then upload it to ExactOnline & Flush
                        //******************************************************************
                        //*** Construct Parent Folder Path String
                        string strParentFolderpath = "";
                        if ((List <string>)Session["FolderPath"] != null)
                        {
                            foreach (var item in (List <string>)Session["FolderPath"])
                            {
                                strParentFolderpath += "/" + item;
                            }
                        }

                        string strPath = strParentFolderpath + "/" + ((Label)itemRow.FindControl("lblFileName")).Text;
                        strFolderpath = strPath;

                        //*** Create Folder Function
                        Stream fnStreamResult = await DropBoxConnector.Download(Application["dropBoxClientObj"], strPath);

                        if (DropBoxConnector.MsgError != "")    //*** If error
                        {
                            intFailed += 1;
                        }
                        else
                        {
                            //*************************************************************
                            //*** Convert File to Byte Array and upload it to Exact Online
                            //*************************************************************
                            //**** Construct Exact Online Class
                            ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                            if (Application["ExactOnlineAccessToken"] != null)
                            {
                                objExactOnlineConnector.AccessToken = Application["ExactOnlineAccessToken"].ToString();
                            }

                            strFolderGUID = objExactOnlineConnector.CreateDocumentWithAttachment(((Label)itemRow.FindControl("lblFileName")).Text, Session["CurrentExactFolderGUID"].ToString(), Common.ConvertStreamtoByteArr(fnStreamResult));
                            if (strFolderGUID == "")
                            {
                                intFailed += 1;
                            }
                            else
                            {
                                intSuccess += 1;
                            }
                        }
                        //******************************************************************
                    }

                    //*** The Add to update record into DB
                    if (bool.Parse(((Label)itemRow.FindControl("lblisFolder")).Text))    //*** If Folder
                    {
                        if ((List <string>)Session["FolderPath"] != null)
                        {
                            foreach (var item in (List <string>)Session["FolderPath"])
                            {
                                strFolderpath += "/" + item;
                            }
                        }
                        strFolderpath += "/" + ((Label)itemRow.FindControl("lblFileName")).Text;
                    }

                    FilesDocumentsEntities objFilesDocumentsEntities = new FilesDocumentsEntities();

                    //*** Check First if File Already exisit into DB
                    DropBoxExactOnline objRecord = objFilesDocumentsEntities.DropBoxExactOnlines.Where(i => i.DropBoxPath == strFolderpath).FirstOrDefault();
                    if (objRecord != null)
                    {
                        //**** Update DB
                        objRecord.DropBoxPath     = strFolderpath;
                        objRecord.ExactOnlineGUID = strFolderGUID;
                        if (bool.Parse(((Label)itemRow.FindControl("lblisFolder")).Text))
                        {
                            objRecord.isFile = 0;
                        }
                        else
                        {
                            objRecord.isFile = 1;
                        }

                        objFilesDocumentsEntities.SaveChanges();
                    }
                    else
                    {
                        //*** add to DB
                        DropBoxExactOnline objRecordNew = new DropBoxExactOnline();
                        objRecordNew.DropBoxPath     = strFolderpath;
                        objRecordNew.ExactOnlineGUID = strFolderGUID;
                        if (bool.Parse(((Label)itemRow.FindControl("lblisFolder")).Text))
                        {
                            objRecordNew.isFile = 0;
                        }
                        else
                        {
                            objRecordNew.isFile = 1;
                        }

                        objFilesDocumentsEntities.DropBoxExactOnlines.Add(objRecordNew);
                        objFilesDocumentsEntities.SaveChanges();
                    }
                    //*******************************************************************************

                    //*** set Session Variable (Shared Variable)
                    Session["SyncAllNumbers"] = grdVWDropBoxFilesFolderList.Rows.Count.ToString() + "," + intCount.ToString() + "," + intSuccess.ToString() + "," + intFailed.ToString();
                }

                //*** Rebind Exact Online Grid
                ExactOnlineGridDataBind(Session["CurrentExactFolderGUID"].ToString());
            }
            catch (Exception e)
            {
                lblExactOnlineMsg.Text = e.ToString();

                //*** Show Error
                divExactOnlineAlert.Visible = true;
            }
        }
Exemplo n.º 15
0
        //*** Upload File Button
        protected async void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)
        {
            //*** Construct Parent Folder + File Path String
            string strUploadedFilePath = "";
            string strFolderName       = "";
            string DocumentGUID        = "";

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strUploadedFilePath += "/" + item;
                    strFolderName        = item;
                }
            }
            strUploadedFilePath += "/" + args[0].FileName;

            //*** Upload File to DropBox Function
            bool blnUploadResult = await DropBoxConnector.Upload(Application["dropBoxClientObj"], strUploadedFilePath, args[0].OpenStream());

            if (!blnUploadResult)    //*** If error
            {
                lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                //*** Show Error
                divDropBoxAlert.Visible = true;

                //*** Exit from function
                return;
            }
            else   //**** Success
            {
                //****************************************************************
                //**** Exact Online Part
                //****************************************************************
                if (divExactOnlineFileGrid.Visible)     //**** If Exact Online Grid Shown
                {
                    //*** Create Folder on Exact Online also
                    //**** Construct Exact Online Class
                    ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                    if (Application["ExactOnlineAccessToken"] != null)
                    {
                        objExactOnlineConnector.AccessToken = Application["ExactOnlineAccessToken"].ToString();
                    }

                    DocumentGUID = objExactOnlineConnector.CreateDocumentWithAttachment(args[0].FileName, Session["CurrentExactFolderGUID"].ToString(), Common.ConvertStreamtoByteArr(args[0].OpenStream()));
                    if (DocumentGUID == "")
                    {
                        //*** If Error returned
                        lblExactOnlineMsg.Text = objExactOnlineConnector.MsgError;

                        //*** Show Error
                        divExactOnlineAlert.Visible = true;
                    }
                    else
                    {
                        //*** Add Entity to DB
                        FilesDocumentsEntities objFilesDocumentsEntities = new FilesDocumentsEntities();

                        //*** Check First if File Already exisit into DB
                        DropBoxExactOnline objRecord = objFilesDocumentsEntities.DropBoxExactOnlines.Where(i => i.DropBoxPath == strUploadedFilePath).FirstOrDefault();
                        if (objRecord != null)
                        {
                            //**** Update DB
                            objRecord.DropBoxPath     = strUploadedFilePath;
                            objRecord.ExactOnlineGUID = DocumentGUID;
                            objRecord.isFile          = 1;

                            objFilesDocumentsEntities.SaveChanges();
                        }
                        else
                        {
                            //*** add to DB
                            DropBoxExactOnline objRecordNew = new DropBoxExactOnline();
                            objRecordNew.DropBoxPath     = strUploadedFilePath;
                            objRecordNew.ExactOnlineGUID = DocumentGUID;
                            objRecordNew.isFile          = 1;

                            objFilesDocumentsEntities.DropBoxExactOnlines.Add(objRecordNew);
                            objFilesDocumentsEntities.SaveChanges();
                        }
                    }
                }
                //***************************************************************************

                //*** Rebind Data Grid Again
                DropBoxGridDataBind(((List <string>)Session["FolderPath"]));
            }
        }
Exemplo n.º 16
0
        //*** Delete Button
        protected async void lnkbtnDelete_Click(object sender, ImageClickEventArgs e)
        {
            //*** Construct Parent Folder Path String
            string strParentFolderpath = "";
            string strFolderName       = "";
            bool   isFolder            = false;

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strParentFolderpath += "/" + item;
                }
            }

            //*** Loop on Items to see who is checked to delete
            foreach (GridViewRow row in grdVWDropBoxFilesFolderList.Rows)
            {
                if (((CheckBox)row.FindControl("chkItem")).Checked)
                {
                    //*** Check if file or Folder
                    isFolder = bool.Parse(((Label)row.FindControl("lblisFolder")).Text);

                    string strPath = strParentFolderpath + "/" + ((Label)row.FindControl("lblFileName")).Text;
                    strFolderName = ((Label)row.FindControl("lblFileName")).Text;

                    //*** Create Folder Function
                    bool fnResult = await DropBoxConnector.DeleteFileOrFolder(Application["dropBoxClientObj"], strPath);

                    if (!fnResult)    //*** If error
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;

                        //*** Exit loop function
                        break;
                    }

                    //****************************************************************
                    //**** Exact Online Part
                    //****************************************************************
                    string strFileFolderGUID = "";
                    if (divExactOnlineFileGrid.Visible)     //**** If Exact Online Grid Shown
                    {
                        //*** 1. Get Folder Guid (If not root)
                        if (strFolderName != "")
                        {
                            //*** Fitch Grid to get GUID
                            foreach (GridViewRow itemRow in grdVWExactOnlineFilesFolderList.Rows)
                            {
                                if (isFolder)   //**** If Folder
                                {
                                    //*** Check if name & Is Folcder
                                    if (bool.Parse(((Label)itemRow.FindControl("lblisFolder")).Text) && ((Label)itemRow.FindControl("lblFileName")).Text.ToLower() == strFolderName.ToLower())
                                    {
                                        strFileFolderGUID = ((Label)itemRow.FindControl("lblFolderID")).Text;
                                        break;
                                    }
                                }
                                else
                                {
                                    //*** Check if name & Is File
                                    if (!bool.Parse(((Label)itemRow.FindControl("lblisFolder")).Text) && ((Label)itemRow.FindControl("lblFileName")).Text.ToLower() == strFolderName.ToLower())
                                    {
                                        strFileFolderGUID = ((Label)itemRow.FindControl("lblFolderID")).Text;
                                        break;
                                    }
                                }
                            }
                        }

                        if (strFileFolderGUID != "")
                        {
                            //*** Create Folder on Exact Online also
                            //**** Construct Exact Online Class
                            ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                            if (Application["ExactOnlineAccessToken"] != null)
                            {
                                objExactOnlineConnector.AccessToken = Application["ExactOnlineAccessToken"].ToString();
                            }

                            if (isFolder)        //*** This is Folder
                            {
                                //*** Call Delete Folder
                                if (!objExactOnlineConnector.DeleteDocumentFolder(strFileFolderGUID))
                                {
                                    //*** If Error returned
                                    lblExactOnlineMsg.Text = objExactOnlineConnector.MsgError;

                                    //*** Show Error
                                    divExactOnlineAlert.Visible = true;
                                }
                            }
                            else  //**** If File
                            {
                                //**** Call Delete Document
                                if (!objExactOnlineConnector.DeleteDocument(strFileFolderGUID))
                                {
                                    //*** If Error returned
                                    lblExactOnlineMsg.Text = objExactOnlineConnector.MsgError;

                                    //*** Show Error
                                    divExactOnlineAlert.Visible = true;
                                }
                            }
                        }
                    }
                    //***************************************************************************

                    //*** Then Delete Records from DB
                    FilesDocumentsEntities objFilesDocumentsEntities = new FilesDocumentsEntities();

                    //*** Check First if File Already exisit into DB
                    DropBoxExactOnline objRecord = objFilesDocumentsEntities.DropBoxExactOnlines.Where(i => i.DropBoxPath == strPath).FirstOrDefault();
                    if (objRecord != null)
                    {
                        objFilesDocumentsEntities.DropBoxExactOnlines.Remove(objRecord);
                        objFilesDocumentsEntities.SaveChanges();
                    }
                }
            }

            //*** Rebind Data Grid Again
            DropBoxGridDataBind(((List <string>)Session["FolderPath"]));
        }
Exemplo n.º 17
0
        //**** Create Folder Button
        protected async void btnPanel2Yes_Click(object sender, EventArgs e)
        {
            //*** Check First if Folder Exist/ Fitsh
            foreach (GridViewRow row in grdVWDropBoxFilesFolderList.Rows)
            {
                if (((Label)row.FindControl("lblFileName")).Text.ToLower() == txtFolderName.Text.ToLower() && bool.Parse(((Label)row.FindControl("lblisFolder")).Text.ToLower()))
                {
                    //*** Folder Already Exist
                    lblDropBoxMsg.Text = "Folder already exists with same name";

                    //*** Show Error with grid
                    divDropBoxAlert.Visible    = true;
                    DivDropBoxFileGrid.Visible = true;

                    //*** Exit from function
                    return;
                }
            }

            //*** Construct Parent Folder Path String
            string strFolderpath = "";
            string strFolderName = "";

            if ((List <string>)Session["FolderPath"] != null)
            {
                foreach (var item in (List <string>)Session["FolderPath"])
                {
                    strFolderpath += "/" + item;
                    strFolderName  = item;
                }
            }
            strFolderpath += "/" + txtFolderName.Text;

            //*** Create Folder Function
            bool fnResult = await DropBoxConnector.CreateFolder(Application["dropBoxClientObj"], strFolderpath);

            if (!fnResult)    //*** If error
            {
                lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                //*** Show Error
                divDropBoxAlert.Visible = true;
            }
            else
            {
                //****************************************************************
                //**** Exact Online Part
                //****************************************************************
                if (divExactOnlineFileGrid.Visible)     //**** If Exact Online Grid Shown
                {
                    //*** Create Folder on Exact Online also
                    //**** Construct Exact Online Class
                    ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                    if (Application["ExactOnlineAccessToken"] != null)
                    {
                        objExactOnlineConnector.AccessToken = Application["ExactOnlineAccessToken"].ToString();
                    }

                    string strFolderGUID = objExactOnlineConnector.CreateDocumentFolder(txtFolderName.Text, Session["CurrentExactFolderGUID"].ToString());
                    if (strFolderGUID == "")
                    {
                        //*** If Error returned
                        lblExactOnlineMsg.Text = objExactOnlineConnector.MsgError;

                        //*** Show Error
                        divExactOnlineAlert.Visible = true;
                    }
                    else  //*** Add Entry To DB
                    {
                        FilesDocumentsEntities objFilesDocumentsEntities = new FilesDocumentsEntities();

                        DropBoxExactOnline objRecord = new DropBoxExactOnline();
                        objRecord.DropBoxPath     = strFolderpath;
                        objRecord.ExactOnlineGUID = strFolderGUID;
                        objRecord.isFile          = 0;

                        objFilesDocumentsEntities.DropBoxExactOnlines.Add(objRecord);
                        objFilesDocumentsEntities.SaveChanges();
                    }
                }
                //***************************************************************************

                //*** Success & Rebind Data Grid Again & Initialize
                txtFolderName.Text = "";
                DropBoxGridDataBind(((List <string>)Session["FolderPath"]));
            }
        }
Exemplo n.º 18
0
        protected async void Page_Load(object sender, EventArgs e)
        {
            //*** First Time
            if (!Page.IsPostBack)
            {
                //*** Initialization
                divDropBoxAlert.Visible         = false;
                lnkbtnConnectDropBox.Visible    = false;
                lnkbtnDisconnectDropBox.Visible = false;
                DivDropBoxFileGrid.Visible      = false;
                pnlDownload.Visible             = false;

                strSiteBaseURL = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host;
                if (HttpContext.Current.Request.Url.Port > 0)
                {
                    strSiteBaseURL += ":" + HttpContext.Current.Request.Url.Port.ToString();
                }
                ;

                //*** Adjust Drop Box Call Back URL for
                if (HttpContext.Current.Session["dropBoxReturnBackURL"] == null)
                {
                    HttpContext.Current.Session["dropBoxReturnBackURL"]  = strSiteBaseURL;
                    HttpContext.Current.Session["dropBoxReturnBackURL"] += "/" + System.Configuration.ConfigurationManager.AppSettings["dropBoxAuthReturnPage"];
                }
                //******************************************************


                //*** Check dropBox Aurhentication Token
                if (Application["dropBoxAccessToken"] == null)
                {
                    //***************************
                    //*** access token is empty
                    //***************************
                    //*** 1. Check first for dropBox App Key & App secret
                    if (String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppKey"]) ||
                        String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["dropBoxAppSecret"]))
                    {
                        //*** Show Error Message
                        lblDropBoxMsg.Text = "Please set app key and secret in this project's Web.config file and restart. " +
                                             "App key/secret can be found in the Dropbox App Console, here: " +
                                             "https://www.dropbox.com/developers/apps";

                        //*** Show Error
                        divDropBoxAlert.Visible = true;

                        return;
                    }
                    else   //*** AppKey & secret exist
                    {
                        //*** Show Connect to DropBox button
                        lnkbtnConnectDropBox.Visible = true;
                    }
                }
                else
                {
                    //*** Get DropBox Client Object
                    Application["dropBoxClientObj"] = DropBoxConnector.getDropboxClient(Application["dropBoxAccessToken"].ToString());

                    if (DropBoxConnector.MsgError != "")    //*** If error
                    {
                        lblDropBoxMsg.Text = DropBoxConnector.MsgError;

                        //*** Show Error
                        divDropBoxAlert.Visible = true;
                    }
                    else
                    {
                        //*** Get User Info
                        await DropBoxConnector.getUserInfo(Application["dropBoxClientObj"]);

                        lblDropBoxAccountName.Text = DropBoxConnector.objDropBoxUser.AccountDisplayName;

                        DropBoxGridDataBind((List <string>)Session["FolderPath"]);
                    }
                }
            }

            //******************************************************************************************************
            //*** Exact Online Part
            //******************************************************************************************************
            //*** First Time
            if (!Page.IsPostBack)
            {
                //*** Initialization
                divExactOnlineAlert.Visible         = false;
                lnkbtnConnectExactOnline.Visible    = false;
                lnkbtnDisconnectExactOnline.Visible = false;
                DivDropBoxFileGrid.Visible          = false;

                //*** Adjust Drop Box Call Back URL for
                if (HttpContext.Current.Session["exactOnlineReturnBackURL"] == null)
                {
                    HttpContext.Current.Session["exactOnlineReturnBackURL"] = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host;
                    if (HttpContext.Current.Request.Url.Port > 0)
                    {
                        HttpContext.Current.Session["exactOnlineReturnBackURL"] += ":" + HttpContext.Current.Request.Url.Port.ToString();
                    }
                    ;
                    HttpContext.Current.Session["exactOnlineReturnBackURL"] += "/" + System.Configuration.ConfigurationManager.AppSettings["exactOnlineReturnPage"];
                }

                //*** Check If Code returned into Connection String
                if (Application["ExactOnlineAccessToken"] == null && Session["ExactOnlineReturnCode"] != null)
                {
                    //**** Initialize Session Folder Path
                    List <string> Dump = new List <string> {
                    };
                    Session["ExactOnlineFolderPath"] = Dump;

                    //**** Construct Exact Online Class
                    ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                    Application["ExactOnlineAccessToken"] = objExactOnlineConnector.GetAccessToken();

                    if (objExactOnlineConnector.MsgError != "")
                    {   //*** If Error returned
                        lblExactOnlineMsg.Text = objExactOnlineConnector.MsgError;

                        //*** Show Error
                        divExactOnlineAlert.Visible = true;

                        return;
                    }
                }
                //******************************************************

                //*** Check ExactOnline Aurhentication Token
                if (Application["ExactOnlineAccessToken"] == null)
                {
                    //***************************
                    //*** access token is empty
                    //***************************
                    //*** 1. Check first for ExactOnline App Key & App secret
                    if (String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"]) ||
                        String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"]) ||
                        String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"]))
                    {
                        //*** Show Error Message
                        lblExactOnlineMsg.Text = "Please set client id, client secret and end point URL into this project's Web.config file and restart. " +
                                                 "client id/secret can be found in the ExactOnline App Console, here: " +
                                                 "https://start.exactonline.co.uk";

                        //*** Show Error
                        divExactOnlineAlert.Visible = true;

                        return;
                    }
                    else   //*** AppKey & secret exist
                    {
                        //*** Set URL Parameters
                        //strExactOnlineAuthParam = "";

                        //*** Show Connect to ExactOnline button
                        lnkbtnConnectExactOnline.Visible = true;
                    }
                }

                if (Session["ExactOnlineReturnCode"] != null)
                {
                    //**** Construct Exact Online Class
                    ExactOnlineConnector objExactOnlineConnector = new ExactOnlineConnector(System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientId"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineClientSecret"], System.Configuration.ConfigurationManager.AppSettings["exactOnlineEndPoint"], new Uri(HttpContext.Current.Session["exactOnlineReturnBackURL"].ToString()), Session["ExactOnlineReturnCode"].ToString());

                    if (Application["ExactOnlineAccessToken"] != null)
                    {
                        objExactOnlineConnector.AccessToken = Application["ExactOnlineAccessToken"].ToString();
                    }
                    //*** Get User Info
                    lblExactOnlineAccountName.Text = objExactOnlineConnector.getUserInfo().FullName;

                    if (objExactOnlineConnector.MsgError != "")
                    {   //*** If Error returned
                        lblExactOnlineMsg.Text = objExactOnlineConnector.MsgError;

                        //*** Show Error
                        divExactOnlineAlert.Visible = true;

                        return;
                    }
                    else
                    {
                        //*** Bind Folder Grid View
                        ExactOnlineGridDataBind();
                    }
                }
            }
            //*********************************************************************************************************
        }