예제 #1
0
        private void m_btnInit_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (m_gAuth == null)
            {
                RscStore store = new RscStore();
                store.CreateFolderPath(csSecretsFolder);

                string sPath      = csSecretsFolder + "\\" + "client_secret.json";
                bool   bNotExists = false;
                string sJSon      = store.ReadTextFile(sPath, "", out bNotExists);
                if (bNotExists)
                {
                    MessageBox.Show("File " + sPath + " does not exists!"
                                    + "\n\n(NOTE: Drive A: reffers to Isolated Storage.)"
                                    + "\n\n(NOTE: You can download missing file from FTP Cloud. Press Tools button in Caption Bar.)");
                    return;
                }

                string      sErr = "";
                RscJSonItem json = RscJSon.FromResponseContetn(sJSon, out sErr);
                if (sErr.Length > 0)
                {
                    LogError(sErr);

                    //Try to get values needed...
                    //return;
                }

                //To see content of json...
                TreeLbItem tiJSon;
                tiJSon       = new TreeLbItem(m_aTI, null);
                tiJSon.Title = "client_secret.json";
                m_aTI.Add(tiJSon);
                tiJSon.SetResponse(json, false);

                bool bTmp;
                m_sUserIDlast = store.ReadTextFile(csSecretsFolder + "\\" + "UserIDlast.txt", "", out bTmp);


                // //
                //

                m_gAuth = new RscGoogleAuth(json,
                                            RscGoogleScopes.UserinfoEmail
                                            + " " + RscGoogleScopes.UserinfoProfile
                                            + " " + RscGoogleScopes.Gmail,
                                            webBrowser1);

                m_gAuth.Authenticated        += new EventHandler(m_gAuth_Authenticated);
                m_gAuth.AuthenticationFailed += new EventHandler(m_gAuth_AuthenticationFailed);
                m_gAuth.ShowAuthPage         += new EventHandler(m_gAuth_ShowAuthPage);
                m_gAuth.ResponseReceived     += new Ressive.GoogleApi.RscGoogleAuth.ResponseReceived_EventHandler(m_gAuth_ResponseReceived);

                m_gAuth.AuthResult = LoadAuthResult();

                //
                // //


                m_btnInit.Visibility = Rsc.Collapsed;

                m_btnExpandAll.Visibility   = Rsc.Visible;
                m_btnCollapseAll.Visibility = Rsc.Visible;

                //DO NOT!!!
                //m_btnLogOut.Visibility = Rsc.Visible;

                m_AppFrame.StatusText = "Initialized...";

                // //
                //

                TreeLbItem ti;

                ti    = new TreeLbItem(m_aTI, null);
                ti.gr = GoogleRequest.UserInfo;
                m_aTI.Add(ti);

                if (m_sUserIDlast.Length > 0)
                {
                    AddRootContainers();
                }

                //
                // //
            }
        }
예제 #2
0
        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);
        }