Esempio n. 1
0
        /// <summary>
        ///  Initializes a file instance by a absolute path, child name and type.
        ///  This can be userful when filtering non existing files.
        /// </summary>
        /// <param name="man">Reference to manager that requested the file.</param>
        /// <param name="absolute_path">Absolute file/directory path.</param>
        /// <param name="child_name">Name of child file for the directory.</param>
        /// <param name="type">Type of file to create.</param>
        public LocalFile(ManagerEngine man, string absolute_path, string child_name, FileType type)
        {
            this.manager = man;

            if (child_name != "")
                this.absPath = PathUtils.ToUnixPath(absolute_path + "/" + child_name);
            else
                this.absPath = PathUtils.ToUnixPath(absolute_path);

            if (type == FileType.Directory)
                this.dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.absPath));
            else if (type == FileType.File)
                this.fileInfo = new FileInfo(PathUtils.ToOSPath(this.absPath));
            else {
                // Create file info or dir info
                this.fileInfo = new FileInfo(PathUtils.ToOSPath(this.absPath));
                if (!this.fileInfo.Exists) {
                    this.dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.absPath));
                    this.fileInfo = null;
                }

                if (this.fileInfo != null)
                    this.absPath = PathUtils.ToUnixPath(this.fileInfo.FullName);

                if (this.dirInfo != null)
                    this.absPath = PathUtils.RemoveTrailingSlash(PathUtils.ToUnixPath(this.dirInfo.FullName));
            }

            this.config = this.manager.Config;
            this.configResolved = false;
            this.triggerEvents = true;
        }
        public int Insert(string userId, string path, FileType fileType)
        {
            int id = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Files_Insert"
               , inputParamMapper: delegate(SqlParameterCollection paramCollection)
               {
                   paramCollection.AddWithValue("@UserId", userId);
                   paramCollection.AddWithValue("@Path", path);
                   paramCollection.AddWithValue("@FileType", fileType);

                   SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                   p.Direction = System.Data.ParameterDirection.Output;

                   paramCollection.Add(p);

               }, returnParameters: delegate(SqlParameterCollection param)
               {
                   int.TryParse(param["@Id"].Value.ToString(), out id);
               }

               );

            return id;
        }
Esempio n. 3
0
        static string GetFileName(string name, FileType type)
        {
            var sb = new StringBuilder(256);

            if (type == FileType.Package)
                sb.Append("p_");
            if (type == FileType.File)
                sb.Append("f_");
            if (type == FileType.Directory)
                sb.Append("d_");

            sb = sb.Append(name);
            sb = sb.Replace("\\", "-");
            sb = sb.Replace("/", "-");
            sb = sb.Replace(":", string.Empty);

            if (type == FileType.Directory && sb[sb.Length - 1] != '-')
                sb.Append('-');

            sb = sb.Append(".html");

            if (type != FileType.File && type != FileType.Directory && type != FileType.SourceFile)
            {
                sb = sb.Replace(" ", string.Empty);
                sb = sb.Replace("-g&lt;", "(");
                sb = sb.Replace("&lt;", "(");
                sb = sb.Replace("&gt;", ")");
            }

            return sb.ToString();
        }
 public static void GetFilesFromDirectory(FileType type, ObservableCollection<CodeFile> collection, string directoryPath)
 {
     if (Directory.Exists(directoryPath))
     {
         string[] extensions = null;
         switch (type)
         {
             case FileType.All:
                 extensions = new string[] { ".cs", ".vb" };
                 break;
             case FileType.CS:
                 extensions = new string[] { ".cs" };
                 break;
             case FileType.VB:
                 extensions = new string[] { ".vb" };
                 break;
         }
         string[] files = Directory.GetFiles(directoryPath);
         foreach (string file in files)
         {
             if (!extensions.Contains<string>(Path.GetExtension(file)))
                 continue;
             CodeFile cFile = new CodeFile();
             PopulateCodeFile(cFile, file);
             collection.Add(cFile);
         }
     }
 }
