示例#1
0
        //Download for handling by the mobile
        public bool AddMobileDownload(int iMobileID, int iDirID, string sPath, long lFilesize)
        {
            //Cannot add a zero length
            if (sPath.Length == 0)
            {
                return(false);
            }

            //Struct for handling item
            DownloadMobileDB aDownload = new DownloadMobileDB
            {
                FilePath   = sPath,
                DirID      = iDirID,
                MobileID   = iMobileID,
                DownloadID = GetRandomString(RANDOM_LENGTH, RANDOM_CHARACTERSUSED.ToCharArray()),
                Status     = DownloadStatus.NOTSET,
                FileSize   = lFilesize
            };

            //Check if the item exists already
            LiteCollection <DownloadMobileDB> aDBValues = m_dbdownload.GetCollection <DownloadMobileDB>("mobiledownload");

            var results = aDBValues.FindOne(x => x.FilePath == sPath && x.MobileID == iMobileID && x.DirID == iDirID);

            if (results != null)
            {
                results.Status = DownloadStatus.NOTSET;
                aDBValues.Update(results);
                return(false); //Already exist, do not add twice, but reset status
            }
            else //Add new dir to DB
            {
                aDBValues.EnsureIndex(x => x.DownloadID);
                var val = aDBValues.Insert(aDownload);
                return(true);
            }
        }
示例#2
0
        //Add a way to manipulate the order of items
        public bool MoveMobileDownload(string sDownloadID, MobileDownloadMover mover)
        {
            LiteCollection <DownloadMobileDB> aDBValues = m_dbdownload.GetCollection <DownloadMobileDB>("mobiledownload");
            var results = aDBValues.FindOne(x => x.DownloadID == sDownloadID);

            if (results != null) //If dir exists, return displayname
            {
                DownloadMobileDB Source      = results;
                DownloadMobileDB Destination = null;
                DownloadMobileDB Last        = null;

                var results2 = aDBValues.Find(x => x.MobileID == Source.MobileID && x.Status == DownloadStatus.NOTSET);
                foreach (DownloadMobileDB download in results2)
                {
                    //Move as first object (not status set)
                    if (Destination == null &&
                        mover == MobileDownloadMover.FIRST
                        )
                    {
                        Destination = download;
                        int nSourceID = Source.Id;
                        Source.Id      = Destination.Id;
                        Destination.Id = nSourceID;
                        aDBValues.Update(Source);
                        aDBValues.Update(Destination);
                        return(true); //Status was set
                    }

                    //Move UP in in list
                    if (mover == MobileDownloadMover.UP &&
                        download.Equals(Source) &&
                        Last != null)
                    {
                        Destination = Last;
                        int nSourceID = Source.Id;
                        Source.Id      = Destination.Id;
                        Destination.Id = nSourceID;
                        aDBValues.Update(Source);
                        aDBValues.Update(Destination);
                        return(true); //Status was set
                    }

                    //Move DOWN in in list (last in one itteration after)
                    if (mover == MobileDownloadMover.DOWN &&
                        Source.Equals(Last))
                    {
                        Destination = download;
                        int nSourceID = Source.Id;
                        Source.Id      = Destination.Id;
                        Destination.Id = nSourceID;
                        aDBValues.Update(Source);
                        aDBValues.Update(Destination);
                        return(true); //Status was set
                    }

                    //Store last for swapping
                    Last = download;
                }

                //Swap to bottom
                if (mover == MobileDownloadMover.LAST)
                {
                    Destination = Last;
                    int nSourceID = Source.Id;
                    Source.Id      = Destination.Id;
                    Destination.Id = nSourceID;
                    aDBValues.Update(Source);
                    aDBValues.Update(Destination);
                    return(true); //Status was set
                }
            }

            return(false);
        }