public static void WriteFile(string fName) { VegDET det = new VegDET(); det.Id = Guid.NewGuid(); det.Owner = "Dr. Frank N. Furter, ESQ"; ExcelVegDET excel = new ExcelVegDET(det); CreateListOfPhonySites(det, 4); excel.Save(fName); }
public override UpdateStatus Update(FilestoreFile tempFileUpload, SampleEventMap map) { if (tempFileUpload != null) { FilestoreFile oldFile = this.Get(map); if (oldFile != null) { if (this.CanModify(map)) { VegDET curdet = new VegDET(); ExcelVegDET curexcel = new ExcelVegDET(curdet); curexcel.Load(tempFileUpload); ValidationIssues curIssues = curdet.ValidationIssues; if (curIssues.Count < 1) { VegDET olddet = new VegDET(); ExcelVegDET excel = new ExcelVegDET(olddet); excel.Load(oldFile); ValidationIssues issues = olddet.ValidationIssues; if (issues.Count < 1) //should be this is the old file { UpdateStatus status = null; if (olddet.Surveys.Count < 1) //old file has no data - bare det { if (curdet.Surveys.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.Veg); 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 IVegSurveyProvider depl = VegetationManager.Instance.GetSurveyProvider(this.Context); IVegSampleProvider meas = VegetationManager.Instance.GetSampleProvider(this.Context); if (depl != null && meas != null) { if (depl.CanCreate() && meas.CanCreate()) { List <EntityBundle> bundles = this.GetBundles(map, KnownDetType.Veg); if (bundles != null && bundles.Count >= 5) { if (bundles.Count > 5) { status = this.InitialLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], bundles[3], bundles[4], bundles[5], curdet, depl, meas, item.IsPrivate); } else { status = this.InitialLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], bundles[3], bundles[4], null, curdet, depl, meas, item.IsPrivate); } 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")); } } 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 { IVegSurveyProvider depl = VegetationManager.Instance.GetSurveyProvider(this.Context); IVegSampleProvider meas = VegetationManager.Instance.GetSampleProvider(this.Context); if (depl != null && meas != null) { if (depl.CanCreate() && meas.CanCreate()) { SampleEventMapItem item = map.Get(KnownDetType.Veg); List <EntityBundle> bundles = this.GetBundles(map, KnownDetType.Veg); if (bundles != null && bundles.Count >= 5) { if (bundles.Count > 5) { status = this.DeltaLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], bundles[3], bundles[4], bundles[5], curdet, olddet, depl, meas, map); } else { status = this.DeltaLoad(map.SampleEventId, bundles[0], bundles[1], bundles[2], bundles[3], bundles[4], null, curdet, olddet, depl, meas, map); } 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")); } 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)); }
public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle plotTypes, EntityBundle shrubSpecies, EntityBundle treeSpecies, EntityBundle herbSpecies, EntityBundle nonLiving, bool isPrivate) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); VegDET det = new VegDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + plotTypes.PrincipalOrgId.Identity.ToString(); int ct = 0; foreach (BundleElement cur in sites.Elements) { SiteDTO tmp = new SiteDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Sites.Add(tmp); ct++; } if (ct > 0) //has to be elements in the collection { ct = 0; foreach (BundleElement cur in plotTypes.Elements) { PlotTypeDTO tmp = new PlotTypeDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.PlotTypes.Add(tmp); ct++; } if (ct > 0) { ct = 0; foreach (BundleElement cur in shrubSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.ShrubSpecies.Add(tmp); ct++; } if (treeSpecies != null) { foreach (BundleElement cur in treeSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.TreeSpecies.Add(tmp); ct++; } } if (herbSpecies != null) { foreach (BundleElement cur in herbSpecies.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.HerbSpecies.Add(tmp); ct++; } } if (nonLiving != null) { foreach (BundleElement cur in nonLiving.Elements) { SpeciesDTO tmp = new SpeciesDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.NonLiving.Add(tmp); } } if (ct > 0) //have to have at least one of herb, tree, shrub to POSSIBLY be valid { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelVegDET excel = new ExcelVegDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } } return(null); }
public static void ReadFile(string fName) { Console.WriteLine("reading workbook named [{0}]", fName); VegDET det = new VegDET(); ExcelVegDET excel = new ExcelVegDET(det); excel.Load(fName); ValidationIssues issues = det.ValidationIssues; if (issues.Count > 0) { foreach (ValidationIssue issue in issues) { Console.WriteLine(issue.IssueMessage); } //return; } Console.WriteLine("Custom property Name: {0}, Value: {1}", "oncorID", det.Id); Console.WriteLine("Custom property Name: {0}, Value: {1}", "oncorOwner", det.Owner); int count = 1; foreach (var dto in det.Sites.Values) { Console.WriteLine("Site Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.Elevations.Values) { Console.WriteLine("Elevations Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.Herbs.Values) { Console.WriteLine("Herbs Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.HerbSpecies.Values) { Console.WriteLine("HerbSpecies Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.NonLiving.Values) { Console.WriteLine("NonLiving Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.PlotTypes.Values) { Console.WriteLine("PlotTypes Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.Shrubs.Values) { Console.WriteLine("Shrubs Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.ShrubSpecies.Values) { Console.WriteLine("Shrubs Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.Surveys.Values) { Console.WriteLine("Surveys Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.Trees.Values) { Console.WriteLine("Trees Row: {0}, Value: {1}", count++, dto); } count = 1; foreach (var dto in det.TreeSpecies.Values) { Console.WriteLine("TreeSpecies Row: {0}, Value: {1}", count++, dto); } Console.WriteLine("Closing workbook named [{0}]", fName); }