Exemple #1
0
        private void DoExpCol(object sender)
        {
            Button     btn = (Button)sender;
            TreeLbItem ti  = (TreeLbItem)btn.Tag;

            DoExpColItem(ti);
        }
Exemple #2
0
        private void TreeLbItem_BtnCustom1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Button     btn = (Button)sender;
            TreeLbItem ti  = (TreeLbItem)btn.Tag;

            DoAck(ti);
        }
Exemple #3
0
        //
        // //

        protected void DoAck(TreeLbItem ti)
        {
            if (MessageBoxResult.OK != MessageBox.Show("Do you really want to acknowledge message?\n\n(press Back to Cancel)"))
            {
                return;
            }

            if (m_sUserIDlast.Length == 0)
            {
                return;
            }

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

            RscStore store = new RscStore();

            sPath += "\\Threads";
            if (!store.FolderExists(sPath))
            {
                return;
            }

            MyThread2 th = new MyThread2();

            th = store.ReadXmlDataFile(sPath + "\\" + ti.sID + "\\" + ti.sHistoryID + ".xml", th);
            if (th.ID.Length == 0)
            {
                return;                 //FAIL!!!
            }
            th.DateAcked = DateTime.Now;

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

            ti.BtnCustom1Visibility = Rsc.Collapsed;
            ti.DetailsOfTitle       = TreeLbItemThread.DecorateSnippet(th);
            ti.ClearCustomBackColor();

            int iCount_NonAckAll = 0;

            iCount_NonAckAll = store.ReadXmlDataFile(sPath + "\\" + "Count_NonAck" + ".xml", iCount_NonAckAll);
            iCount_NonAckAll = Math.Max(0, iCount_NonAckAll - 1);
            store.WriteXmlDataFile(sPath + "\\" + "Count_NonAck" + ".xml", iCount_NonAckAll, true);

            int iCountAll = 0;

            iCountAll = store.ReadXmlDataFile(sPath + "\\" + "Count" + ".xml", iCountAll);
            UpdateSumItem(iCount_NonAckAll, iCountAll);

            m_AppFrame.StatusText = "";             //To refresh mem info...
        }
Exemple #4
0
        private void AddRootContainers()
        {
            TreeLbItem ti;

            // //
            //

            if (!AppLogic.VersionUpgrade(m_sUserIDlast, true))
            {
                ti                 = new TreeLbItem(m_aTI, null);
                ti.Title           = "Local Data - Version Upgrade needed...";
                ti.sID             = csVerUp;
                ti.CustomBackColor = Colors.Red;
                ti.CustomForeColor = Colors.Yellow;
                m_aTI.Add(ti);

                return;
            }

            //
            // //

            /*
             * ti = new TreeLbItem( m_aTI, null );
             * ti.gr = GoogleRequest.GMail_Messages;
             * m_aTI.Add( ti );
             *
             * ti = new TreeLbItem( m_aTI, null );
             * ti.gr = GoogleRequest.GMail_Labels;
             * m_aTI.Add( ti );
             */

            ti       = new TreeLbItem(m_aTI, null);
            ti.Title = "Reload Google-API threads...";
            ti.gr    = GoogleRequest.GMail_Threads;
            m_aTI.Add(ti);

            DoExpColItem(ti);

            /*
             * ti = new TreeLbItem( m_aTI, null );
             * ti.gr = GoogleRequest.GMail_History;
             * m_aTI.Add( ti );
             *
             * ti = new TreeLbItem( m_aTI, null );
             * ti.gr = GoogleRequest.GMail_Drafts;
             * m_aTI.Add( ti );
             */
        }
        override public void Expand()
        {
            if (Expanded)
            {
                return;
            }

            if (sID.Length == 0 || sHistoryID.Length == 0)
            {
                base.Expand();
                return;
            }

            PreInserts();

            foreach (MyThread2 thSub in m_a)
            {
                TreeLbItem tiSub = new TreeLbItem(Holder, this);
                //
                tiSub.sID        = thSub.ID;
                tiSub.sHistoryID = thSub.HistoryID;
                //
                tiSub.DetailsFontSize  = DetailsFontSize;
                tiSub.DetailsBackColor = Holder.Theme.ThemeColors.TextDarkBack;
                tiSub.DetailsForeColor = Holder.Theme.ThemeColors.TextDarkFore;
                if (!thSub.Acknowledged)
                {
                    tiSub.CustomBackColor = Colors.Orange;

                    tiSub.BtnCustom1Visibility = Rsc.Visible;
                }
                tiSub.BtnCustom1Image = BtnCustom1Image;
                //
                tiSub.Title          = RscUtils.toDateDiff(thSub.DateSaved);
                tiSub.DetailsOfTitle = TreeLbItemThread.DecorateSnippet(thSub);
                tiSub.IsLeaf         = true;

                Insert(tiSub);
            }

            base.Expand();
        }
        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();
        }
