コード例 #1
0
ファイル: Core.cs プロジェクト: cmksoftdev/CMK_CMS
 public void CreateFile(string name)
 {
     if (selectedProject != null)
     {
         var file = new ProjectFile {
             FilePath = SelectedProject.Name + "\\" + name
         };
         fileManager.Add(file);
         SelectedProject.Config.ProjectFiles.Add(file);
         projectManager.Save();
     }
 }
コード例 #2
0
        // POST api/values
        public bool Post(string department)
        {
            var mgr    = new FileManager(Helper.DepartmentFile);
            var result = mgr.Add(department);

            return(result);
        }
コード例 #3
0
        public override IFile <FilterFileItem> OpenFile(string fileName)
        {
            FilterFile filterFile = new FilterFile();

            try
            {
                SetStatus("OpenFile:enter: " + fileName);

                if (FileManager.Exists(x => String.Compare(x.Tag, fileName, true) == 0))
                {
                    SetStatus("file already open:" + fileName);
                    return(filterFile);
                }

                filterFile = (FilterFile)ReadFile(fileName);
                ManageFilterFileItem(filterFile);

                ManageFileProperties(fileName, filterFile);
                FileManager.Add(filterFile);
                Settings.AddFilterFile(fileName);
                OnPropertyChanged("FilterFileManager");
                SetStatus("OpenFile:exit: " + fileName);
                return(filterFile);
            }
            catch (Exception e)
            {
                SetStatus(string.Format("error opening filter file:{0}:{1}", fileName, e.ToString()));
                return(filterFile);
            }
        }
コード例 #4
0
 public bool SignUpManager(string firstName, string lastName, string password)
 {
     if (isValidName(firstName) && isValidName(lastName))
     {
         Manager manager = new Manager(firstName.Trim(), lastName.Trim(), password);
         //Now Here we have to check the Tree
         //   if (Universal.instance.managerTree == null)
         //  {
         //      BTree newMaster = new BTree();
         //      newMaster.put(manager.id + "", "mng\\" + manager.id);
         //       Universal.instance.studentTree = newMaster;
         //   }
         //   else
         //   {
         //       Universal.instance.studentTree.put(manager.id + "", "mng\\" + manager.id);
         //   }
         //   FileStream file = File.Create("mng\\" + manager.id);
         //   BinaryFormatter bf = new BinaryFormatter();
         //   bf.Serialize(file, manager);
         //   file.Close();
         FileManager.Add <Manager>(Universal.instance.managerTree, manager, manager.id, fileDirectoryPlusName: dir + "stdFile");
         Universal.instance.SaveTree("mngTree", Universal.instance.managerTree);
         return(true);
     }
     else
     {
         return(false);
     }
     //End of Method
 }
コード例 #5
0
        public override IFile <FilterFileItem> NewFile(string LogName, ObservableCollection <FilterFileItem> fileItems = null)
        {
            FilterFile filterFile = new FilterFile();

            ManageFilterFileItem(filterFile);

            FileManager.Add(ManageFileProperties(LogName, filterFile));

            Settings.AddFilterFile(LogName);
            OnPropertyChanged("FilterFileManager");
            return(filterFile);
        }
コード例 #6
0
 public bool SignUpStudent(string firstName, string lastName, string major)
 {
     if (isValidName(firstName) && isValidName(lastName))
     {
         Student student = new Student(firstName.Trim(), lastName.Trim(), major);
         FileManager.Add <Student>(Universal.instance.studentTree, student, student.id, fileDirectoryPlusName: dir + "stdFile");
         Universal.instance.SaveTree("stdTree", Universal.instance.studentTree);
         return(true);
     }
     else
     {
         return(false);
     }
     //End of Method
 }
