/// <summary>
 /// Gets an instance of SES
 /// </summary>
 /// <returns></returns>
 public static SideEffectStore GetInstance()
 {
     if (ses == null)
     {
         ses = ReadFromDatabase();
     }
     return(ses);
 }
 /// <summary>
 /// Gets an instance of SES
 /// </summary>
 /// <returns></returns>
 public static SideEffectStore GetInstance()
 {
     if (ses == null)
     {
         ses = ReadFromDatabase();
     }
     return ses;
 }
        /// <summary>
        /// Reads from the database
        /// </summary>
        /// <returns></returns>
        public static SideEffectStore ReadFromDatabase()
        {
            try
            {
                var filename = Path.Combine(DUCoverConstants.DUCoverStoreLocation, DUCoverConstants.SideEffectStoreDebugFile);
                SideEffectStore ses = new SideEffectStore();
                if (!File.Exists(filename))
                    return ses;

                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        line.Trim();
                        string methodname = line;
                        SEMethodStore sem = new SEMethodStore(methodname);
                        ses.MethodStore[methodname] = sem;

                        //Reading defined
                        line = sr.ReadLine().Trim();
                        string[] parts = line.Split(' ');

                        int numDefined = Convert.ToInt32(parts[1]);
                        for (int count = 0; count < numDefined; count++)
                        {
                            line = sr.ReadLine().Trim();
                            string[] lineparts = line.Split(' ');

                            SEFieldStore sef = new SEFieldStore(lineparts[0]);
                            sem.DefinedFieldSet[lineparts[0]] = sef;
                            for (int tcount = 1; tcount < lineparts.Length; tcount++)
                            {
                                sef.AllOffsets.Add(Convert.ToInt32(lineparts[tcount]));
                            }
                        }

                        //Reading used
                        line = sr.ReadLine().Trim();
                        parts = line.Split(' ');

                        int numUsed = Convert.ToInt32(parts[1]);
                        for (int count = 0; count < numUsed; count++)
                        {
                            line = sr.ReadLine().Trim();
                            string[] lineparts = line.Split(' ');

                            SEFieldStore sef = new SEFieldStore(lineparts[0]);
                            sem.UsedFieldSet[lineparts[0]] = sef;
                            for (int tcount = 1; tcount < lineparts.Length; tcount++)
                            {
                                sef.AllOffsets.Add(Convert.ToInt32(lineparts[tcount]));
                            }
                        }
                    }
                }

                Console.WriteLine("Number of entries read: " + ses.MethodStore.Count);
                return ses;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to deserialize");
                logger.ErrorException("Error occurred while reading from file " + ex.StackTrace, ex);
            }

            return new SideEffectStore();
        }
        /// <summary>
        /// Reads from the database
        /// </summary>
        /// <returns></returns>
        public static SideEffectStore ReadFromDatabase()
        {
            try
            {
                var             filename = Path.Combine(DUCoverConstants.DUCoverStoreLocation, DUCoverConstants.SideEffectStoreDebugFile);
                SideEffectStore ses      = new SideEffectStore();
                if (!File.Exists(filename))
                {
                    return(ses);
                }

                using (StreamReader sr = new StreamReader(filename))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        line.Trim();
                        string        methodname = line;
                        SEMethodStore sem        = new SEMethodStore(methodname);
                        ses.MethodStore[methodname] = sem;

                        //Reading defined
                        line = sr.ReadLine().Trim();
                        string[] parts = line.Split(' ');

                        int numDefined = Convert.ToInt32(parts[1]);
                        for (int count = 0; count < numDefined; count++)
                        {
                            line = sr.ReadLine().Trim();
                            string[] lineparts = line.Split(' ');

                            SEFieldStore sef = new SEFieldStore(lineparts[0]);
                            sem.DefinedFieldSet[lineparts[0]] = sef;
                            for (int tcount = 1; tcount < lineparts.Length; tcount++)
                            {
                                sef.AllOffsets.Add(Convert.ToInt32(lineparts[tcount]));
                            }
                        }

                        //Reading used
                        line  = sr.ReadLine().Trim();
                        parts = line.Split(' ');

                        int numUsed = Convert.ToInt32(parts[1]);
                        for (int count = 0; count < numUsed; count++)
                        {
                            line = sr.ReadLine().Trim();
                            string[] lineparts = line.Split(' ');

                            SEFieldStore sef = new SEFieldStore(lineparts[0]);
                            sem.UsedFieldSet[lineparts[0]] = sef;
                            for (int tcount = 1; tcount < lineparts.Length; tcount++)
                            {
                                sef.AllOffsets.Add(Convert.ToInt32(lineparts[tcount]));
                            }
                        }
                    }
                }

                Console.WriteLine("Number of entries read: " + ses.MethodStore.Count);
                return(ses);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to deserialize");
                logger.ErrorException("Error occurred while reading from file " + ex.StackTrace, ex);
            }

            return(new SideEffectStore());
        }