Esempio n. 1
0
        private void TransferFile(ClientRequest Request)
        {
            FileInfo info = null;

            try
            {
                info = new FileInfo(Path.Combine(this._UpdatingProductDirectory.FullName, Request.Request));
                if (info.Exists)
                {
                    byte[]     buffer = new byte[info.Length];
                    FileStream stream = info.OpenRead();
                    stream.Read(buffer, 0, System.Convert.ToInt32(info.Length));
                    stream.Close();
                    this._FilesTransferred++;
                    Request.BinaryResponse = buffer;
                }
                else
                {
                    Request.Response = "FAILED";
                }
            }
            catch (Exception exception)
            {
                Request.Response = "EXCEPTION";
                Auxiliary.WriteLog(
                    $"Exception while transfering file:\r\nRequested file: {Request.Request}\r\nSource: {((info != null) ? info.FullName : "FileInfo is null")}\r\nException: {exception.ToString()}");
            }
        }
Esempio n. 2
0
        private void ReceiveFile(ClientRequest request)
        {
            Auxiliary.WriteLog("Receiving the file " + request.Request);
            FileInfo info = null;

            try
            {
                ShortFileInfo fromFileList = GetFromFileList(request.Request);
                if (fromFileList != null)
                {
                    this._files.Remove(fromFileList);
                    info = new FileInfo(Path.Combine(this._DestinationDirectory.FullName, fromFileList.FileName));
                    if (!info.Directory.Exists)
                    {
                        info.Directory.Create();
                    }
                    FileStream stream = info.Create();
                    stream.Write(request.BinaryResponse, 0, request.BinaryResponse.Length);
                    stream.Close();
                }
                _filesUpdated++;
            }
            catch (Exception exception)
            {
                Auxiliary.WriteLog(
                    $"Exception while receiving file \"{request.Request}\"\r\nDestination: {((info != null) ? info.FullName : "FileInfo is null")}\r\n{exception.ToString()}");
            }
        }
Esempio n. 3
0
 public void Update(ClientProtocol client, ClientRequest firstRequest, string product, string directory, string tempDirectory)
 {
     this._Client               = client;
     this._Product              = product;
     this._SourceDirectory      = new DirectoryInfo(directory);
     this._DestinationDirectory = (tempDirectory != "") ? new DirectoryInfo(tempDirectory) : this._SourceDirectory;
     this._filesUpdated         = 0;
     client.ResponseReceived   += new ClientProtocol.ResponseReceivedEventHandler(this.ClientResponseReceived);
     Auxiliary.WriteLog(
         $"ClientSideUpdateProtocol::\r\nSourceDirectory: {this._SourceDirectory.FullName}\r\nDestinationDirectory: {this._DestinationDirectory.FullName}");
     firstRequest.Request = "UPDATE " + this._Product;
 }
Esempio n. 4
0
 private void RequestNextFile(ClientRequest Request)
 {
     if (this._files.Count > 0)
     {
         Request.Request = this._files[0].FileName;
         Auxiliary.WriteLog("Requesting the file " + Request.Request);
     }
     else
     {
         this.AbortUpdate(Request);
     }
 }
Esempio n. 5
0
 private void ParseFileList(string files)
 {
     Auxiliary.WriteLog("Files for product " + this._Product + ":\r\n" + files);
     this._files = new List <ShortFileInfo>();
     if (files != ":empty:")
     {
         string[] strArray = files.Split(new char[] { '\n' });
         for (int i = 0; i < strArray.Length; i++)
         {
             ShortFileInfo fileInfo = this.GetFileInfo(strArray[i]);
             if (fileInfo != null)
             {
                 FileInfo info2 = new FileInfo(Path.Combine(this._SourceDirectory.FullName, fileInfo.FileName));
                 if ((!info2.Exists || (info2.LastWriteTimeUtc < fileInfo.CreationTime)) || (System.Convert.ToInt32(info2.Length) != fileInfo.FileSize))
                 {
                     this._files.Add(fileInfo);
                 }
             }
         }
     }
 }