Esempio n. 5
0
        public override void SaveFileAs(string fileName, FileType type)
        {
            // step 1: creation of a document-object
            iTextSharp.text.Document myDocument = new iTextSharp.text.Document(PageSize.A4.Rotate());
            try
            {
                // step 2:
                // Now create a writer that listens to this doucment and writes the document to desired Stream.
                PdfWriter.GetInstance(myDocument, new FileStream(fileName, FileMode.CreateNew));

                // step 3:  Open the document now using
                myDocument.Open();

                // step 4: Now add some contents to the document
                myDocument.Add(new iTextSharp.text.Paragraph(parsedFile.contentRaw));

            }
            catch (iTextSharp.text.DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }
            myDocument.Close();
        }
 public static List<string> GetTypeList(FileType type) {
     short i = 0;
     switch (type) {
         case FileType.Compressed:
             i = 0;
             break;
         case FileType.Audio:
             i = 1;
             break;
         case FileType.Document:
             i = 2;
             break;
         case FileType.Image:
             i = 3;
             break;
         case FileType.SourceCode:
             i = 4;
             break;
         case FileType.Executable:
             i = 5;
             break;
         case FileType.Video:
             i = 6;
             break;
     }
     return TypesList[i];
 }
 public File getFileWithType( FileType filetype )
 {
     foreach ( File file in Files )
         if ( file.FileType == filetype )
             return file;
     return null;
 }
