public NQDetails GetNQEvent()
        {
            string query = "SELECT * FROM " + EVENT_TABLE_NAME + " WHERE " + EVENT_ORIGIN + " = 'N' ORDER BY " + EVENT_INDEX + " LIMIT 1;";
            LogWrapper.LogMessage("DBHandler - GetNQEvent", "Running query: " + query);
            NQDetails item = null;

            SQLiteConnection sqlConnection = OpenConnection();
            SQLiteCommand sqlCommand = new SQLiteCommand(query, sqlConnection);
            SQLiteDataReader sqlDataReader = null;
            try
            {
                sqlDataReader = sqlCommand.ExecuteReader();
                while (sqlDataReader.Read())
                {
                    item = new NQDetails();
                    PopulateNQEventFromReader(ref item, ref sqlDataReader);
                }
            }
            catch (Exception ex)
            {
                LogWrapper.LogMessage("DbHandler - GetNQEvent", "Caught exception: " + ex.Message);
                item = null;
            }

            if (null != sqlDataReader)
                sqlDataReader.Close();
            sqlConnection.Close();

            return item;
        }
        public int AddNQEvent(NQDetails nqEvent)
        {
            int result = -1;
            string query = "insert into " + EVENT_TABLE_NAME + " (" +
                            EVENT_ORIGIN + ", " +
                            EVENT_NQ_SIZE + ", " +
                            EVENT_NQ_DOMAIN_URI + ", " +
                            EVENT_NQ_EVENT + ", " +
                            EVENT_NQ_RESULT + ", " +
                            EVENT_NQ_TIME + ", " +
                            EVENT_NQ_USER + ", " +
                            EVENT_NQ_HASH + ", " +
                            EVENT_NQ_EXPORTED_PATH + ", " +
                            EVENT_NQ_ID + ", " +
                            EVENT_NQ_NAME + ", " +
                            EVENT_NQ_OBJ_TYPE + ", " +
                            EVENT_NQ_PARENT_ID + ", " +
                            EVENT_NQ_PARENT_URI + ") values ('N', " +
                            nqEvent.lSize + ",'" +
                            nqEvent.StrDomainUri + "','" +
                            nqEvent.StrEvent + "','" +
                            nqEvent.StrEventResult + "','" +
                            nqEvent.StrEventTime + "','" +
                            nqEvent.StrEventUser + "','" +
                            nqEvent.StrHash + "','" +
                            EscapeString(nqEvent.StrMezeoExportedPath) + "','" +
                            nqEvent.StrObjectID + "','" +
                            EscapeString(nqEvent.StrObjectName) + "','" +
                            nqEvent.StrObjectType + "','" +
                            nqEvent.StrParentID + "','" +
                            nqEvent.StrParentUri + "');";

            SQLiteConnection sqlConnection = OpenConnection();
            SQLiteCommand sqlCommand = new SQLiteCommand(query, sqlConnection);
            LogWrapper.LogMessage("DBHandler - AddNQEvent", "Running query: " + query);

            result = sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();

            // Increment the job count.
            if (0 < result)
                IncrementJobCount();

            // A result of 1 is success (# of rows affected and we should
            // only have 1), not the index of the newly created entry.
            return result;
        }
        public void PopulateNQEventFromReader(ref NQDetails item, ref SQLiteDataReader sqlDataReader)
        {
            item.EventDbId = (Int64)sqlDataReader[EVENT_INDEX];

            item.lSize = (long)sqlDataReader[EVENT_NQ_SIZE];
            item.StrDomainUri = (string)sqlDataReader[EVENT_NQ_DOMAIN_URI];
            item.StrEvent = (string)sqlDataReader[EVENT_NQ_EVENT];
            item.StrEventResult = (string)sqlDataReader[EVENT_NQ_RESULT];
            item.StrEventTime = (string)sqlDataReader[EVENT_NQ_TIME];
            item.StrEventUser = (string)sqlDataReader[EVENT_NQ_USER];
            item.StrHash = (string)sqlDataReader[EVENT_NQ_HASH];
            item.StrMezeoExportedPath = (string)sqlDataReader[EVENT_NQ_EXPORTED_PATH];
            item.StrObjectID = (string)sqlDataReader[EVENT_NQ_ID];
            item.StrObjectName = (string)sqlDataReader[EVENT_NQ_NAME];
            item.StrObjectType = (string)sqlDataReader[EVENT_NQ_OBJ_TYPE];
            item.StrParentID = (string)sqlDataReader[EVENT_NQ_PARENT_ID];
            item.StrParentUri = (string)sqlDataReader[EVENT_NQ_PARENT_URI];
        }
        private int UpdateFromNQ(NQDetails UpdateQ)
        {
            //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", "Enter");

            NQDetails nqDetail = UpdateQ;
            int nStatus = 0;

            int nStatusCode = 0;
            NSResult nsResult = null;

            //Encoding uri for special character and then replacing "+" with "%20" if we have spaces in file name
            string uri = cLoginDetails.szNamespaceUri + "/" + HttpUtility.UrlEncode(nqDetail.StrMezeoExportedPath);
            uri = uri.Replace("+", "%20");

            //nsResult = cMezeoFileCloud.GetNamespaceResult(cLoginDetails.szNamespaceUri + "/" +
            //                                                nqDetail.StrMezeoExportedPath,
            //                                                nqDetail.StrObjectType, ref nStatusCode);

            nsResult = cMezeoFileCloud.GetNamespaceResult(uri, nqDetail.StrObjectType, ref nStatusCode);
            if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
            {
                return nStatusCode;
            }
            else if (nStatusCode != ResponseCode.GETNAMESPACERESULT && nStatusCode != ResponseCode.NOTFOUND)
            {
                return nStatusCode;
            }

            if (nsResult == null && nqDetail.StrEvent != "cdmi_delete")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", "nsResult Null");
                nStatus = 1;
                return nStatus;
            }

            if (nqDetail.StrObjectName == "csp_recyclebin")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - skipping csp_recyclebin notification.", "csp_recyclebin notification skipped");
                nStatus = 1;
                return nStatus;
            }

            int startIndex = Math.Min(cLoginDetails.szNQParentUri.Length + 1, nqDetail.StrParentUri.Length);
            string strPath = nqDetail.StrParentUri.Substring(startIndex);
            string strKey = strPath.Replace("/" , "\\");

            if(nsResult == null)
                strKey += nqDetail.StrObjectName;
            else
                strKey += nsResult.StrName;

            strPath = BasicInfo.SyncDirPath + "\\" + strKey;
            //lblStatusL3.Text = strPath;

            if (nqDetail.StrEvent == "cdmi_create_complete")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Enter");

                string strDBKey = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, new string[] { DbHandler.CONTENT_URL }, new string[] { nsResult.StrContentsUri }, new DbType[] { DbType.String });

                // Just because the length is 0 doesn't make it the only reason to download the file.
                // Check the file size against the event.  If the size differs, then download the file
                // again since the local one is a partial...probably from a pause/resume.
                // The pause/resume can also result in a file that doesn't exist even though the database
                // entry does.  That condition should also be marked as a difference so that the event
                // is processed and the file is downloaded.
                bool bLocalFileDiffers = false;
                if (strDBKey.Trim().Length != 0)
                {
                    try
                    {
                        FileInfo fileInfo = new FileInfo(strPath);
                        if ((fileInfo != null) && (0 == (fileInfo.Attributes & FileAttributes.Directory)) && fileInfo.Exists && (fileInfo.Length != nqDetail.lSize))
                            bLocalFileDiffers = true;
                        if ((0 == (fileInfo.Attributes & FileAttributes.Directory)) && (!System.IO.File.Exists(strPath)))
                            bLocalFileDiffers = true;
                    }
                    catch (System.IO.PathTooLongException ex)
                    {
                        // Skip this item.
                        LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ", "Caught exception: " + ex.Message);
                        nStatus = 1;
                        return nStatus;
                    }
                }

                if ((strDBKey.Trim().Length == 0) || bLocalFileDiffers)
                {
                    nStatus = nqEventCdmiCreate(nqDetail, nsResult, strKey, strPath);
                    if (nStatus == ResponseCode.LOGINFAILED1 || nStatus == ResponseCode.LOGINFAILED2)
                    {
                        return nStatus;
                    }
                    else if (nStatus != ResponseCode.GETETAG && nStatus != ResponseCode.DOWNLOADFILE && nStatus != ResponseCode.DOWNLOADITEMDETAILS && nStatus != 1)
                    {
                        return nStatus;
                    }
                }
                else
                    nStatus = 1;

                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Leave");
            }
            else if (nqDetail.StrEvent == "cdmi_modify_complete")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Enter");

                string strDBKey = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, new string[] { DbHandler.CONTENT_URL }, new string[] { nsResult.StrContentsUri }, new DbType[] { DbType.String });
                string strDBEtag = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.E_TAG, new string[] { DbHandler.KEY }, new string[] { strDBKey }, new DbType[] { DbType.String });
                string strEtagCloud = cMezeoFileCloud.GetETag(nsResult.StrContentsUri, ref nStatusCode);
                if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
                {
                    return nStatusCode;
                }
                else if (nStatusCode != ResponseCode.GETETAG)
                {
                    return nStatusCode;
                }

                if (strKey != strDBKey)
                {
                    if (File.Exists(strPath))
                    {
                        nqEventCdmiDelete(BasicInfo.SyncDirPath + "\\" + strDBKey, strDBKey);
                    }
                    else
                    {
                        if (File.Exists(BasicInfo.SyncDirPath + "\\" + strDBKey))
                            File.Move(BasicInfo.SyncDirPath + "\\" + strDBKey, strPath);
                    }

                    // Let's update the name as well.
                    string fileName = strPath.Substring(strPath.LastIndexOf("\\") + 1);
                    dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.FILE_NAME, fileName, DbHandler.KEY, strDBKey);

                    // Update the key for the entry.
                    dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.KEY, strKey, DbHandler.KEY, strDBKey);
                }

                if (strDBEtag != strEtagCloud)
                {
                    if ("FILE" == nsResult.StrType)
                    {
                        bool bRet = cMezeoFileCloud.DownloadFile(nsResult.StrContentsUri + '/' + nsResult.StrName, strPath, nsResult.dblSizeInBytes, ref nStatusCode);
                        if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
                        {
                            return nStatusCode;
                        }
                        else if (nStatusCode != ResponseCode.DOWNLOADFILE)
                        {
                            return nStatusCode;
                        }
                        if (bRet)
                        {
                            dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.E_TAG, strEtagCloud, DbHandler.KEY, strKey);
                            bool isFileExist = File.Exists(strPath);
                            if (isFileExist)
                            {
                                FileInfo fInfo = new FileInfo(strPath);
                                dbHandler.UpdateModifiedDate(fInfo.LastWriteTime, strKey);
                            }
                        }
                    }
                }
                nStatus = 1;
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Leave");
            }
            else if (nqDetail.StrEvent == "cdmi_delete")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Enter");

                // bugzid:2352 - file is open when app gets cloud event to delete same file
                // If the file can't be deleted (due to being in use), then just keep retrying
                // until the file is released.
                if (nqEventCdmiDelete(strPath, strKey))
                    nStatus = 1;
                else
                    nStatus = 0;

                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Leave");
            }
            else if (nqDetail.StrEvent == "cdmi_rename")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Enter");

                string strDBKey = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, new string[] { DbHandler.CONTENT_URL }, new string[] { nsResult.StrContentsUri }, new DbType[] { DbType.String });
                if (strDBKey.Trim().Length != 0 && strDBKey != strKey)
                {
                    if(Directory.Exists(strPath))
                    {
                        nqEventCdmiDelete(BasicInfo.SyncDirPath + "\\" + strDBKey, strDBKey);
                    }
                    else
                    {
                        // Let's update the name as well.
                        string fileName = strPath.Substring(strPath.LastIndexOf("\\") + 1);
                        dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.FILE_NAME, fileName, DbHandler.KEY, strDBKey);

                        // Update the key for the entry.
                        Directory.Move(BasicInfo.SyncDirPath + "\\" + strDBKey, strPath);
                        dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.KEY , strKey , DbHandler.KEY , strDBKey );

                        // Update the key for the children.
                        DirectoryInfo rootDir = new DirectoryInfo(strPath);
                        WalkDirectoryTree(rootDir, BasicInfo.SyncDirPath + "\\" + strDBKey);
                    }
                }
                else if(strDBKey.Trim().Length == 0)
                {
                    nStatus = nqEventCdmiCreate(nqDetail, nsResult, strKey, strPath);
                    if (nStatus == ResponseCode.LOGINFAILED1 || nStatus == ResponseCode.LOGINFAILED2)
                    {
                        return nStatus;
                    }
                    else if (nStatus != ResponseCode.GETETAG && nStatus != ResponseCode.DOWNLOADFILE && nStatus != ResponseCode.DOWNLOADITEMDETAILS && nStatus != 1)
                    {
                        return nStatus;
                    }
                }
                nStatus = 1;
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Leave");
            }
            else if (nqDetail.StrEvent == "cdmi_copy")
            {
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Enter");

                if (strKey.LastIndexOf("\\") != -1)
                    CheckAndCreateForParentDir(strKey.Substring(0, strKey.LastIndexOf("\\")));

                FileFolderInfo fileFolderInfo = new FileFolderInfo();

                fileFolderInfo.IsPublic = nsResult.bPublic;
                fileFolderInfo.IsShared = nsResult.bShared;
                fileFolderInfo.ContentUrl = nsResult.StrContentsUri;
                fileFolderInfo.CreatedDate = nsResult.dtCreated;
                fileFolderInfo.FileName = nsResult.StrName;
                fileFolderInfo.FileSize = nsResult.dblSizeInBytes;
                fileFolderInfo.MimeType = nsResult.StrMimeType;
                fileFolderInfo.ModifiedDate = nsResult.dtModified;
                fileFolderInfo.ParentUrl = nsResult.StrParentUri;
                fileFolderInfo.Status = DB_STATUS_SUCCESS;
                fileFolderInfo.Type = nsResult.StrType;
                fileFolderInfo.Key = strKey;

                int lastSepIndex = strKey.LastIndexOf("\\");
                string parentDirPath = "";

                if (lastSepIndex != -1)
                {
                    parentDirPath = strKey.Substring(0, strKey.LastIndexOf("\\"));
                    parentDirPath = parentDirPath.Substring(parentDirPath.LastIndexOf("\\") + 1);
                }

                fileFolderInfo.ParentDir = parentDirPath;
                bool bRet = false;
                if (nqDetail.StrObjectType == "DIRECTORY")
                {
                    if (Directory.Exists(strPath))
                    {
                        //string strCheck = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, DbHandler.KEY + "='" + strKey + "'");
                        string strCheck = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, new string[] { DbHandler.KEY }, new string[] { strKey }, new DbType[] { DbType.String });
                        if(strCheck == strKey)
                            bRet = false;
                        else
                            bRet = true;
                    }
                    else
                    {
                        Directory.CreateDirectory(strPath);
                        bRet = true;
                    }
                }
                else
                {
                    if (File.Exists(strPath))
                    {
                        bRet = false;
                    }
                    else
                    {
                        string strEtagCloud = cMezeoFileCloud.GetETag(nsResult.StrContentsUri, ref nStatusCode);
                        if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
                        {
                            return nStatusCode;
                        }
                        else if (nStatusCode != ResponseCode.GETETAG)
                        {
                            return nStatusCode;
                        }
                        //string strCheck = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, DbHandler.E_TAG + "='" + strEtagCloud + "'");
                        string strCheck = dbHandler.GetString(DbHandler.TABLE_NAME, DbHandler.KEY, new string[] { DbHandler.E_TAG }, new string[] { strEtagCloud }, new DbType[] { DbType.String });
                        if (strCheck.Trim().Length != 0)
                        {
                            File.Copy(BasicInfo.SyncDirPath + "\\" + strCheck, strPath);
                            fileFolderInfo.ETag = strEtagCloud;
                            bRet = true;
                        }
                        else
                        {
                            bRet = cMezeoFileCloud.DownloadFile(nsResult.StrContentsUri + '/' + nsResult.StrName, strPath, nsResult.dblSizeInBytes, ref nStatusCode);
                            if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
                            {
                                return nStatusCode;
                            }
                            else if (nStatusCode != ResponseCode.DOWNLOADFILE)
                            {
                                return nStatusCode;
                            }
                        }
                    }
                }

                if (bRet)
                {
                    if (fileFolderInfo.ETag == null)
                    {
                        fileFolderInfo.ETag = "";
                    }

                    if (fileFolderInfo.ETag.Trim().Length == 0)
                        fileFolderInfo.ETag = cMezeoFileCloud.GetETag(nsResult.StrContentsUri, ref nStatusCode);

                    if (fileFolderInfo.ETag == null)
                    {
                        fileFolderInfo.ETag = "";
                    }
                    if (fileFolderInfo.MimeType == null)
                    {
                        fileFolderInfo.MimeType = "";
                    }

                    dbHandler.Write(fileFolderInfo);
                }
                nStatus = 1;
                //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", nqDetail.StrEvent + " - " + strKey + " - Leave");
            }

            //LogWrapper.LogMessage("frmSyncManager - UpdateFromNQ - ", "Leave");

            return nStatus;
        }
        private int nqEventCdmiCreate(NQDetails nqDetail, NSResult nsResult, string strKey, string strPath)
        {
            //LogWrapper.LogMessage("frmSyncManager - nqEventCdmiCreate", "enter");
            //bool bIssuccess = false;
            int nStatus = 0;
            FileFolderInfo fileFolderInfo = new FileFolderInfo();

            fileFolderInfo.IsPublic = nsResult.bPublic;
            fileFolderInfo.IsShared = nsResult.bShared;
            fileFolderInfo.ContentUrl = nsResult.StrContentsUri;
            fileFolderInfo.CreatedDate = nsResult.dtCreated;
            fileFolderInfo.FileName = nsResult.StrName;
            fileFolderInfo.FileSize = nsResult.dblSizeInBytes;
            fileFolderInfo.MimeType = nsResult.StrMimeType;
            fileFolderInfo.ModifiedDate = nsResult.dtModified;
            fileFolderInfo.ParentUrl = nsResult.StrParentUri;
            fileFolderInfo.Status = DB_STATUS_IN_PROGRESS;
            fileFolderInfo.Type = nsResult.StrType;
            fileFolderInfo.Key = strKey;

            int lastSepIndex = strKey.LastIndexOf("\\");
            string parentDirPath = "";

            if (lastSepIndex != -1)
            {
                parentDirPath = strKey.Substring(0, strKey.LastIndexOf("\\"));
                parentDirPath = parentDirPath.Substring(parentDirPath.LastIndexOf("\\") + 1);
            }

            fileFolderInfo.ParentDir = parentDirPath;

            if (fileFolderInfo.ETag == null) { fileFolderInfo.ETag = ""; }
            if (fileFolderInfo.MimeType == null) { fileFolderInfo.MimeType = ""; }

            dbHandler.Write(fileFolderInfo);

            bool bRet = false;
            string strEtag = "";
            int refCode = 0;
            int nStatusCode = 0;

            if (nqDetail.StrObjectType == "FILE")
            {
                MarkParentsStatus(strPath, DB_STATUS_IN_PROGRESS);
                bRet = cMezeoFileCloud.DownloadFile(nsResult.StrContentsUri + '/' + nsResult.StrName, strPath,nsResult.dblSizeInBytes, ref nStatusCode);
                if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
                {
                    return nStatusCode;
                }
                else if (nStatusCode != ResponseCode.DOWNLOADFILE)
                {
                    return nStatusCode;
                }
                strEtag = cMezeoFileCloud.GetETag(nsResult.StrContentsUri, ref refCode);
                if (refCode == ResponseCode.LOGINFAILED1 || refCode == ResponseCode.LOGINFAILED2)
                {
                    return refCode;
                }
                else if (refCode != ResponseCode.GETETAG)
                {
                    return refCode;
                }
            }
            else
            {
                MarkParentsStatus(strPath, DB_STATUS_IN_PROGRESS);
                try
                {
                    Directory.CreateDirectory(strPath);
                }
                catch (System.IO.PathTooLongException ex)
                {
                    LogWrapper.LogMessage("frmSyncManager - nqEventCdmiCreate", "Caught exception: " + ex.Message);
                }

                strEtag = cMezeoFileCloud.GetETag(nsResult.StrContentsUri, ref refCode);
                if (refCode == ResponseCode.LOGINFAILED1 || refCode == ResponseCode.LOGINFAILED2)
                {
                    return refCode;
                }
                else if (refCode != ResponseCode.GETETAG)
                {
                    return refCode;
                }

                bRet = true;
            }

            if (bRet)
            {
                MarkParentsStatus(strPath, DB_STATUS_SUCCESS);
                if (nqDetail.StrObjectType == "DIRECTORY")
                {
                    DirectoryInfo dInfo = new DirectoryInfo(strPath);
                    dbHandler.UpdateModifiedDate(dInfo.LastWriteTime, fileFolderInfo.Key);
                    dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.E_TAG , strEtag , DbHandler.KEY , fileFolderInfo.Key );
                    dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.STATUS ,"SUCCESS", DbHandler.KEY ,fileFolderInfo.Key);
                }
                else
                {
                    FileInfo fInfo = new FileInfo(strPath);
                    dbHandler.UpdateModifiedDate(fInfo.LastWriteTime, fileFolderInfo.Key);
                    dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.E_TAG , strEtag , DbHandler.KEY , fileFolderInfo.Key );
                    dbHandler.Update(DbHandler.TABLE_NAME, DbHandler.STATUS , "SUCCESS", DbHandler.KEY ,fileFolderInfo.Key );
                    nStatus = 1;
                }
            }

            if (nqDetail.StrObjectType == "DIRECTORY")
            {
                ItemDetails[] iDetails = cMezeoFileCloud.DownloadItemDetails(nsResult.StrContentsUri, ref nStatusCode, null);
                if (nStatusCode == ResponseCode.LOGINFAILED1 || nStatusCode == ResponseCode.LOGINFAILED2)
                {
                    return nStatusCode;
                }
                else if (nStatusCode == ResponseCode.INTERNAL_SERVER_ERROR)
                {
                    // Don't do anything, just keep on chugging.
                }
                else if (nStatusCode != ResponseCode.DOWNLOADITEMDETAILS)
                {
                    return nStatusCode;
                }
                if (iDetails != null)
                {
                    for (int num = 0; num < iDetails[0].nTotalItem; num++)
                    {
                        nStatus = DownloadFolderStructureForNQ(iDetails[num], strKey);
                        if (nStatus == ResponseCode.LOGINFAILED1 || nStatus == ResponseCode.LOGINFAILED2)
                        {
                            return nStatus;
                        }
                        else if (nStatus != ResponseCode.GETETAG && nStatus != ResponseCode.DOWNLOADFILE && nStatus != ResponseCode.DOWNLOADITEMDETAILS && nStatus != 1)
                        {
                            return nStatus;
                        }
                    }
                }
                else
                    nStatus = 1;
            }

            //LogWrapper.LogMessage("frmSyncManager - nqEventCdmiCreate", "leave");
            return nStatus;
        }
        private void GetNextEvent(ref LocalEvents lEvent, ref NQDetails nqEvent, ref LocalItemDetails localItemDetails, ref string strDisplayName)
        {
            bool usePriorityQueueLogic = false;
            if (usePriorityQueueLogic)
            {
                // See if there are any events in the queue.
                // Local events take priority over NQ.
                // localItemDetails (initial sync events) take priority over local events.
                localItemDetails = dbHandler.GetLocalItemDetailsEvent();
                if (localItemDetails == null)
                {
                    lEvent = dbHandler.GetLocalEvent();
                    if (lEvent == null)
                        nqEvent = dbHandler.GetNQEvent();
                }
            }
            else
            {
                // See if there are any events in the queue.
                // localItemDetails (initial sync events) take priority over other events.
                // If there are no 'I'nitial sync events, just get the item with the
                // lowest index, determine the type, populate it, and return it.
                // The GetXEvent() functions sort by index so we just have to know
                // the type of event before calling the appropriate function.
                localItemDetails = dbHandler.GetLocalItemDetailsEvent();
                if (localItemDetails == null)
                {
                    string eventType = "";
                    Int64 eventId = dbHandler.GetNextEventId(ref eventType);
                    if (-1 != eventId)
                    {
                        switch (eventType)
                        {
                            case "I":    // The 'I'nitial events should already be handled.
                                break;

                            case "L":    // 'L'ocal event.
                                lEvent = dbHandler.GetLocalEvent();
                                break;

                            case "N":    // 'N'otification queue event.
                                nqEvent = dbHandler.GetNQEvent();
                                break;
                        }
                    }
                }
            }

            if (null != lEvent)
                strDisplayName = lEvent.FullPath;
            else if (null != nqEvent)
                strDisplayName = nqEvent.StrObjectName;
            else if (null != localItemDetails)
                strDisplayName = localItemDetails.Path;
        }