Esempio n. 1
0
        public void AddFileTest()
        {
            var auxFile = new File {
                Name = "Pepe", Id = 3
            };

            fileRepository.Add(auxFile);

            mockSet.Verify(v => v.Add(It.IsAny <File>()), Times.Once());
            mockContext.Verify(e => e.SaveChanges(), Times.Once());
        }
Esempio n. 2
0
        public void CanAddFile()
        {
            FileRepository repo = new FileRepository();
            File           file = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags     = new List <Tag>()
            };

            repo.Add(file);

            Assert.AreNotEqual(0, file.Id);
        }
Esempio n. 3
0
        public void CanGetFile()
        {
            FileRepository repo = new FileRepository();
            File           file = new File
            {
                FilePath = Guid.NewGuid().ToString(),
                Tags     = new List <Tag>()
            };

            repo.Add(file);

            Assert.AreEqual(file, repo.GetByFilename(file.FilePath));
        }
        public ActionResult UploadFile()
        {
            var postedFile = Request.Files[0];

            if (postedFile != null)
            {
                repo.Add(postedFile);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Upload"));
            }
        }
Esempio n. 5
0
        public void AddCorrectlyAddedFile()
        {
            var file = new File {
                ParentID = 1,
                Syntax   = Syntax.JavaScript,
                Name     = "NewTestFile",
                Content  = "NewTestFileContent"
            };

            var repo = new FileRepository(_context);

            repo.Add(file);
            var res = repo.Find(file.Id);

            Assert.Equal(file, res);
        }
Esempio n. 6
0
        public void TestAdd()
        {
            var person = new Person {
                Name         = "Name4",
                Organization = "Org4"
            };
            var text     = File.ReadAllText(fileName);
            var expected = text + "Name4"
                           + Environment.NewLine
                           + "Org4"
                           + Environment.NewLine;
            var repository = new FileRepository(fileName);

            // act
            repository.Add(person);
            //assert
            Assert.AreEqual(expected, File.ReadAllText(fileName));
        }
Esempio n. 7
0
        public void sendPost(string title, int section, string content, string categoryIds)
        {
            var sender = userRep.getYaUserFromYaMail(User.Identity.Name);


            if (!string.IsNullOrWhiteSpace(content) || !string.IsNullOrWhiteSpace(title))
            {
                var blogToPost = new BlogEntryModel
                {
                    Title   = title,
                    Section = section,
                    Sender  = sender.Id,
                    Content = content,
                    Date    = DateTime.Now
                };

                var id = blogRep.AddBlogEntry(blogToPost.MapToBlogEntity());

                var test = mjau(categoryIds);

                //int k;
                //k = test.Length;

                for (int s = 0; s < test.Length; s++)
                {
                    var blog_kat = new Category_Blog
                    {
                        CategoryId = test[s],
                        BlogId     = id
                    };
                    cb_rep.Add(blog_kat);
                }
                ;

                var fileModel = new FileModel
                {
                    BlogEntry = id,
                    Path      = root,
                    Type      = null
                };
                fileRep.Add(fileModel.MapToFileEntity());
            }
        }
