private static void TestWriteByKey() { var titles = new[] { "Заголовок1", "Заголовок2", "Заголовок3", "Заголовок4", null, "Время обновления" }; var items = new Dictionary <string, object[]> { { "Key1", new object[] { "Value1", 1, 1.1, (decimal)2.1, null, DateTime.Now } }, { "Key2", new object[] { "Value2", 2, 2.2, (decimal)2.2, null, DateTime.Now } }, }; var client = GetClient(); //client.DateTimeFormat = "dd.MM.yyyy"; GoogleUtils.WriteByKey(client, "WriteByKey", 0, 1, items, titles).Wait(); }
override public string GetTitle() { if (gr != GoogleRequest.None) { return(GoogleUtils.GoogleRequestTitle(gr)); } if (m_jsonResponse != null) { return(m_jsonResponse.Name); } return("N/A"); }
public async Task GetRefreshToken_ManualTest() { var token = await GoogleUtils.GetRefreshToken(ClientId, ClientSecret, "IA.Episodes", GoogleScopes.Youtube); Assert.IsNotNullOrEmpty(token); }
private void DoExpCol(object sender) { Button btn = (Button)sender; TreeLbItem ti = (TreeLbItem)btn.Tag; if (ti.gr == GoogleRequest.None && (!ti.HasResponse)) { return; //Nothing to load... } if (ti.Expanded) { ti.Collapse(); } else { if (ti.HasResponse) { ti.Expand(); } else { if (m_tiLoading != null) { MessageBox.Show("Load in progress!\n\nPlease wait..."); return; } string id = ""; if (ti.Parameters != null) { id = ti.Parameters.GetPropertyValue("id"); } string sUriResource = ""; string sBaseUrl = GoogleUtils.GoogleRequestBaseUrl(ti.gr, out sUriResource, "me", id); if (sBaseUrl.Length == 0) { MessageBox.Show("No Request Url found!"); return; } bool bLoadedFromFile = false; if (m_sUserIDlast.Length > 0) { string sPath = csSecretsFolder + "\\" + m_sUserIDlast; RscStore store = new RscStore(); store.CreateFolderPath(sPath); string sFn = Uri2FileName(sBaseUrl + sUriResource); bool bTmp; string sJSon = store.ReadTextFile(sPath + "\\" + sFn + ".json", "", out bTmp); if (sJSon.Length > 0) { DoLoad(ti, sJSon, sBaseUrl + sUriResource, "", false); m_btnCleanUp.Visibility = Rsc.Visible; bLoadedFromFile = true; } } if (!bLoadedFromFile) { m_tiLoading = ti; m_tiLoading.Loading = true; //VERY SLOW!!! //m_aTI.Refresh(); m_gAuth.SendRequest(sBaseUrl, sUriResource); } } } }
private void DoLoad(TreeLbItem ti, string sContent, string sID, string sDetails, bool bSaveJSon) { string sErr = ""; RscJSonItem jsonRoot = null; /* * jsonRoot = new RscJSonItem(); * jsonRoot.ID = response.ResponseUri.ToString(); * jsonRoot.Name = "IRestResponse<Object>"; * jsonRoot.AddProperty( "Response Status", response.ResponseStatus.ToString() ); * jsonRoot.AddProperty( "Response Uri", response.ResponseUri.ToString() ); * jsonRoot.AddProperty( "Content Length", response.ContentLength.ToString() ); */ jsonRoot = RscJSon.FromResponseContetn(jsonRoot, sContent, out sErr, sID, sDetails); if (sErr.Length > 0) { LogError(sErr); } if (jsonRoot != null) { // // // string sErrorCode = ""; if (jsonRoot.ChildCount > 0) { if (jsonRoot.GetChild(0).Name == "error") { //For example: Required Scope not specified while LogOn!!! sErrorCode = jsonRoot.GetChildPropertyValue(0, "code"); string sErrorMessage = jsonRoot.GetChildPropertyValue(0, "message"); LogError("Error response:\ncode: " + sErrorCode + "\nmessage: " + sErrorMessage); } } // // // //Show Error JSon!!! //if( sErrorCode.Length == 0 ) { //Try to load result as is... GoogleRequest gr = GoogleUtils.GoogleRequestFromUrl(jsonRoot.ID); switch (gr) { case GoogleRequest.UserInfo: case GoogleRequest.GMail_Messages: case GoogleRequest.GMail_Message_Details: case GoogleRequest.GMail_Labels: case GoogleRequest.GMail_Threads: case GoogleRequest.GMail_History: case GoogleRequest.GMail_Drafts: { ti.SetResponse(jsonRoot); RscStore store = new RscStore(); if (gr == GoogleRequest.UserInfo) { string sUserID = jsonRoot.GetPropertyValue("id"); if (m_sUserIDlast.Length == 0 || m_sUserIDlast != sUserID) { if (sUserID.Length > 0) { m_sUserIDlast = sUserID; store.WriteTextFile(csSecretsFolder + "\\" + "UserIDlast.txt", m_sUserIDlast, true); AddRootContainers(); } } } string sPath = ""; string sFn = ""; if (m_sUserIDlast.Length > 0) { sPath = csSecretsFolder + "\\" + m_sUserIDlast; sFn = Uri2FileName(jsonRoot.ID); } if (bSaveJSon) { if (m_sUserIDlast.Length > 0) { store.CreateFolderPath(sPath); store.WriteTextFile(sPath + "\\" + sFn + ".json", sContent, true); m_btnCleanUp.Visibility = Rsc.Visible; } } if (sErr.Length == 0) { if (sFn.Length > 0) { if (bSaveJSon) { m_AppFrame.StatusText = "Downloaded to " + sPath + "\\" + sFn + ".json"; } else { m_AppFrame.StatusText = "Loaded from " + sPath + "\\" + sFn + ".json"; } } else { if (bSaveJSon) { m_AppFrame.StatusText = "Downloaded..."; } else { m_AppFrame.StatusText = "Loaded..."; } } } break; } default: { //Unexpected... LogError(jsonRoot.ToDecoratedString()); break; } } } } }
override public void Expand() { if (Expanded) { return; } if (!HasResponse) { base.Expand(); return; } PreInserts(); if (m_jsonResponse.ID.Length > 0) { TreeLbItem ti = new TreeLbItem(Holder, this); ti.DetailsOnly = "RscJSonItem.ID" + ": " + m_jsonResponse.ID; ti.DetailsBackColor = Colors.Gray; ti.DetailsForeColor = Colors.Black; Insert(ti); } if (m_jsonResponse.Description.Length > 0) { TreeLbItem ti = new TreeLbItem(Holder, this); ti.DetailsOnly = "RscJSonItem.Description" + ": " + m_jsonResponse.Description; ti.DetailsBackColor = Colors.Gray; ti.DetailsForeColor = Colors.Black; Insert(ti); } if (m_jsonParameters != null) { //Response properties inherited from parent to get this response... for (int i = 0; i < m_jsonParameters.PropertyCount; i++) { RscJSonItemProperty oProp = m_jsonParameters.GetProperty(i); TreeLbItem ti = new TreeLbItem(Holder, this); ti.DetailsOnly = oProp.Name + ": " + oProp.Value(false); ti.DetailsBackColor = Colors.White; ti.DetailsForeColor = Colors.Black; Insert(ti); } } for (int i = 0; i < m_jsonResponse.PropertyCount; i++) { RscJSonItemProperty oProp = m_jsonResponse.GetProperty(i); TreeLbItem ti = new TreeLbItem(Holder, this); ti.DetailsOnly = oProp.Name + ": " + oProp.Value(false); Insert(ti); } GoogleRequest grParent = GoogleRequest.None; if (Parent != null) { if (((TreeLbItem)Parent).Response != null) { grParent = GoogleUtils.GoogleRequestFromUrl(((TreeLbItem)Parent).Response.ID); } } for (int i = 0; i < m_jsonResponse.ChildCount; i++) { RscJSonItem oChild = m_jsonResponse.GetChild(i); TreeLbItem ti = new TreeLbItem(Holder, this); /* * if( m_jsonResponse.Name != "error" ) * { */ switch (grParent) { case GoogleRequest.GMail_Messages: { if (m_jsonResponse.Name == "messages") { //Downloadable, but with parameters... ti.gr = GoogleRequest.GMail_Message_Details; ti.m_jsonParameters = oChild; } else { ti.m_jsonResponse = oChild; } break; } default: { //Allowe to expand item... ti.m_jsonResponse = oChild; break; } } /* * } * else * { * ti.m_jsonResponse = oChild; * } */ Insert(ti); } base.Expand(); }
public int ReadThreadData() { RscStore store = new RscStore(); store.CreateFolderPath(AppLogic.csSecretsFolder); string sPath = AppLogic.csSecretsFolder + "\\" + "client_secret.json"; bool bNotExists = false; string sJSon = store.ReadTextFile(sPath, "", out bNotExists); if (bNotExists) { return(-2); } string sErr = ""; RscJSonItem json = RscJSon.FromResponseContetn(sJSon, out sErr); if (sErr.Length > 0) { //Try to get values needed... //return -3; } m_sUserIDlast = store.ReadTextFile(AppLogic.csSecretsFolder + "\\" + "UserIDlast.txt", ""); if (m_sUserIDlast.Length == 0) { return(-3); } // // // //if( gAuth == null ) //{ RscGoogleAuth gAuth = new RscGoogleAuth(json, RscGoogleScopes.UserinfoEmail + " " + RscGoogleScopes.UserinfoProfile + " " + RscGoogleScopes.Gmail, null); //webBrowser1 ); gAuth.Authenticated += new EventHandler(m_gAuth_Authenticated); gAuth.AuthenticationFailed += new EventHandler(m_gAuth_AuthenticationFailed); gAuth.ShowAuthPage += new EventHandler(m_gAuth_ShowAuthPage); gAuth.ResponseReceived += new Ressive.GoogleApi.RscGoogleAuth.ResponseReceived_EventHandler(m_gAuth_ResponseReceived); //bool bNotExists; gAuth.AuthResult = LoadAuthResult(out bNotExists); if (bNotExists) { return(-4); } //} // // // string sUriResource = ""; string sBaseUrl = GoogleUtils.GoogleRequestBaseUrl(GoogleRequest.GMail_Threads, out sUriResource, "me", ""); if (sBaseUrl.Length == 0) { return(-5); } /* * Object oRes = null; * var taskHlp = Task.Run(async () => { oRes = await m_gAuth.SendRequestTask( sBaseUrl, sUriResource ); }); * taskHlp.Wait(); * * if( oRes == null ) * return -6; * else * return oRes.ToString().Length; */ //Task<Object> tsk = gAuth.SendRequestTask( sBaseUrl, sUriResource ); //tsk.Wait(); /* * int iRet = 0; * var taskHlp = Task.Run(async () => { iRet = await SendRequestTask( gAuth, sBaseUrl, sUriResource ); }); * taskHlp.Wait(); */ /* * Task<Object> tsk = gAuth.SendRequestTask( sBaseUrl, sUriResource ); * for(;;) * { * if( tsk.IsCompleted ) * break; * * //System.Threading.Tasks.Task.Delay(100).Wait(); * * MessageBox.Show( "Not complete..." ); * } */ try { gAuth.SendRequest(sBaseUrl, sUriResource); } catch (Exception) { return(-6); } return(0); }
private void DoExpColItem(TreeLbItem ti) { if (ti.gr == GoogleRequest.None && (!ti.HasResponse)) { if (ti.Expanded) { ti.Collapse(); } else if (!ti.IsLeaf && !ti.IsDetailsOnly) { if (ti.sID == csVerUp) { if (m_tiLoading != null) { MessageBox.Show("Load in progress!\n\nPlease wait..."); return; } m_tiLoading = ti; m_tiLoading.Loading = true; m_AppFrame.StartTimer(csVerUp, LayoutRoot, 1, 0, false); } else if (ti.sID == csMoreItems) { int iStartIndex = Int32.Parse(ti.sHistoryID); string sPath = AppLogic.csSecretsFolder + "\\" + m_sUserIDlast; ShowSavedThreadData(sPath, iStartIndex, ti); } else { ti.Expand(); } } return; //Nothing to load... } if (ti.Expanded) { ti.Collapse(); } else { if (ti.HasResponse) { ti.Expand(); } else { if (m_tiLoading != null) { MessageBox.Show("Load in progress!\n\nPlease wait..."); return; } string id = ""; if (ti.Parameters != null) { id = ti.Parameters.GetPropertyValue("id"); } string sUriResource = ""; string sBaseUrl = GoogleUtils.GoogleRequestBaseUrl(ti.gr, out sUriResource, "me", id); if (sBaseUrl.Length == 0) { MessageBox.Show("No Request Url found!"); return; } bool bLoadedFromFile = false; if (m_sUserIDlast.Length > 0) { if (ti.gr != GoogleRequest.GMail_Threads) { string sPath = AppLogic.csSecretsFolder + "\\" + m_sUserIDlast; RscStore store = new RscStore(); store.CreateFolderPath(sPath); string sFn = Uri2FileName(sBaseUrl + sUriResource); bool bTmp; string sJSon = store.ReadTextFile(sPath + "\\" + sFn + ".json", "", out bTmp); if (sJSon.Length > 0) { bool bTmp2; DoLoad(ti, sJSon, sBaseUrl + sUriResource, "", false, out bTmp2); m_btnCleanUp.Visibility = Rsc.Visible; bLoadedFromFile = true; } } } if (!bLoadedFromFile) { if (ti.gr == GoogleRequest.GMail_Threads) { m_tiSum = null; m_aTI.RemoveAll(ti); } m_tiLoading = ti; m_tiLoading.Loading = true; //VERY SLOW!!! //m_aTI.Refresh(); m_gAuth.SendRequest(sBaseUrl, sUriResource); } } } }