コード例 #7
0
        public override IFile <LogFileItem> NewFile(string fileName, ObservableCollection <LogFileItem> logFileItems = null)
        {
            SetStatus("NewFile:enter: " + fileName);
            LogFile logFile = new LogFile();

            if (logFileItems != null)
            {
                logFile.ContentItems = logFileItems;
            }

            FileManager.Add(ManageFileProperties(fileName, logFile));
            logFile.Modified = true;
            Settings.AddLogFile(fileName);
            OnPropertyChanged("LogFileManager");
            SetStatus("NewFile:exit: " + fileName);
            return(logFile);
        }
コード例 #8
0
 public bool AddCourse(int code, String name, int mstId, String time, String examTime, int val)
 {
     if (isValidName(name) && ((Math.Log10(code) + 1) >= 5 && (SearchMaster(mstId) != null)))
     {
         //We have to check if master exists
         Master mst = SearchMaster(mstId);
         if (mst != null)
         {
             Course course = new Course(name.Trim(), Convert.ToInt32(code), val, time, examTime, mst);
             FileManager.Add <Course>(Universal.instance.courseTree, course, course.code, fileDirectoryPlusName: dir + "crsFile");
             Universal.instance.SaveTree("crsTree", Universal.instance.courseTree);
             return(true);
         }
         return(false);
     }
     else
     {
         return(false);
     }
     //End of Method
 }
コード例 #9
0
        /// <summary>
        /// Uploads the student submission document.
        /// </summary>
        /// <param name="studentId">The student id.</param>
        /// <param name="assignmentSubmissionViewModel">The assignment submission view model.</param>
        public void UploadStudentSubmissionDocument(int studentId, AssignmentSubmissionViewModel assignmentSubmissionViewModel)
        {
            try
            {
                Submission submission = ObjectMapper.Map <AssignmentSubmissionViewModel, Model.Entities.Submission>(assignmentSubmissionViewModel);
                submission.StudentId = studentId;
                SubmissionManager.SubmissionForAssignmentAlreadyExists(ref submission);

                // Create Submission if does not exist
                if (submission == null || submission.Id == 0)
                {
                    submission = SubmissionManager.Add(submission);
                }

                // UploadFile
                UniEBoard.Model.Entities.File uploadFile = FileFactory.CreateSubmissionContentFile(submission.Id, submission.AssignmentId, assignmentSubmissionViewModel.UploadFile) as File;
                FileManager.Add(uploadFile);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing);
            }
        }
コード例 #10
0
ファイル: LogFileManager.cs プロジェクト: wxknxxzj/textFilter
        public override IFile <LogFileItem> NewFile(string fileName, ObservableCollection <LogFileItem> fileItems = null)
        {
            SetStatus("NewFile:enter: " + fileName);
            LogFile file = new LogFile();

            // make temp file
            string tempFilePath = Path.GetTempFileName();

            file.Tag = tempFilePath;

            if (fileItems != null)
            {
                file.ContentItems = fileItems;
            }

            SaveFile(tempFilePath, file);
            FileManager.Add(ManageFileProperties(fileName, file));
            file.Tag   = tempFilePath;
            file.IsNew = true;
            Settings.AddLogFile(fileName);
            OnPropertyChanged("LogFileManager");
            return(file);
        }
コード例 #11
0
        public override IFile <LogFileItem> OpenFile(string fileName)
        {
            IFile <LogFileItem> logFile = new LogFile();

            try
            {
                SetStatus("OpenFile:enter: " + fileName);

                if (FileManager.Exists(x => String.Compare(x.Tag, fileName, true) == 0))
                {
                    SetStatus("file already open:" + fileName);
                    return(logFile);
                }

                if (File.Exists(fileName))
                {
                    logFile.FileName     = Path.GetFileName(fileName);
                    logFile.Tag          = fileName;
                    logFile.ContentItems = ((LogFile)ReadFile(fileName)).ContentItems;
                    FileManager.Add(logFile);
                    Settings.AddLogFile(fileName);
                }
                else
                {
                    SetStatus("log file does not exist:" + fileName);
                    Settings.RemoveLogFile(fileName);
                }

                SetStatus("OpenFile:exit: " + fileName);
                return(logFile);
            }
            catch (Exception e)
            {
                SetStatus("OpenFile:exception: " + e.ToString());
                return(logFile);
            }
        }