Esempio n. 8
0
        public File SaveFile(FileRepository fRepository, string fileName, int expMinutes)
        {
            if (fRepository != null)
            {
                File dbFile = new File();
                dbFile.DateCreated   = DateTime.Now;
                dbFile.DateExpiredOn = dbFile.DateCreated.AddMinutes(expMinutes);
                dbFile.Name          = fileName;
                dbFile.Path          = "";

                dbFile.Id   = fRepository.Add(dbFile);
                dbFile.Path = GetPath(dbFile);
                fRepository.Update(dbFile);

                new LinkServices().GenerateNewLink(new LinkSharing.Core.Repositories.LinkRepository(fRepository.connectionString), dbFile.Id);
                return(dbFile);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 9
0
        public static FileUploadResponses SaveUploadedFile(FileModel CurrentFile)
        {
            IFileRepository     _FileRepsoitory = new FileRepository();
            FileUploadResponses Rtn;

            try
            {
                CompletedTransactionResponses CTR = _FileRepsoitory.Add(CurrentFile);
                if (CTR.WasSuccessfull)
                {
                    Rtn = new FileUploadResponses()
                    {
                        FileName       = CurrentFile.FullFileName,
                        Message        = "Successfully Saved",
                        WasSuccessfull = true
                    };
                }
                else
                {
                    Rtn = new FileUploadResponses()
                    {
                        FileName       = CurrentFile.FullFileName,
                        Message        = "Failed To Upload - Error : " + CTR.Message,
                        WasSuccessfull = false
                    };
                }
            }
            catch (Exception ex)
            {
                Rtn = new FileUploadResponses()
                {
                    FileName       = CurrentFile.FullFileName,
                    Message        = "Failed To Upload - Error : " + ex.Message,
                    WasSuccessfull = false
                };
            }
            return(Rtn);
        }
Esempio n. 10
0
 public void Add(File item)
 {
     FileRepository.Add(item);
 }
Esempio n. 11
0
        private static void Run()
        {
            var cmsRepository  = new CmsRepository();
            var fileRepository = new FileRepository();
            var errorFiles     = new List <SiteContent>();
            var logFilePath    = ConfigurationManager.AppSettings["LogFilePath"] ?? ".";
            var logFileName    = string.Format(@"{0}\{1}-{2:yyyyMMdd-hhmmsstt}.txt", logFilePath, ApplicationName, DateTime.Now);
            var logFile        = new StreamWriter(logFileName);

            try
            {
                logFile.WriteLine(SettingsMessage);
                logFile.LogInfo("Retrieving files to copy.");

                var directories = Directory.GetDirectories(CmsFilePath);

                foreach (var directory in directories)
                {
                    var file = Directory.GetFiles(directory).FirstOrDefault();

                    if (string.IsNullOrEmpty(file))
                    {
                        logFile.LogError(null, string.Format("Could not find file in directory: {0}", directory));
                    }

                    var fileInfo  = new System.IO.FileInfo(file);
                    var contentId = int.Parse(fileInfo.Directory.Name);

                    var content = cmsRepository.FindBy <SiteContent>(s => s.SiteContentID == contentId).FirstOrDefault();

                    logFile.LogInfo("Uploading File: {0} ({1:#,00.00} KB)", fileInfo.Name, fileInfo.Length / 1024);

                    if (content == null)
                    {
                        logFile.LogError(null, string.Format("SiteContent Record not found: {0}", contentId));
                        continue;
                    }

                    var fileBytes = System.IO.File.ReadAllBytes(file);

                    var newFile = new Portal.Model.File
                    {
                        Data = fileBytes,
                        Info = new Portal.Model.FileInfo
                        {
                            Name         = fileInfo.Name,
                            Extension    = Path.GetExtension(fileInfo.Name),
                            SizeBytes    = fileBytes.Length,
                            CreateUserID = 0,
                            CreateDate   = DateTime.Now
                        }
                    };

                    // Save File
                    fileRepository.Add(newFile);
                    fileRepository.Save();

                    if (newFile.FileID > 0)
                    {
                        content.FileID       = newFile.FileID;
                        content.ModifyUserID = 0;
                        content.ModifyDate   = DateTime.Now;

                        // Update SiteContent with FileID
                        cmsRepository.Update(content);
                        cmsRepository.Save();
                    }

                    logFile.LogInfo("\tSaved file: {0}, FileID: {1}.", fileInfo.Name, newFile.FileID);
                }

                logFile.LogInfo("Import Completed.\r\n\r\nSummary:\r\nTotal Files: {0}\r\nErrored Files: {1}", directories.Length, errorFiles.Count);

                //if (errorFiles.Count > 0)
                //{
                //    logFile.Log(EventTypes.Warning, null, "Files that could not be imported:");
                //    errorFiles.ForEach(f => logFile.Log(EventTypes.Warning, null, "\tSiteContentID: {0}, File: {1}:{2}/{3}", f.SiteContentID, f.FileContentLocation, f.FileSubdirectory, f.FileName));
                //}

                logFile.LogInfo("\r\n\r\nDone!  Log file saved to: {0}.", Path.GetFullPath(logFileName));
            }
            catch (Exception ex)
            {
                logFile.LogError(ex, "\t{0}", ex.FullMessage());
            }
            finally
            {
                logFile.Dispose();
                cmsRepository.Dispose();
                fileRepository.Dispose();
            }
        }
Esempio n. 12
0
        public ActionResult Index(int?page, int?id, string filename, string nowdo, string path, string search, string attr)
        {
            int pag = page ?? 1;

            ViewData["page"] = pag;
            ViewData["attr"] = attr;
            IPagedList <xiayun.Model.File> files;

            if (path == null)
            {
                path             = "Home";
                ViewData["path"] = "Home";
            }
            else
            {
                ViewData["path"] = path;
            }


            if (id != null)
            {
                xiayun.Model.File file  = fileinfo.Find(x => x.Id == id);
                string            npath = file.FilePath + '/' + file.FileName;

                IEnumerable <xiayun.Model.File> filess = fileinfo.FindAll(x => x.FilePath.StartsWith(npath));
                if (nowdo == "delete")
                {
                    foreach (var item in filess)
                    {
                        fileinfo.Delete(item);
                    }
                    fileinfo.Delete(file);
                }

                else if (nowdo == "update")
                {
                    foreach (var item in filess)
                    {
                        //item.FilePath.Replace("we", "nihao");
                        item.FilePath = item.FilePath.Replace(file.FileName, filename);
                        item.UpTime   = DateTime.Now.ToString();
                        fileinfo.Update(item);

                        /*
                         * item.FilePath.Replace("we", "he");
                         * item.UpTime = DateTime.Now.ToString();
                         * fileinfo.Update(item);
                         */
                    }

                    file.FileName = filename;
                    file.UpTime   = DateTime.Now.ToString();
                    fileinfo.Update(file);
                }
                fileinfo.SaveChanges();
            }
            if (nowdo == "add")
            {
                string foldername = "新建文件夹";
                int    i          = 0;
                while (true)
                {
                    bool p = fileinfo.Exist(x => x.FileName == foldername + i);
                    if (p == false)
                    {
                        break;
                    }
                    i++;
                }
                fileinfo.Add(new xiayun.Model.File
                {
                    FileName = foldername + i,
                    Belong   = Session["user"].ToString(),
                    FileExt  = "folder",
                    UpTime   = DateTime.Now.ToString(),
                    FilePath = path,
                });
                fileinfo.SaveChanges();
            }
            if (search != null)
            {
                files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & x.FileName.Contains(search), x => x.UpTime, pag, 10, false);
                ViewData["search"] = search;
                return(View(files));
            }
            if (attr != null)
            {
                string images = ".bmp,.jpg,.png,.tiff,.gif,.pcx,.tga,.exif,.fpx,.svg,.psd,.cdr,.pcd,.dxf,.ufo,.eps,.ai,.raw,.WMF";
                string musics = ",.mp3,.wma,.wav,.asf,.aac,.vqf,.falc,.ape,.mid,.ogg";
                string videos = ".rm,.rmvb,.mp4,.mov,.mtv,.dat,.wmv,.avi,.3gp,.amv,.dmv";
                switch (attr)
                {
                case "img": files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & images.Contains(x.FileExt.ToLower()), x => x.UpTime, pag, 10, false); break;

                case "music": files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & musics.Contains(x.FileExt.ToLower()), x => x.UpTime, pag, 10, false); break;

                case "video": files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & videos.Contains(x.FileExt.ToLower()), x => x.UpTime, pag, 10, false); break;

                default: files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString(), x => x.UpTime, pag, 10, false); break;
                }
                return(View(files));
            }
            files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & x.FilePath == path, x => x.UpTime, pag, 10, false);
            return(View(files));
        }
