예제 #1
0
        public List <FileListModel> GetGoogleDriveList(int planId, string directory, PlatformInsertModel planData)
        {
            PlatformGoogle gg = new PlatformGoogle(_env.ContentRootPath);



            dynamic platformDetail = JObject.Parse(planData.JsonData);
            string  token          = "";

            if (WebUtilities.ConvertDatabaseDateTime(platformDetail.tokenExpire.ToString()) > DateTime.Now)
            {
                token = platformDetail.accessToken;
            }
            else
            {
                var trp = gg.AuthCodeToAccessToken("", "", platformDetail.refreshToken.ToString());

                dynamic dData = null;
                if (!String.IsNullOrEmpty(planData.JsonData))
                {
                    dData = JObject.Parse(planData.JsonData);
                }

                List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();
                list.Add(new KeyValuePair <string, string>("accountId", planId.ToString()));
                list.Add(new KeyValuePair <string, string>("accessToken", trp.AccessToken));
                if (!String.IsNullOrEmpty(trp.RefreshToken))
                {
                    list.Add(new KeyValuePair <string, string>("refreshToken", trp.RefreshToken));
                }
                else if (dData != null)
                {
                    list.Add(new KeyValuePair <string, string>("refreshToken", dData.refreshToken.ToString()));
                }
                list.Add(new KeyValuePair <string, string>("tokenExpire", DateTime.Now.AddSeconds(trp.ExpiresInSeconds).ToString()));
                string jsonData = "";
                foreach (var item in list)
                {
                    string header = item.Key;
                    string data   = item.Value;
                    jsonData += "\"" + header + "\": \"" + data + "\",";
                }
                jsonData = jsonData.Substring(0, jsonData.Length - 1);
                jsonData = "{ " + jsonData + " }";

                planData.JsonData = jsonData;
                operations.Plan.UpdatePlan(planData, GetOrganizationId());

                token = trp.AccessToken;
            }
            GoogleDriveAuthInformation inf = new GoogleDriveAuthInformation()
            {
                access_token = token
            };

            return(gg.GetDirectoryList(directory, inf.access_token));
        }