Exemple #7
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);
                    }
                }
            }
        }
Exemple #8
0
        private void DoLoad(TreeLbItem ti, string sContent, string sID, string sDetails, bool bSaveJSon, out bool bAddRootContainers)
        {
            bAddRootContainers = false;

            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:
                    {
                        if (sErr.Length > 0 || (gr != GoogleRequest.GMail_Threads))
                        {
                            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(AppLogic.csSecretsFolder + "\\" + "UserIDlast.txt", m_sUserIDlast, true);

                                    bAddRootContainers = true;
                                }
                            }
                        }

                        string sPath = "";
                        string sFn   = "";
                        if (m_sUserIDlast.Length > 0)
                        {
                            sPath = AppLogic.csSecretsFolder + "\\" + m_sUserIDlast;
                            sFn   = Uri2FileName(jsonRoot.ID);
                        }
                        if (bSaveJSon)
                        {
                            if (m_sUserIDlast.Length > 0)
                            {
                                //ATT: We need up to date data always!!!
                                if (gr == GoogleRequest.UserInfo)
                                {
                                    store.CreateFolderPath(sPath);

                                    store.WriteTextFile(sPath + "\\" + sFn + ".json", sContent, true);

                                    m_btnCleanUp.Visibility = Rsc.Visible;
                                }
                                //ATT: We need up to date data always!!!


                                if (gr == GoogleRequest.GMail_Threads)
                                {
                                    if (sErr.Length == 0)
                                    {
                                        //Saving threads to have older thread content...
                                        AppLogic.SaveThreadData(false, sPath, jsonRoot);

                                        m_btnCleanUp.Visibility = Rsc.Visible;

                                        ShowSavedThreadData(sPath, 0);
                                    }
                                }
                            }
                        }

                        if (sErr.Length == 0)
                        {
                            if (sFn.Length > 0)
                            {
                                if (bSaveJSon)
                                {
                                    m_AppFrame.StatusText = "Downloaded...";                                             // + sPath + "\\" + sFn + ".json";
                                }
                                else
                                {
                                    m_AppFrame.StatusText = "Loaded...";                                             // + sPath + "\\" + sFn + ".json";
                                }
                            }
                            else
                            {
                                if (bSaveJSon)
                                {
                                    m_AppFrame.StatusText = "Downloaded...";
                                }
                                else
                                {
                                    m_AppFrame.StatusText = "Loaded...";
                                }
                            }
                        }

                        break;
                    }

                    default:
                    {
                        //Unexpected...
                        LogError(jsonRoot.ToDecoratedString());
                        break;
                    }
                    }
                }
            }
        }
Exemple #9
0
        private void m_btnInit_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (m_gAuth == null)
            {
                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)
                {
                    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 );
                 */

                m_sUserIDlast = store.ReadTextFile(AppLogic.csSecretsFolder + "\\" + "UserIDlast.txt", "");


                // //
                //

                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);

                //bool bNotExists;
                m_gAuth.AuthResult = AppLogic.LoadAuthResult(out bNotExists);

                if (!bNotExists)
                {
                    //ATT: Logged ON!!!
                    m_btnLogOut.Visibility = Rsc.Visible;
                }

                //
                // //


                m_btnInit.Visibility = Rsc.Collapsed;

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

                m_btnAddTile.Visibility = Rsc.Visible;

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

                m_AppFrame.StatusText = "Initialized...";

                // //
                //

                TreeLbItem ti;

                ti       = new TreeLbItem(m_aTI, null);
                ti.Title = "User Profile";
                ti.gr    = GoogleRequest.UserInfo;
                m_aTI.Add(ti);

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

                //
                // //
            }
        }