Esempio n. 13
0
        //o파일 입출력 클래스 생성
        public void makeEpoch(string root, string station)
        {
            var addEpoch  = new FileRepository();
            var eachEpoch = new eachEpoch();

            var stream = new FileStream(root, FileMode.Open);
            var reader = new StreamReader(stream, System.Text.Encoding.ASCII);

            var readline = reader.ReadLine();

            var signalNum = 0;

            while (!readline.Contains("TYPES OF OBSERV"))
            {
                readline = reader.ReadLine();
            }
            signalNum = int.Parse(readline.Substring(4, 2));
            while (!reader.ReadLine().Contains("END OF HEADER"))
            {
            }

            /*
             * for (int i = 0; i < 21; i++)
             * {
             *  reader.ReadLine();
             * }
             */

            int j      = 1;
            int row    = 1;
            int numSat = 1;

            string[] sat    = new string[50];
            int      year   = 1;
            int      month  = 1;
            int      day    = 1;
            int      hour   = 1;
            int      minute = 1;
            int      second = 1;

            for (int i = 0; i < 5760; i++)
            {
                string fileLine = "";

                if (j == 1)
                {
                    fileLine = reader.ReadLine();
                    row      = row + 1;

                    if (fileLine.Length > 0)
                    {
                        year   = int.Parse(fileLine.Substring(1, 2));
                        month  = int.Parse(fileLine.Substring(4, 2));
                        day    = int.Parse(fileLine.Substring(7, 2));
                        hour   = int.Parse(fileLine.Substring(10, 2));
                        minute = int.Parse(fileLine.Substring(13, 2));
                        second = int.Parse(fileLine.Substring(16, 2));
                        numSat = int.Parse(fileLine.Substring(30, 2));

                        for (int k = 0; k < 12; k++)
                        {
                            var satName = fileLine.Substring((3 * k) + 32, 3);
                            sat[k] = satName;
                        }

                        if (numSat > 12)
                        {
                            fileLine = reader.ReadLine();
                            row      = row + 1;
                            fileLine = fileLine.Trim();
                            //numSat = 12 + (fileLine.Length / 3);

                            for (int k = 0; k < fileLine.Length / 3; k++)
                            {
                                var satName = fileLine.Substring(k * 3, 3);
                                sat[12 + k] = satName;
                            }
                            if (numSat > 24)
                            {
                                fileLine = reader.ReadLine();
                                row      = row + 1;
                                fileLine = fileLine.Trim();

                                for (int k = 0; k < fileLine.Length / 3; k++)
                                {
                                    var satName = fileLine.Substring(k * 3, 3);
                                    sat[24 + k] = satName;
                                }
                            }
                        }
                    }
                    j = j + 2;
                }
                else
                {
                    for (int k = 0; k < numSat; k++)
                    {
                        fileLine = reader.ReadLine();
                        row      = row + 1;
                        if (fileLine.Length > 0)
                        {
                            //여기서 부터 L1, L2 기록

                            /*
                             * Phase  : Units in whole cycles of carrier
                             * Code   : Units in meters
                             */
                            var    satName      = sat[k];
                            double observation1 = 0;
                            double observation2 = 0;
                            if (fileLine.Substring(2, 12).Length > 0)
                            {
                                observation1 = double.Parse(fileLine.Substring(2, 12));
                            }
                            if (fileLine.Length > 16)
                            {
                                if (fileLine.Substring(17, 12).Trim().Length > 0)
                                {
                                    observation2 = double.Parse(fileLine.Substring(17, 12));
                                }
                            }

                            eachEpoch.id           = (year * 10000000000 + month * 100000000 + day * 1000000 + hour * 10000 + minute * 100 + second).ToString() + satName;
                            eachEpoch.year         = year;
                            eachEpoch.month        = month;
                            eachEpoch.day          = day;
                            eachEpoch.hour         = hour;
                            eachEpoch.minute       = minute;
                            eachEpoch.second       = second;
                            eachEpoch.satNum       = int.Parse(satName.Substring(1, 2));
                            eachEpoch.satType      = satName.Substring(0, 1);
                            eachEpoch.station      = station;
                            eachEpoch.observation1 = observation1;
                            eachEpoch.observation2 = observation2;

                            addEpoch.Add(eachEpoch);
                        }
                        if (signalNum > 10)
                        {
                            reader.ReadLine();
                            row = row + 1;
                        }
                        reader.ReadLine();
                        row = row + 1;
                        j   = j + 1;
                    }
                    j = 1;
                }
            }
        }
