public void InitFileStream(string path, string key)
        {
            if (this.filesToWrite.ContainsKey(key))
            {
                this.filesToWrite.Remove(key);
            }
            KFile file = KFile.NewKFile(path, KFile.WRITE_MODE);

            this.filesToWrite.Add(key, file);
        }
Beispiel #2
0
 public string SendFiles(List <String> paths)
 {
     foreach (string path in paths)
     {
         Resource rec  = new Resource(true);
         KFile    file = KFile.NewKFile(path, KFile.READ_MODE);
         rec.SetFile(file);
         this.mysentFileController.addStoreResource(rec);
     }
     return("Files was sent ");
 }
 public void WriteFile(string key, byte[] data, int lengthData, int numFrames, int progress)
 {
     try {
         KFile file = this.filesToWrite[key];
         if (numFrames == progress)
         {
             file.Write(data, lengthData);
             file.Close();
             this.filesToWrite.Remove(key);
             return;
         }
         file.Write(data, lengthData);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message + " - no stream");
     }
 }
Beispiel #4
0
        public static KFile NewKFile(string path, int mode)
        {
            KFile file = new KFile(path);

            if (KFile.READ_MODE == mode)
            {
                file.path      = path;
                file.extension = Path.GetExtension(path);
                file.name      = Path.GetFileName(path);
                file.progress  = -1;
                file.myStream  = new FileStream(path, FileMode.Open, FileAccess.Read);
                file.myReader  = new BinaryReader(file.myStream);
                file.numBytes  = file.myStream.Length;
            }
            if (KFile.WRITE_MODE == mode)
            {
                try
                {
                    file.myStream = new FileStream(path, FileMode.Create, FileAccess.Write);
                    file.myWriter = new BinaryWriter(file.myStream);
                }
                catch
                {
                    string newpath = path;
                    string ext     = Path.GetExtension(newpath);
                    int    i       = 1;
                    while (File.Exists(newpath))
                    {
                        newpath = newpath.Insert(newpath.Length - ext.Length, i.ToString());
                        i++;
                    }
                    file.myStream = new FileStream(newpath, FileMode.Create, FileAccess.Write);
                    file.myWriter = new BinaryWriter(file.myStream);
                }
            }
            return(file);
        }
Beispiel #5
0
 public void SetFile(KFile file)
 {
     this.fileToSend = file;
     this.message    = file.GetFileName();
 }