Beispiel #1
0
        /// <summary>
        /// Method to unlock a DCRGraph in the database. This is a helper method which is used by all methods which change data in the database.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="graphId"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public async Task <Tuple <bool, string> > Unlock(Guid guid, int graphId, DBO.Database db)
        {
            var graph = await db.DCRGraphs.FindAsync(graphId);

            if (graph == null)
            {
                return(new Tuple <bool, string>(false, "The graph did not exist"));
            }

            if (graph.Lock == false)
            {
                return(new Tuple <bool, string>(false, "The graph was not locked when reaching the unlock phase"));
            }

            if (graph.Guid != guid)
            {
                return(new Tuple <bool, string>(false, "someone else has locked the graph. Should not be possible."));
            }

            //unlock and save to db.
            graph.Lock = false;

            db.Entry(graph).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(new Tuple <bool, string>(true, ""));
        }
Beispiel #2
0
        /// <summary>
        /// Method to lock a DCRGraph in the database. This is a helper method which is used by all methods which change data in the database.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="graphId"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public async Task <Tuple <bool, string> > LockGraph(Guid guid, int graphId, DBO.Database db)
        {
            var graph = await db.DCRGraphs.FindAsync(graphId);

            //check if the graph exist
            if (graph == null)
            {
                return(new Tuple <bool, string>(false, "The graph did not exist"));
            }

            //Check that the graph is not locked, and if it is, check whether it's an old lock. Locks older than 1minute we do no care about.
            if (graph.Lock && DateTime.Now.Subtract(graph.LockTime).Minutes < 1)
            {
                return(new Tuple <bool, string>(false, "The graph is already locked"));
            }

            //lock this
            graph.Lock     = true;
            graph.LockTime = DateTime.Now;
            graph.Guid     = guid;

            db.Entry(graph).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(new Tuple <bool, string>(true, ""));
        }
Beispiel #3
0
        /// <summary>
        /// Method to check if a DCRGraph in the database is locked. This is a helper method which is used by all methods which change data in the database.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="graphId"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public async Task <Tuple <bool, string> > CheckLock(Guid guid, int graphId, DBO.Database db)
        {
            var graph = await db.DCRGraphs.FindAsync(graphId);

            if (graph == null)
            {
                return(new Tuple <bool, string>(false, "The graph did not exist"));
            }

            if (graph.Lock == false)
            {
                return(new Tuple <bool, string>(false, "The graph was not locked when reaching the check lock phase"));
            }

            if (graph.Guid != guid)
            {
                return(new Tuple <bool, string>(false, "someone else has locked the graph."));
            }

            return(new Tuple <bool, string>(true, ""));
        }