コード例 #12
0
        public IHttpActionResult CreateFromResult([FromBody] ResultFileUploadModel model)
        {
            var userId = Request.GetUserId();

            if (userId < 0)
            {
                return(Unauthorized());
            }

            if (model == null)
            {
                return(BadRequest("file is null"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var fileName = $"{Guid.NewGuid():N}.{model.Extension}";

            var directory          = Path.Combine(HttpRuntime.AppDomainAppPath, FileManager.RELATIVE_PATH);
            var directoryThumbnail = Path.Combine(HttpRuntime.AppDomainAppPath, FileManager.RELATIVE_PATH_THUMBNAIL);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (!Directory.Exists(directoryThumbnail))
            {
                Directory.CreateDirectory(directoryThumbnail);
            }


            var filePath = Path.Combine(directory, fileName);

            var filePathThumbnail = Path.Combine(directoryThumbnail, fileName);

            System.IO.File.WriteAllText(filePath, model.FileContent);

            //var image = Image.FromFile(filePath);

            //var thumbnail = (Image)new Bitmap(image, new Size(200, 200));

            //thumbnail.Save(filePathThumbnail);

            var urlPath          = GetUrlPath(FileManager.RELATIVE_PATH, fileName);
            var urlPathThumbnail = GetUrlPath(FileManager.RELATIVE_PATH_THUMBNAIL, fileName);

            var fileInfo = new FileInfo(filePath);

            var file = new File
            {
                Extension     = model.Extension,
                FilePath      = urlPath,
                ThumbnailPath = urlPathThumbnail,
                Size          = (int)(fileInfo.Length / 1024),
                RowState      = RowState.Created,
                UploadedAt    = DateTime.Now,
                UploadedBy    = userId
            };

            _fileManager.Add(file);

            return(Ok(Mapper.Map <FileViewModel>(file)));
        }
コード例 #13
0
        private bool LoadFile(string filename)
        {
            /**
             * Loading a file:
             *  1. Local file which can be used 1-on-1
             *  2. "Local" file which needs rewriting (FTP Location Service)
             *  3. Remote file, not accessible via Samba.
             *  4. Remote file, accessible via Samba.
             *
             * Situations 1, 2 and 4 can be resolved using a simple filename rewriter. In case (1)
             * no rewriting has to be done, in case (2) complete rewriting has be done and in case (3)
             * partial rewriting has to be done.
             *
             * Situation 3 can be resolved by using the Source DBGP command, but that leaves us in the dark
             * as to what other files are available which makes debugging rather annoying when dealing
             * with large systems. It can also take a very long time with loading large files, at least
             * with the current implementation.
             */

            string baseFile = System.IO.Path.GetFileName(filename);

            string remoteFilename = filename;
            string localFilename  = filename;

            xdc.Forms.SourceFileForm sff = _fileMgr.getFormByRemoteFilename(filename);

            if (sff != null)
            {
                sff.Focus();
                return(true);
            }

            xdc.Forms.SourceFileForm f = new xdc.Forms.SourceFileForm(_client, filename);


            f.FormClosed += new FormClosedEventHandler(SourceFileForm_FileClosed);
            f.Text        = baseFile;
            f.TabText     = localFilename;

            /* When we can't find the file specified, offer a way to rewrite the path */
            if (!System.IO.File.Exists(filename))
            {
                if (_fileLoader == null)
                {
                    xdc.Forms.FileHandlingForm filehandlingForm = new xdc.Forms.FileHandlingForm(filename);
                    DialogResult handlerResult = filehandlingForm.ShowDialog();

                    if (handlerResult != DialogResult.OK)
                    {
                        MessageBox.Show("Can't debug without a source file. Terminating debug session.", "No file loaded.");
                        this.StopDebuggingSession();
                        return(false);
                    }

                    _fileLoader = FileLoaderFactory.Create(filehandlingForm.SelectedFileLoader);
                    _fileLoader.setClient(_client);
                }

                bool fileLoaded = false;

                if (_fileLoader.DetermineLocalFilename(filename, ref localFilename))
                {
                    if (_fileLoader.OpenFile(f, localFilename))
                    {
                        fileLoaded = true;
                    }
                }

                if (!fileLoaded)
                {
                    MessageBox.Show("Can't debug without a source file. Terminating debug session.", "No file loaded");
                    this.StopDebuggingSession();
                    return(false);
                }
            }
            else
            {
                /* The user might've opened a file that appears to be local (opened via network, for instance)
                 * that should be mapped to a remote path. If we have a fileLoader instance, see if it
                 * can rewrite the file for us. */

                if (_fileLoader != null)
                {
                    string tmpRemoteFilename = "";
                    if (_fileLoader.DetermineRemoteFilename(localFilename, ref tmpRemoteFilename))
                    {
                        f.TabText = tmpRemoteFilename;

                        /* The filename in the SourceFileForm is always considered
                         * to be the filename expected by xdebug, so update it to
                         * the remote version */
                        f.setFilename(tmpRemoteFilename);
                        filename = tmpRemoteFilename;
                    }
                }

                f.LoadFile(localFilename);
            }

            _fileMgr.Add(filename, localFilename, f);
            f.Show(this.dockPanel, DockState.Document);

            closeToolStripMenuItem.Enabled = true;

            // We have to collect all the bookmarks added and removed. This way
            // XdebugClient is able to restore bookmarks whenever a script is rerun.
            f.getBookmarkManager().Added   += new BookmarkEventHandler(BreakpointAdded);
            f.getBookmarkManager().Removed += new BookmarkEventHandler(BreakpointRemoved);

            return(true);
        }
コード例 #14
0
        /**
         * Initializes main file and BTrees.
         */
        public Universal()
        {
            if (instance == null)
            {
                instance = this;
                if (!File.Exists(dir + "mngFile"))
                {
                    FileStream mngFile = File.Create(dir + "mngFile");
                    mngFile.Close();
                }
                if (File.Exists("mngTree"))
                {
                    //Tree File exists.
                    FileStream      mngTreeFile = File.Open("mngTree", FileMode.Open);
                    BinaryFormatter bf          = new BinaryFormatter();
                    if (new FileInfo("mngTree").Length == 0)
                    {
                        //Tree File is empty.
                        BTree   mngTree = new BTree();
                        Manager manager = new Manager();
                        mngTree.put(manager.id, 0);
                        instance.managerTree = mngTree;
                        bf.Serialize(mngTreeFile, mngTree);
                        FileManager.Add <Manager>(mngTree, new Manager(), manager.id, fileDirectoryPlusName: dir + "mngFile");
                        // FileStream newFile = File.Create("mng\\" + manager.id);
                        // BinaryFormatter newbf = new BinaryFormatter();
                        //bf.Serialize(newFile, manager);
                        // newFile.Close();
                        mngTreeFile.Close();
                    }
                    else
                    {
                        //Tree File was already created.
                        instance.managerTree = bf.Deserialize(mngTreeFile) as BTree;
                        mngTreeFile.Close();
                    }
                }
                else
                {
                    //Tree File not exists
                    BTree   mngTree = new BTree();
                    Manager manager = new Manager();
                    mngTree.put(manager.id, 0);
                    instance.managerTree = mngTree;
                    FileStream      mngTreeFile = File.Create("mngTree");
                    BinaryFormatter bf          = new BinaryFormatter();
                    bf.Serialize(mngTreeFile, mngTree);
                    FileManager.Add <Manager>(mngTree, new Manager(), manager.id, fileDirectoryPlusName: dir + "mngFile");                                                                                                                            //FileStream newFile = File.Create("mng\\" + manager.id);
                                                                                                                                                                                                                                                      //BinaryFormatter newbf = new BinaryFormatter();
                                                                                                                                                                                                                                                      //bf.Serialize(newFile, manager);
                                                                                                                                                                                                                                                      //newFile.Close();
                    mngTreeFile.Close();
                }

                if (!File.Exists("mstFile"))
                {
                    FileStream mstFile = File.Create("mstFile");
                    mstFile.Close();
                }
                if (File.Exists("mstTree"))
                {
                    //Tree File exists.
                    FileStream      mstTreeFile = File.Open("mstTree", FileMode.Open);
                    BinaryFormatter bf          = new BinaryFormatter();
                    if (new FileInfo("mstTree").Length == 0)
                    {
                        //Tree File is empty.
                        BTree mstTree = new BTree();
                        instance.masterTree = mstTree;
                        bf.Serialize(mstTreeFile, mstTree);
                        mstTreeFile.Close();
                    }
                    else
                    {
                        //Tree File was already created.
                        instance.masterTree = bf.Deserialize(mstTreeFile) as BTree;
                        mstTreeFile.Close();
                    }
                }
                else
                {
                    //Tree File not exists
                    BTree mstTree = new BTree();
                    instance.masterTree = mstTree;
                    FileStream      mstFile = File.Create("mstTree");
                    BinaryFormatter bf      = new BinaryFormatter();
                    bf.Serialize(mstFile, mstTree);
                    mstFile.Close();
                }

                if (!File.Exists("stdFile"))
                {
                    FileStream stdFile = File.Create("stdFile");
                    stdFile.Close();
                }
                if (File.Exists("stdTree"))
                {
                    //Tree File exists.
                    FileStream      stdTreeFile = File.Open("stdTree", FileMode.Open);
                    BinaryFormatter bf          = new BinaryFormatter();
                    if (new FileInfo("stdTree").Length == 0)
                    {
                        //Tree File is empty.
                        BTree stdTree = new BTree();
                        instance.studentTree = stdTree;
                        bf.Serialize(stdTreeFile, stdTree);
                        stdTreeFile.Close();
                    }
                    else
                    {
                        //Tree File was already created.
                        instance.studentTree = bf.Deserialize(stdTreeFile) as BTree;
                        stdTreeFile.Close();
                    }
                }
                else
                {
                    //Tree File not exists
                    BTree stdTree = new BTree();
                    instance.studentTree = stdTree;
                    FileStream      stdTreeFile = File.Create("stdTree");
                    BinaryFormatter bf          = new BinaryFormatter();
                    bf.Serialize(stdTreeFile, stdTree);
                    stdTreeFile.Close();
                }

                if (!File.Exists("crsFile"))
                {
                    FileStream crsFile = File.Create("crsFile");
                    crsFile.Close();
                }
                if (File.Exists("crsTree"))
                {
                    //File exists.
                    FileStream      crsFile = File.Open("crsTree", FileMode.Open);
                    BinaryFormatter bf      = new BinaryFormatter();
                    if (new FileInfo("crsTree").Length == 0)
                    {
                        //File is empty.
                        BTree crsTree = new BTree();
                        instance.courseTree = crsTree;
                        bf.Serialize(crsFile, crsTree);
                        crsFile.Close();
                    }
                    else
                    {
                        //File was already created.
                        instance.courseTree = bf.Deserialize(crsFile) as BTree;
                        crsFile.Close();
                    }
                }
                else
                {
                    //File not exists
                    BTree crsTree = new BTree();
                    instance.courseTree = crsTree;
                    FileStream      crsTreeFile = File.Create("crsTree");
                    BinaryFormatter bf          = new BinaryFormatter();
                    bf.Serialize(crsTreeFile, crsTree);
                    crsTreeFile.Close();
                }
            }
        }