public override UpdateStatus Update(FilestoreFile tempFileUpload, SampleEventMap map) { if (tempFileUpload != null) { FilestoreFile oldFile = this.Get(map); if (oldFile != null) { if (this.CanModify(map)) { FishDET curdet = new FishDET(); ExcelFishDET curexcel = new ExcelFishDET(curdet); curexcel.Load(tempFileUpload); ValidationIssues curIssues = curdet.ValidationIssues; if (curIssues.Count < 1) { FishDET olddet = new FishDET(); ExcelFishDET excel = new ExcelFishDET(olddet); excel.Load(oldFile); ValidationIssues issues = olddet.ValidationIssues; if (issues.Count < 1) //should be this is the old file { UpdateStatus status = null; if (olddet.CatchEfforts.Count < 1) //old file has no data - bare det { if (curdet.CatchEfforts.Count < 1) //nothing to do really, new file has no data either { olddet = null; excel = null; oldFile.Dispose(); curdet = null; curexcel = null; FileStoreManager.Instance.GetProvider().Delete(tempFileUpload); status = new UpdateStatus(UpdateIssue.AllOk); status.Add(new IssueNotice("NoDataInEither", "nothing to do")); return(status); } SampleEventMapItem item = map.Get(KnownDetType.Fish); if (item != null) { olddet = null; //release old reference excel = null; //release old reference //ok, no data in old file, but data in new file -- we have work to do -- handle first-time data insertion ICatchEffortProvider depl = FishManager.Instance.GetCatchEffortProvider(this.Context); ICatchHaulProvider meas = FishManager.Instance.GetCatchHaulProvider(this.Context); IFishProvider fi = FishManager.Instance.GetFishProvider(this.Context); if (depl != null && meas != null && fi != null) { if (depl.CanCreate()) { List <EntityBundle> bundles = this.GetBundles(map, KnownDetType.Fish); if (bundles != null && bundles.Count >= 3) { EntityBundle mac = null; if (bundles.Count > 3) { mac = bundles[3]; } status = this.InitialLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], mac, curdet, depl, meas, fi, item.IsPrivate); if (status != null && status.Issue == UpdateIssue.AllOk) //success, so we overwrite the file { curdet = null; curexcel = null; olddet = null; excel = null; IFileStoreProvider ip = FileStoreManager.Instance.GetProvider(); if (ip.Replace(tempFileUpload, oldFile)) //overwrite the existing file with the new one { tempFileUpload.Dispose(); oldFile.Dispose(); //ip.Delete(tempFileUpload); //may still be references so delete can fail return(status); //we're done here } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("File", "Failed to replace file")); } } } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("Bundles", "Failed to get bundles")); } } else { status = new UpdateStatus(UpdateIssue.Security); status.Add(new IssueNotice("Permissions", "create denied")); } } else { status = new UpdateStatus(UpdateIssue.SystemIssue); status.Add(new IssueNotice("Failure", "Failed to get provider")); } } else { status = new UpdateStatus(UpdateIssue.NoExistingFile); status.Add(new IssueNotice("NoMapEntry", "Failed to find map reference")); } return(status); } else //crap -- this is an update where existing file already had data { ICatchEffortProvider depl = FishManager.Instance.GetCatchEffortProvider(this.Context); ICatchHaulProvider meas = FishManager.Instance.GetCatchHaulProvider(this.Context); IFishProvider fi = FishManager.Instance.GetFishProvider(this.Context); if (depl != null && meas != null && fi != null) { if (depl.CanCreate()) { SampleEventMapItem item = map.Get(KnownDetType.Fish); List <EntityBundle> bundles = this.GetBundles(map, KnownDetType.Fish); if (item != null && bundles != null && bundles.Count >= 3) { EntityBundle mac = null; if (bundles.Count > 3) { mac = bundles[3]; } status = this.DeltaLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], mac, curdet, olddet, depl, meas, fi, map); if (status != null && status.Issue == UpdateIssue.AllOk) //success, so we overwrite the file { curdet = null; curexcel = null; olddet = null; excel = null; //NOTE -- making new file the permanent file and removing old file, then updating map for new file IFileStoreProvider ip = FileStoreManager.Instance.GetProvider(); if (ip.Replace(tempFileUpload, oldFile)) //overwrite the existing file with the new one { tempFileUpload.Dispose(); oldFile.Dispose(); //ip.Delete(tempFileUpload); //may still be references so delete can fail return(status); //we're done here } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("File", "Failed to replace file")); } } } else { status = new UpdateStatus(UpdateIssue.DataIssue); status.Add(new IssueNotice("Bundles", "Failed to get bundles")); } } else { status = new UpdateStatus(UpdateIssue.Security); status.Add(new IssueNotice("Permissions", "create denied")); } } else { status = new UpdateStatus(UpdateIssue.SystemIssue); status.Add(new IssueNotice("Failure", "Failed to get provider")); } return(status); } } else { UpdateStatus stat = new UpdateStatus(UpdateIssue.NoExistingFile); foreach (ValidationIssue cur in issues) { stat.Add(new IssueNotice(cur.IssueCode.ToString(), cur.IssueMessage)); } return(stat); } } else { UpdateStatus stat = new UpdateStatus(UpdateIssue.FileValidationIssues); foreach (ValidationIssue cur in curIssues) { stat.Add(new IssueNotice(cur.IssueCode.ToString(), cur.IssueMessage)); } return(stat); } } else { UpdateStatus status = new UpdateStatus(UpdateIssue.Security); status.Add(new IssueNotice("Permissions", "create denied")); return(status); } } return(new UpdateStatus(UpdateIssue.NoExistingFile)); } return(new UpdateStatus(UpdateIssue.NoFilePosted)); }