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); }