示例#1
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"]);
                    }
                }
            }
        }
示例#2
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();
                    }
                }
            }
            //*********************************************************************************************************
        }