Exemple #10
0
        private void ShowSavedThreadData(string sPath, int iStartIndex, TreeLbItem tiHead = null)
        {
            RscStore store = new RscStore();

            sPath += "\\Threads";
            if (!store.FolderExists(sPath))
            {
                return;
            }

            int iCountAll = 0;

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

            int iCount_NonAckAll = 0;

            iCount_NonAckAll = store.ReadXmlDataFile(sPath + "\\" + "Count_NonAck" + ".xml", iCount_NonAckAll);

            if (iStartIndex == 0)
            {
                m_tiSum = new TreeLbItem(m_aTI, null);
                m_tiSum.DetailsFontSize = cdFontSize;
                UpdateSumItem(iCount_NonAckAll, iCountAll);
                m_aTI.Add(m_tiSum);

                tiHead = new TreeLbItem(m_aTI, null);
                //tiHead.DetailsFontSize = cdFontSize;
                tiHead.DetailsOnly = "...";
                m_aTI.Add(tiHead);
            }

            string sThreadIdOrder = "";

            sThreadIdOrder = store.ReadTextFile(sPath + "\\" + "IdOrder" + ".txt", sThreadIdOrder);
            string [] asThreadIdOrders = sThreadIdOrder.Split('|');

            bool bMoreItems = false;
            int  iThCnt     = asThreadIdOrders.Length;

            for (int iTh = iStartIndex; iTh < iThCnt; iTh++)
            {
                //NOT all...
                if ((iTh - iStartIndex) >= ciMaxAtOnce)
                {
                    bMoreItems = true;
                    break;
                }

                string sID = asThreadIdOrders[iTh];

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

                if (!store.FolderExists(sPath + "\\" + sID))
                {
                    continue;
                }

                string sIdOrder = "";
                sIdOrder = store.ReadTextFile(sPath + "\\" + sID + "\\" + "IdOrder" + ".txt", sIdOrder);
                string [] asIdOrders = sIdOrder.Split('|');

                string sHistoryID = asIdOrders[0];

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

                if (!store.FileExists(sPath + "\\" + sID + "\\" + sHistoryID + ".xml"))
                {
                    continue;
                }

                MyThread2 th = new MyThread2();
                th = store.ReadXmlDataFile(sPath + "\\" + sID + "\\" + sHistoryID + ".xml", th);
                if (th.ID.Length == 0)
                {
                    continue;
                }

                TreeLbItem ti = new TreeLbItem(m_aTI, null);
                //
                ti.DetailsFontSize  = cdFontSize;
                ti.DetailsBackColor = m_AppFrame.Theme.ThemeColors.TextDarkBack;
                ti.DetailsForeColor = m_AppFrame.Theme.ThemeColors.TextDarkFore;
                if (!th.Acknowledged)
                {
                    ti.CustomBackColor = Colors.Orange;

                    ti.BtnCustom1Visibility = Rsc.Visible;
                }
                ti.BtnCustom1Image = m_isCheckOn;                 //Off;
                //
                string sTitle = "";
                sTitle += RscUtils.toDateDiff(th.DateSaved);
                if (asIdOrders.Length > 1)
                {
                    sTitle += " ( +" + (asIdOrders.Length - 1).ToString() + " )";
                }
                ti.Title          = sTitle;
                ti.DetailsOfTitle = TreeLbItemThread.DecorateSnippet(th);
                ti.IsLeaf         = (asIdOrders.Length <= 1);
                m_aTI.Add(ti);

                ti.sID        = sID;
                ti.sHistoryID = sHistoryID;

                foreach (string sId in asIdOrders)
                {
                    if (sId.Length == 0)
                    {
                        continue;
                    }
                    if (sId == sHistoryID)
                    {
                        continue;
                    }

                    MyThread2 thSub = new MyThread2();
                    thSub = store.ReadXmlDataFile(sPath + "\\" + sID + "\\" + sId + ".xml", thSub);
                    if (thSub.ID.Length == 0)
                    {
                        continue;
                    }

                    //DO NOT!!!

                    /*
                     * TreeLbItem tiSub = new TreeLbItem( m_aTI, ti );
                     * tiSub.Title = RscUtils.toDateDiff( thSub.DateSaved ) + "retrived...";
                     * tiSub.DetailsOfTitle = thSub.Snippet;
                     * tiSub.IsLeaf = true;
                     * m_aTI.Add( tiSub );
                     */

                    ti.m_a.Add(thSub);
                }
            }

            if (tiHead != null)
            {
                string sTit = "Threads " + (iStartIndex + 1).ToString() + " - ";
                if (bMoreItems)
                {
                    sTit += (iStartIndex + ciMaxAtOnce).ToString();
                }
                else
                {
                    sTit += iThCnt.ToString();
                }

                //tiHead.DetailsFontSize = cdFontSize;
                tiHead.DetailsOnly = sTit;
            }

            if (bMoreItems)
            {
                TreeLbItem ti = new TreeLbItem(m_aTI, null);
                ti.Title           = "Threads " + (iStartIndex + ciMaxAtOnce + 1).ToString() + " - ... (press to list)";
                ti.sID             = csMoreItems;
                ti.sHistoryID      = (iStartIndex + ciMaxAtOnce).ToString();
                ti.CustomBackColor = m_AppFrame.Theme.ThemeColors.TreeDescBack;
                ti.CustomForeColor = m_AppFrame.Theme.ThemeColors.TreeDescFore;
                m_aTI.Add(ti);
            }
        }