Esempio n. 14
0
        public ActionResult Index(int?page, int?id, string filename, string nowdo, string path, string search)
        {
            int pag = page ?? 1;

            ViewData["page"] = pag;
            IPagedList <xiayun.Model.File> files;

            if (path == null)
            {
                path             = "Home";
                ViewData["path"] = "Home";
            }
            else
            {
                ViewData["path"] = path;
            }


            if (id != null)
            {
                xiayun.Model.File file  = fileinfo.Find(x => x.Id == id);
                string            npath = file.FilePath + '/' + file.FileName;

                IEnumerable <xiayun.Model.File> filess = fileinfo.FindAll(x => x.FilePath.StartsWith(npath));
                if (nowdo == "delete")
                {
                    foreach (var item in filess)
                    {
                        fileinfo.Delete(item);
                    }
                    fileinfo.Delete(file);
                }

                else if (nowdo == "update")
                {
                    foreach (var item in filess)
                    {
                        //item.FilePath.Replace("we", "nihao");
                        item.FilePath = item.FilePath.Replace(file.FileName, filename);
                        item.UpTime   = DateTime.Now.ToString();
                        fileinfo.Update(item);

                        /*
                         * item.FilePath.Replace("we", "he");
                         * item.UpTime = DateTime.Now.ToString();
                         * fileinfo.Update(item);
                         */
                    }

                    file.FileName = filename;
                    file.UpTime   = DateTime.Now.ToString();
                    fileinfo.Update(file);
                }
                fileinfo.SaveChanges();
            }
            if (nowdo == "add")
            {
                string foldername = "新建文件夹";
                int    i          = 0;
                while (true)
                {
                    bool p = fileinfo.Exist(x => x.FileName == foldername + i);
                    if (p == false)
                    {
                        break;
                    }
                    i++;
                }
                fileinfo.Add(new xiayun.Model.File
                {
                    FileName = foldername + i,
                    Belong   = Session["user"].ToString(),
                    FileExt  = "folder",
                    UpTime   = DateTime.Now.ToString(),
                    FilePath = path,
                });
                fileinfo.SaveChanges();
            }
            if (search != null)
            {
                files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & x.FileName.Contains(search), x => x.UpTime, pag, 10, false);
                ViewData["search"] = search;
                return(View(files));
            }
            files = fileinfo.GetPaged(x => x.Belong == Session["user"].ToString() & x.FilePath == path, x => x.UpTime, pag, 10, false);
            return(View(files));
        }