void UploaderThread() { while (file.Position < filesz) { Int64 blksz; Int64 nchunk = 512 * 1024; if (nchunk > filesz - file.Position) nchunk = filesz - file.Position; byte[] data = new byte[nchunk]; blksz = file.Read(data, 0, data.Length); currentsz += blksz; counter++; UploadData ud = new UploadData(); ud.Counter = counter; ud.data = data; ud.Size = blksz; ud.MD5 = MD5Utilities.CalcMD5(data); if (this.net.UploadData(ud) == false) { lasterror = this.net.GetLastError(); this.net.CloseConnection(); file.Close(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new voidy(OnError)); return; } if (CancelThread == true) { lasterror = "Canceled"; this.net.UploadCancel(); this.net.CloseConnection(); file.Close(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new voidy(OnCancel)); return; } this.BeginInvoke(new voidy(UpdatePromille)); } file.Close(); NewUploadDataID nid = this.net.UploadFinalise(); if (nid == null) { lasterror = this.net.GetLastError(); this.net.CloseConnection(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new voidy(OnError)); return; } this.net.CloseConnection(); this.BeginInvoke(new voidy(Reset)); this.BeginInvoke(new newd(OnSuccess), nid); }
void OnSuccess(NewUploadDataID newid) { if (Success != null) Success(newid); }
public RESTStatus FinaliseUpload(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.Upload == null) { ni.Error = "Upload is not running"; ni.ErrorID = ErrorFlags.UploadNotRunning; return(RESTStatus.Fail); } if (ni.Upload.Data == null) { ni.Error = "No data"; ni.ErrorID = ErrorFlags.NoData; return(RESTStatus.Fail); } if (ni.Upload.Size != ni.Upload.CurrentPosition) { ni.Error = "Upload not completed"; ni.ErrorID = ErrorFlags.UploadNotCompleted; return(RESTStatus.Fail); } switch (ni.Upload.FileType) { case FlagsConst.Document_Type_Package: { ni.Upload.Data.Close(); PackageInstaller pki = new PackageInstaller(); string ErrorText; PKGStatus res; PKGRecieptData reciept; List <byte[]> CER = PolicyCertificates.GetPolicyCertificates(sql); if (pki.InstallPackage(Settings.Default.DataPath + ni.Upload.TempFilename, CER, PackageInstaller.InstallMode.TestPackageOnly, false, out ErrorText, out res, out reciept) == false) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + ni.Upload.TempFilename); } catch { } ni.Error = "Package contains errors: " + ErrorText; ni.ErrorID = ErrorFlags.FaultyData; ni.Upload = null; return(RESTStatus.Fail); } string GUID = Guid.NewGuid().ToString(); string Filename = "PKG_" + GUID + ".foxpkg"; string FilenameMeta = "PKG_" + GUID + ".meta.foxpkg"; File.Move(Settings.Default.DataPath + ni.Upload.TempFilename, Settings.Default.DataPath + Filename); if (pki.CreateMetaDataPackage(Settings.Default.DataPath + Filename, Settings.Default.DataPath + FilenameMeta, out ErrorText) == false) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename); } catch { } try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta); } catch { } ni.Error = "Cannot create meta Package: " + ErrorText; ni.ErrorID = ErrorFlags.FaultyData; ni.Upload = null; return(RESTStatus.Fail); } if (pki.PackageInfo(Settings.Default.DataPath + Filename, CER, out ErrorText) == false) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename); } catch { } try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta); } catch { } ni.Error = "Cannot read Package Info: " + ErrorText; ni.ErrorID = ErrorFlags.FaultyData; ni.Upload = null; return(RESTStatus.Fail); } Int64?NewID = null; lock (ni.sqllock) { NewID = sql.InsertMultiDataID("Packages", new SQLData("PackageID", pki.PackageInfoData.PackageID), new SQLData("Version", pki.PackageInfoData.VersionID), new SQLData("Title", pki.PackageInfoData.Title), new SQLData("Description", pki.PackageInfoData.Description), new SQLData("Filename", Filename), new SQLData("MetaFilename", FilenameMeta), new SQLData("Size", ni.Upload.Size)); } if (NewID == null) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename); } catch { } try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta); } catch { } ni.Error = "Error storing data"; return(RESTStatus.Fail); } this.NewID = new NewUploadDataID(); this.NewID.NewID = NewID.Value; this.NewID.FileType = ni.Upload.FileType; ni.Upload = null; break; } //case FlagsConst.Document_Type_Invoice: //case FlagsConst.Document_Type_Voucher: //case FlagsConst.Document_Type_ClientData: // { // ni.Error = "Cannot use this function"; // return (false); // } default: { ni.Error = "Invalid type"; ni.ErrorID = ErrorFlags.InvalidType; return(RESTStatus.Fail); } } return(RESTStatus.Success); }