コード例 #1
0
        public int Load(int aid, string fn)
        {
            var f   = Add(aid, fn);
            var fid = f.Id;
            var di  = new DirectoryInfo("FileDataFolder");
            var d   = Path.Combine(di.FullName, fid.ToString("D5"));

            Directory.CreateDirectory(d);
            var input = Request.BodyReader.AsStream();

            byte[] bb;
            using (MemoryStream ms = new MemoryStream())
            {
                input.CopyTo(ms);
                bb = ms.ToArray();
            }
            var db = new EE.DbAppContext();

            f = db.Files.Include(r => r.Revisions).FirstOrDefault(t => t.Id == fid);
            int rev = f?.Revisions.OrderByDescending(r => r.Rev).FirstOrDefault()?.Rev ?? 0;

            rev++;
            var fna = Path.Combine(d, rev + ".bin");

            System.IO.File.WriteAllBytes(fna, bb);
            f.Revisions.Add(new Revision()
            {
                Rev = rev
            });
            db.SaveChanges();
            return(-1);
        }
コード例 #2
0
        public File Add(int aid, string nm, int run)
        {
            nm = nm.ToLower();
            var db = new EE.DbAppContext();
            var a  = db.Apps.Include(t => t.Files).FirstOrDefault(t => t.Id == aid);

            if (a == null)
            {
                return(null);
            }
            var f = a.Files.FirstOrDefault(t => t.Name == nm);

            if (f != null)
            {
                return(f);
            }
            f = new File()
            {
                Name = nm, Run = run == 1
            };
            db.Files.Add(f);
            a.Files.Add(f);
            db.SaveChanges();
            f = a.Files.FirstOrDefault(t => t.Name == nm);
            return(f);
        }
コード例 #3
0
        public int SetRun(int fid, int rn)
        {
            var db = new EE.DbAppContext();
            var f  = db.Files.FirstOrDefault(t => t.Id == fid);

            if (f == null)
            {
                return(0);
            }
            f.Run = rn > 0;
            db.SaveChanges();
            return(1);
        }
コード例 #4
0
        public int Add(string nm)
        {
            nm = nm.ToLower();
            var db = new EE.DbAppContext();
            var o  = db.Apps.FirstOrDefault(t => t.AppName == nm);

            if (o != null)
            {
                return(o.Id);
            }
            db.Apps.Add(new App()
            {
                AppName = nm
            });
            db.SaveChanges();
            o = db.Apps.FirstOrDefault(t => t.AppName == nm);
            if (o != null)
            {
                return(o.Id);
            }
            return(-1);
        }