override public void Expand()
        {
            if (Expanded)
            {
                return;
            }

            if (!HasJSon)
            {
                return;
            }

            PreInserts();

            if (m_json.ID.Length > 0)
            {
                RscViewer_JSon_TreeLbItem ti = new RscViewer_JSon_TreeLbItem(Holder, this);
                ti.DetailsOnly = "RscJSonItem.ID" + ": " + m_json.ID;

                Insert(ti);
            }
            if (m_json.Description.Length > 0)
            {
                RscViewer_JSon_TreeLbItem ti = new RscViewer_JSon_TreeLbItem(Holder, this);
                ti.DetailsOnly = "RscJSonItem.Description" + ": " + m_json.Description;

                Insert(ti);
            }

            for (int i = 0; i < m_json.PropertyCount; i++)
            {
                RscJSonItemProperty oProp = m_json.GetProperty(i);

                RscViewer_JSon_TreeLbItem ti = new RscViewer_JSon_TreeLbItem(Holder, this);
                ti.DetailsOnly = oProp.Name + ": " + oProp.Value(false);

                Insert(ti);
            }

            for (int i = 0; i < m_json.ChildCount; i++)
            {
                RscJSonItem oChild = m_json.GetChild(i);

                RscViewer_JSon_TreeLbItem ti = new RscViewer_JSon_TreeLbItem(Holder, this);
                ti.m_json = oChild;

                Insert(ti);
            }

            base.Expand();
        }
Ejemplo n.º 2
0
        void m_gAuth_ResponseReceived(object sender, RscGoogleAuthEventArgs e)
        {
            string      sErr     = "";
            RscJSonItem jsonRoot = null;

            jsonRoot = RscJSon.FromResponseContetn(jsonRoot, e.Content, out sErr, e.Uri, e.ContentType);
            if (sErr.Length > 0)
            {
                //OnDone( -101 );

                // If m_gAuth_AuthenticationFailed has called,
                // this will called too!!!
                OnDone(ciAuthFail);

                return;
            }

            string sErrorCode = "";

            if (jsonRoot.ChildCount > 0)
            {
                if (jsonRoot.GetChild(0).Name == "error")
                {
                    OnDone(-102);
                    return;
                }
            }

            string sPath = AppLogic.csSecretsFolder + "\\" + m_sUserIDlast;

            //Saving threads to have older thread content...
            int iNew = AppLogic.SaveThreadData(true, sPath, jsonRoot);

            OnDone(iNew);

            //MessageBox.Show( "Completed..." );
        }
Ejemplo n.º 3
0
        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;
                    }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        public static int SaveThreadData(bool bCalledByAgent, string sPath, RscJSonItem jsonThreads)
        {
            RscJSonItem json = jsonThreads.GetChildByName("threads");

            if (json == null)
            {
                return(-200);
            }

            RscStore store = new RscStore();

            bool bFirstRun = false;

            sPath += "\\Threads";
            if (!store.FolderExists(sPath))
            {
                bFirstRun = true;

                store.CreateFolderPath(sPath);
                store.WriteTextFile(sPath + "\\" + "Version.txt", ciCurrentVersion.ToString(), true);
            }

            string sThreadIdOrder_OLD = "";

            sThreadIdOrder_OLD  = store.ReadTextFile(sPath + "\\" + "IdOrder" + ".txt", sThreadIdOrder_OLD);
            sThreadIdOrder_OLD += "|";             //ATTENTION!!! 1 of 2
            string sThreadIdOrder_NEW = "";

            int iJustAdded = 0;

            int iThCnt = json.ChildCount;

            for (int iTh = 0; iTh < iThCnt; iTh++)
            {
                RscJSonItem jsonTh = json.GetChild(iTh);

                string sID        = jsonTh.GetPropertyValue("id");
                string sHistoryID = jsonTh.GetPropertyValue("historyId");
                string sSnippet   = jsonTh.GetPropertyValue("snippet");                 //, true );

                if (sID.Length == 0 || sHistoryID.Length == 0 || sSnippet.Length == 0)
                {
                    continue;
                }

                store.CreateFolderPath(sPath + "\\" + sID);

                if (store.FileExists(sPath + "\\" + sID + "\\" + sHistoryID + ".xml"))
                {
                    //Threads arrives in reverse order, so...
                    break;
                }
                else
                {
                    sThreadIdOrder_OLD = sThreadIdOrder_OLD.Replace(sID + "|", "");                       //Removing ID
                    if (sThreadIdOrder_NEW.Length > 0)
                    {
                        sThreadIdOrder_NEW += "|";
                    }
                    sThreadIdOrder_NEW += sID;                     //Adding ID

                    string sIdOrder = "";
                    sIdOrder = store.ReadTextFile(sPath + "\\" + sID + "\\" + "IdOrder" + ".txt", "");

                    iJustAdded++;

                    MyThread2 th = new MyThread2();
                    th.ID        = sID;
                    th.HistoryID = sHistoryID;
                    th.Snippet   = sSnippet;

                    if (bFirstRun)
                    {
                        th.DateAcked = DateTime.Now;
                    }

                    store.WriteXmlDataFile(sPath + "\\" + sID + "\\" + sHistoryID + ".xml", th, true);

                    if (sIdOrder.Length > 0)
                    {
                        sIdOrder = "|" + sIdOrder;
                    }
                    sIdOrder = sHistoryID + sIdOrder;
                    store.WriteTextFile(sPath + "\\" + sID + "\\" + "IdOrder" + ".txt", sIdOrder, true);
                }
            }

            if (sThreadIdOrder_OLD.Length > 0)
            {
                //ATTENTION!!! 2 of 2
                sThreadIdOrder_OLD = sThreadIdOrder_OLD.Substring(0, sThreadIdOrder_OLD.Length - 1);
            }
            if (sThreadIdOrder_NEW.Length > 0 && sThreadIdOrder_OLD.Length > 0)
            {
                sThreadIdOrder_NEW += "|";
            }
            sThreadIdOrder_NEW += sThreadIdOrder_OLD;
            store.WriteTextFile(sPath + "\\" + "IdOrder" + ".txt", sThreadIdOrder_NEW, true);

            int iCountAll = 0;

            iCountAll  = store.ReadXmlDataFile(sPath + "\\" + "Count" + ".xml", iCountAll);
            iCountAll += iJustAdded;
            store.WriteXmlDataFile(sPath + "\\" + "Count" + ".xml", iCountAll, true);

            int iCount_NonAckAll = 0;

            iCount_NonAckAll = store.ReadXmlDataFile(sPath + "\\" + "Count_NonAck" + ".xml", iCount_NonAckAll);
            if (!bFirstRun)
            {
                iCount_NonAckAll += iJustAdded;
            }
            store.WriteXmlDataFile(sPath + "\\" + "Count_NonAck" + ".xml", iCount_NonAckAll, true);

            int iCount_NEW = 0;

            iCount_NEW = store.ReadXmlDataFile(sPath + "\\" + "Count_NEW" + ".xml", iCount_NEW);
            if (bCalledByAgent)
            {
                iCount_NEW += iJustAdded;
            }
            else if (bFirstRun)
            {
                iCount_NEW = 0;
            }
            else
            {
                iCount_NEW = 0;
            }
            store.WriteXmlDataFile(sPath + "\\" + "Count_NEW" + ".xml", iCount_NEW, true);

            return(iJustAdded);
        }