/// <summary>
 /// Deprecated Method for adding a new object to the Files EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFiles(File file)
 {
     base.AddObject("Files", file);
 }
        public string Unzipfile(Problem problem, Stream inputStream)
        {
            Dictionary<string, TestCas> dTestcase = new Dictionary<string, TestCas>();
            ZipInputStream s = new ZipInputStream(inputStream);
            ZipEntry ZEntry;
            string sFileName = "";
            String configXML = null;
            while ((ZEntry = s.GetNextEntry()) != null)
            {
                string directoryName = "";
                directoryName = Path.GetDirectoryName(ZEntry.Name);

                if (directoryName != "" && directoryName != null && !dTestcase.ContainsKey(directoryName))
                {
                    TestCas tcTemp = new TestCas();
                    tcTemp.MaDB = problem.ID;
                    dTestcase.Add(directoryName, tcTemp);
                    db.TestCases.AddObject(tcTemp);
                    problem.TestCases.Add(tcTemp);
                }

                sFileName = Path.GetFileName(ZEntry.Name);
                if (sFileName == String.Empty)
                    continue;
                #region Doc file entry
                int size = 2048;
                using (MemoryStream memStream = new MemoryStream(size))
                {
                    byte[] data = new byte[size];
                    while (true)
                    {
                        size = s.Read(data, 0, data.Length);
                        if (size > 0)
                        {
                            memStream.Write(data, 0, size);
                        }
                        else
                        {
                            break;
                        }
                    }
                    memStream.Position = 0;
                    switch (Path.GetExtension(sFileName).ToLower())
                    {
                        case ".inp":
                            using (StreamReader docFile = new System.IO.StreamReader(memStream))
                            {
                                TestCas tc = dTestcase[directoryName];
                                tc.Input = docFile.ReadToEnd();
                                docFile.Close();
                            }
                            break;
                        case ".out":
                            using (StreamReader docFile = new System.IO.StreamReader(memStream))
                            {
                                TestCas tc = dTestcase[directoryName];
                                tc.Output = docFile.ReadToEnd();
                                docFile.Close();
                            }
                            break;
                        case ".xml":
                            //Doc file cau hinh
                            if (Path.GetFileNameWithoutExtension(sFileName).ToLower() == problem.Name)
                                using (StreamReader docFile = new System.IO.StreamReader(memStream))
                                {
                                    configXML = docFile.ReadToEnd();
                                    docFile.Close();
                                }
                            break;
                        case ".doc":
                        case ".docx":
                        case ".pdf":
                            byte[] problemfile = memStream.ToArray();
                            SPKTOnline.Models.File file = new SPKTOnline.Models.File();
                            file.Content = problemfile;
                            file.Type = Path.GetExtension(sFileName);
                            file.Name = sFileName;
                            file.DownloadCount = 0;
                            db.Files.AddObject(file);
                            problem.File = file;

                            break;
                        default:
                            break;
                    }
                }
                #endregion
            }
            //TODO: Gan du lieu Problem tu cau hinh xml
            double phanTramDiem = Math.Round(100.0 / problem.TestCases.Count, 2);
            foreach (TestCas tc in dTestcase.Values)
            {
                tc.Diem = phanTramDiem;
            }
            s.Close();
            return sFileName;
        }
 /// <summary>
 /// Create a new File object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static File CreateFile(global::System.Int32 id)
 {
     File file = new File();
     file.ID = id;
     return file;
 }