示例#1
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);
        }
示例#2
0
        public static bool VersionUpgrade(string sUserIDlast, bool bChkOnly)
        {
            RscStore store = new RscStore();

            string sFolder = AppLogic.csSecretsFolder + "\\" + sUserIDlast + "\\" + "Threads";

            int iOldVer = 0;

            if (!store.FolderExists(sFolder))
            {
                if (bChkOnly)
                {
                    return(true);                           //NOTHING stored yet...
                }
                store.CreateFolderPath(sFolder);
            }

            string sVersion = store.ReadTextFile(sFolder + "\\" + "Version.txt", "0");

            if (sVersion == ciCurrentVersion.ToString())
            {
                return(true);
            }

            if (bChkOnly)
            {
                return(false);
            }

            if (!Int32.TryParse(sVersion, out iOldVer))
            {
                iOldVer = 0;
            }

            // //
            //

            int iVer = iOldVer;

            for (;;)
            {
                if (iVer >= ciCurrentVersion)
                {
                    break;
                }

                switch (iVer)
                {
                case 0:
                case 100:
                case 101:
                {
                    string [] asIDs = store.GetFolderNames(sFolder, "*.*");

                    int iSubCntr = 0;

                    for (int i = 0; i < asIDs.Length; i++)
                    {
                        string sIdOrder = "";
                        sIdOrder = store.ReadTextFile(sFolder + "\\" + asIDs[i] + "\\" + "IdOrder" + ".txt", sIdOrder);
                        string [] asIdOrders = sIdOrder.Split('|');

                        iSubCntr += asIdOrders.Length;

                        string sId = asIdOrders[asIdOrders.Length - 1];

                        MyThread2 th = new MyThread2();
                        th = store.ReadXmlDataFile(sFolder + "\\" + asIDs[i] + "\\" + sId + ".xml", th);
                        if (th.ID.Length == 0)
                        {
                            return(false);                                    //FAIL!!!
                        }
                        string sTmp = "";

                        sTmp += th.DateSaved.Year.ToString();
                        sTmp += RscUtils.pad60(th.DateSaved.Month);
                        sTmp += RscUtils.pad60(th.DateSaved.Day);
                        sTmp += "_";
                        sTmp += RscUtils.pad60(th.DateSaved.Hour);
                        sTmp += RscUtils.pad60(th.DateSaved.Minute);
                        sTmp += RscUtils.pad60(th.DateSaved.Second);
                        sTmp += "_";
                        int iMs = th.DateSaved.Millisecond;
                        if (iMs < 10)
                        {
                            sTmp += "00";
                        }
                        else
                        {
                            if (iMs < 100)
                            {
                                sTmp += "0";
                            }
                        }
                        sTmp += iMs.ToString();

                        asIDs[i] = sTmp + "|" + asIDs[i];
                    }

                    asIDs = RscSort.OrderBy(asIDs, true);

                    /*
                     * StringBuilder sb = new StringBuilder();
                     */

                    string sRes = "";

                    foreach (string sID in asIDs)
                    {
                        /*
                         * sb.AppendLine( sID );
                         */

                        if (sRes.Length > 0)
                        {
                            sRes += "|";
                        }
                        sRes += sID.Substring(20);
                    }

                    /*
                     * sb.Append( "\r\n" );
                     * sb.Append( "Cntr: " + asIDs.Length.ToString() + "\r\n" );
                     * sb.Append( "Sub-Cntr: " + iSubCntr.ToString() + "\r\n" );
                     * store.WriteTextFile( "A:\\GMail.txt", sb.ToString(), true );
                     */

                    store.WriteTextFile(sFolder + "\\" + "IdOrder" + ".txt", sRes, true);

                    iVer = 102;

                    break;
                }

                //Denie endless loop...
                default:
                    iVer = ciCurrentVersion;
                    break;
                }

                store.WriteTextFile(sFolder + "\\" + "Version.txt", iVer.ToString(), true);
            }

            //
            // //

            return(true);
        }