Esempio n. 8
0
        public static List<Module> read_Templates_To_Memory(string inpath, FileType fileType)
        {
            int i = 0;
            string filepath = "";
            List<Module> modules = new List<Module>();

            try
            {
                foreach (char c in cset)
                {
                    for (i = 0; i < (1 << 10); i++)
                    {
                        filepath = string.Format("{0}{1}({2}).{3}", inpath, c, i, fileType);

                        if (!File.Exists(filepath)) { break; }
                        modules.Add(read_Template_From_Text_To_Memory(c, filepath));
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("read_Templates_To_Memory:" + e.Message);
            }
            return modules;
        }
Esempio n. 9
0
        public ActionResult AddType()
        {
            string error = "";
            CurtDevDataContext db = new CurtDevDataContext();

            #region Form Submission
            try {
                if (Request.Form.Count > 0) {

                    // Save form values
                    string fileType = (Request.Form["fileType"] != null) ? Request.Form["fileType"] : "";

                    // Validate the form fields
                    if (fileType.Length == 0) throw new Exception("Name is required.");

                    // Create the new customer and save
                    FileType new_type = new FileType {
                        fileType1 = fileType
                    };

                    db.FileTypes.InsertOnSubmit(new_type);
                    db.SubmitChanges();
                    return RedirectToAction("Types");
                }
            } catch (Exception e) {
                error = e.Message;
            }
            #endregion

            ViewBag.error = error;
            return View();
        }
        protected static LightSpeedCleanStrategyBase CreateCleaningStrategy(FileType fileType)
        {
            switch (fileType)
            {
                case FileType.WordDocument:
                    return new LightSpeedWordCleaningStrategy();
                case FileType.WordDocumentX:
                case FileType.WordDocumentMacroX:
                case FileType.WordDocumentTemplateX:
                case FileType.WordDocumentMacroTemplateX:
                    return new LightSpeedWordXCleaningStrategy();

                case FileType.ExcelSheet:
                    return new LightSpeedExcelCleaningStrategy();
                case FileType.ExcelSheetX:
                case FileType.ExcelSheetMacroX:
                case FileType.ExcelSheetTemplateX:
                case FileType.ExcelSheetMacroTemplateX:
                    return new LightSpeedExcelXCleaningStrategy();

                case FileType.PowerPoint:
                    return new LightSpeedPowerPointCleaningStrategy();
                case FileType.PowerPointX:
                case FileType.PowerPointMacroX:
                case FileType.PowerPointTemplateX:
                case FileType.PowerPointMacroTemplateX:
				case FileType.PowerPointShowX:
				case FileType.PowerPointMacroShowX:
                    return new LightSpeedPowerPointXCleaningStrategy();

                default:
                    return null;
            }
        }
Esempio n. 11
0
        protected void DoTests(FileHeader header, FileType expectedFileType, string expectedExtension)
        {
            string fileTypeErrorMessage;
               switch (expectedFileType)
               {
              default:
              case FileType.Other:
                 fileTypeErrorMessage = "Unknown file type";
                 break;
              case FileType.Image:
                 fileTypeErrorMessage = "Should be an image file";
                 break;
              case FileType.Video:
                 fileTypeErrorMessage = "Should be a video file";
                 break;
              case FileType.Audio:
                 fileTypeErrorMessage = "Should be an audio file";
                 break;
              case FileType.Swf:
                 fileTypeErrorMessage = "Should be a flash file";
                 break;
               }

               var extensionErrorMessage = "File format should be " + expectedExtension;

               Assert.NotNull(header, "File header returned null");
               Assert.AreEqual(header.Type, expectedFileType, fileTypeErrorMessage);
               Assert.AreEqual(header.Extension, expectedExtension, extensionErrorMessage);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="source"></param>
        /// <param name="filePath"></param>
        public CodeCoverageStringTextSource(string source, string filePath)
        {
            _fileFound = source != null;

            if (!string.IsNullOrWhiteSpace (filePath)) {
                _filePath = filePath;
                if (_filePath.IndexOfAny(Path.GetInvalidPathChars()) < 0
                    && Path.GetExtension(_filePath).ToLowerInvariant() == ".cs" ) {
                    _fileType = FileType.CSharp;
                }
                if (_fileFound) {
                    try { 
                        _fileTime = System.IO.File.GetLastWriteTimeUtc (this._filePath); 
                    } catch (Exception e) {
                        e.InformUser();
                    }
                }

            }

            _textSource = string.IsNullOrEmpty(source) ? string.Empty : source;

            if (_textSource != string.Empty) {
                _lines = InitLines ();
            }

        }
Esempio n. 13
0
 public Paste(string directory,FileType fileType)
 {
     InitializeComponent();
     // add / to directory name if it doesn't already end in one
     this.directory = directory.Last()=='\\'?directory:directory+"\\";
     this.fileType = fileType;
 }
Esempio n. 14
0
        public WikiFile CreateFile(string fileName, Guid listingVersionGuid, Guid vendorGuid, HttpPostedFile file, FileType fileType, List<UmbracoVersion> v, string dotNetVersion, bool mediumTrust)
        {
            // we have to convert to the uWiki UmbracoVersion :(

            List<UmbracoVersion> vers = new List<UmbracoVersion>();

            foreach (var ver in v)
            {
                vers.Add(UmbracoVersion.AvailableVersions()[ver.Version]);
            }

            //Create the Wiki File
            var uWikiFile = WikiFile.Create(fileName, listingVersionGuid, vendorGuid, file, GetFileTypeAsString(fileType), vers);
            //return the IMediaFile

            //Convert to Deli Media file
            var MediaFile = GetFileById(uWikiFile.Id);

            // If upload is package, extract the package XML manifest and check the version number + type [LK:2016-06-12@CGRT16]
            if (fileType == FileType.package)
            {
                var minimumUmbracoVersion = GetMinimumUmbracoVersion(MediaFile);
                if (!string.IsNullOrWhiteSpace(minimumUmbracoVersion))
                {
                    MediaFile.Versions = new List<UmbracoVersion>() { new UmbracoVersion { Version = minimumUmbracoVersion } };
                }
            }

            MediaFile.DotNetVersion = dotNetVersion;
            SaveOrUpdate(MediaFile);
            return MediaFile;
        }
Esempio n. 15
0
File: Media.cs Progetto: Pr0xY/mywmp
 public Media(string title, string length, string path, FileType fileType)
 {
     Title = title;
     Duree = length;
     Path = path;
     Type = fileType;
 }
        private async Task<string> ReadFileAsync(StorageFolder storageFolder, StorageFile storageFile, FileType fileType)
        {
            var rootFolder = FileSystem.Current.LocalStorage;

            var folder = await rootFolder.GetFolderAsync(storageFolder.ToString());

            if (folder == null)
            {
                return null;
            }

            var file = await folder.GetFileAsync(string.Format(@"{0}.{1}", storageFile, fileType));

            if (file == null)
            {
                return null;
            }

            var stream = await file.OpenAsync(FileAccess.Read);

            if (stream == null)
            {
                return null;
            }

            using (var streamReader = new StreamReader(stream))
            {
                return streamReader.ReadToEnd();
            }
        }
 public MeshReaderWriter(int vertexCount, int faceCount, string path)
 {
     string ext = Path.GetExtension(path);
     if (ext.Equals(".obj"))
     {
         type = FileType.OBJ;
     }
     else if (ext.Equals(".xyz"))
     {
         type = FileType.XYZ;
     }
     else if (ext.Equals(".ply"))
     {
         type = FileType.PLY;
     }
     if (type != null)
     {
         System.Console.WriteLine(path);
         this.path = path;
         this.vertexCount = vertexCount;
         this.faceCount = faceCount;
         this.dest = File.Create(path);
         this.writer = new StreamWriter(dest);
         AddHeader();
     }
 }
Esempio n. 18
0
        public PTableHeader(int version)
        {
            Ensure.Nonnegative(version, "version");

            FileType = FileType.PTableFile;
            Version = version;
        }
Esempio n. 19
0
        public CasetteStream(IDeviceMapping deviceMap, String tiFileName, FileType fileType, 
                             FileOpenMode fileMode, int recSize)
        {
            String nativeFileName = deviceMap.GetNativeFileName(tiFileName);

            if (recordSize > allowableRecordSizes[allowableRecordSizes.Length-1]) throw new ArgumentOutOfRangeException("recordSize");
            if (fileType == FileType.Display) throw new NotImplementedException("Display mode not yet supported");

            foreach(int i in allowableRecordSizes)
            {
                if (i > recSize)
                {
                    this.recordSize = i;
                    break;
                }
            }
            this.fileType = fileType;
            this.fileMode = fileMode;

            if (this.fileMode == FileOpenMode.Output)
            {
                CreateBuffer();
                stream = NativeFile.Open(nativeFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
            }
            else
            {
                buffer = new byte[this.recordSize];
                stream = NativeFile.Open(nativeFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Извлекает данные из файла с данными
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static List<Data> ParseFile(string fileName)
 {
     var fileLines = File.ReadAllLines(fileName);
     string Marker = fileLines[0];
     fileType = GetFileType(Marker);
     List<Data> result = Data.Parse(fileLines, fileType);
     return result;
 }
Esempio n. 21
0
 public string getFileTypeXMLTag(FileType type)
 {
     if (type == FileType.INPUT)
         return "Input";
     else if (type == FileType.OUTPUT) return "Output";
     logMessage("Can't determine the XML tag of the unkwown file type");
     return "UnkwnownType";
 }
        public PointCloudZipStream(string dir, string fileName, FileType type)
        {
            this.FileName = String.IsNullOrEmpty(this.FileName) ? DateTime.Now.ToFileTimeUtc().ToString() : fileName;
            this.FileName += "." + type.Extension();

            this.DirPath = dir;
            this.FileType = type;
        }
            public MoveAction(PipelineController controller, string path, string newpath, FileType type)
            {
                _con = controller;

                this.path = path;
                this.newpath = newpath;
                this.type = type;
            }
            public MoveAction(PipelineController controller, string[] paths, string[] newpaths, FileType[] types)
            {
                _con = controller;

                this.paths = paths;
                this.newpaths = newpaths;
                this.types = types;
            }
Esempio n. 25
0
        public DocumentCleaner(string inputFilename, string outputFilename, FileType fileType, string extension)
        {
            m_filenameIn = inputFilename;
            m_filenameOut = outputFilename;
            m_ft = fileType;
            m_sFileExtension = extension;

        }
Esempio n. 26
0
 public FileData()
 {
     m_filetype = FileType.Unknown;
     m_readpasswordprotected = false;
     m_writepasswordprotected = false;
     m_documentProtected = false;
     m_fileEncrypted = false;
 }
Esempio n. 27
0
File: Schema.cs Progetto: rmc00/gsf
 /// <summary>
 /// Creates a new instance of the <see cref="Schema"/>.
 /// </summary>
 public Schema()
 {
     m_version = 1999;
     m_nominalFrequency = 60.0D;
     m_fileType = FileType.Binary;
     m_timeFactor = 1.0D;
     SampleRates = null;
 }
Esempio n. 28
0
        private TextReader _reader; // internal text reader

        #endregion Fields

        #region Constructors

        internal ResourceTextReader(FileType fileType, Stream stream)
        {
            _delimiter = LocBamlConst.GetDelimiter(fileType);
            if(stream == null)
                throw new ArgumentNullException("stream");

            _reader = new StreamReader(stream);
        }
Esempio n. 29
0
 public SearchFile(IList<string> containers, string path,
     string fileName, FileType type)
 {
     Containers = containers;
     FilePath = path;
     FileName = fileName;
     Type = type;
 }
Esempio n. 30
0
        /// <summary>
        ///  Initializes a file instance by a absolute path, child name and type.
        ///  This can be userful when filtering non existing files.
        /// </summary>
        /// <param name="man">Reference to manager that requested the file.</param>
        /// <param name="absolute_path">Absolute file/directory path.</param>
        /// <param name="child_name">Name of child file for the directory.</param>
        /// <param name="type">Type of file to create.</param>
        public BaseFile(ManagerEngine man, string absolute_path, string child_name, FileType type)
        {
            this.manager = man;

            if (child_name != null && child_name != "")
                this.absPath = PathUtils.ToUnixPath(absolute_path + "/" + child_name);
            else
                this.absPath = PathUtils.ToUnixPath(absolute_path);
        }