public CommandProvider(Func<IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { FluentTest.ProviderInstance = null; this.lazyWebDriver = new Lazy<IWebDriver>(() => { var webDriver = webDriverFactory(); if (FluentTest.ProviderInstance == null) FluentTest.ProviderInstance = webDriver; else FluentTest.IsMultiBrowserTest = true; webDriver.Manage().Cookies.DeleteAllCookies(); webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); if (FluentAutomation.Settings.WindowHeight.HasValue && FluentAutomation.Settings.WindowWidth.HasValue) { webDriver.Manage().Window.Size = new Size(FluentAutomation.Settings.WindowWidth.Value, FluentAutomation.Settings.WindowHeight.Value); } return webDriver; }); this.fileStoreProvider = fileStoreProvider; }
public CommandProvider(Func <IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { FluentTest.ProviderInstance = null; _webDriver = InitializeWebDriver(webDriverFactory); _fileStoreProvider = fileStoreProvider; }
public XMLAccess(bool p_IgnoreTest) { string PlatformVersion; TL = new TraceLogger("", "XMLAccess"); // Create a new trace logger TL.Enabled = GetBool(TRACE_XMLACCESS, TRACE_XMLACCESS_DEFAULT); // Get enabled / disabled state from the user registry RunningVersions(TL); // Include version information sw = new Stopwatch(); // Create the stowatch instances swSupport = new Stopwatch(); FileStore = new AllUsersFileSystemProvider(); // FileStore = New IsolatedStorageFileStoreProvider ProfileMutex = new System.Threading.Mutex(false, PROFILE_MUTEX_NAME); // Bypass test for initial setup by MigrateProfile because the profile isn't yet set up if (!p_IgnoreTest) { try { if (!FileStore.Exists(@"\" + VALUES_FILENAME)) { throw new Exceptions.ProfileNotFoundException("Utilities Error Base key does not exist"); } PlatformVersion = GetProfile(@"\", "PlatformVersion"); } // OK, no exception so assume that we are initialised catch (Exception ex) { TL.LogMessageCrLf("XMLAccess.New Unexpected exception:", ex.ToString()); throw; } } }
public override bool Delete(SampleEventMap map, bool fileOnly) { if (map != null) { SampleEventMapItem id = map.Get(KnownDetType.Veg); if (id != null) { IFileStoreProvider p = FileStore; if (p != null) { IVegSurveyProvider srvProv = VegetationManager.Instance.GetSurveyProvider(this.Context); if (srvProv != null && srvProv.CanDelete()) { if (p.Delete(id.DetId)) { if (fileOnly) { return(true); } return(DeleteData(map)); } } } } } return(false); }
protected virtual void Dispose(bool disposing) { if (!this.disposedValue) { try { this.FileStore = (IFileStoreProvider)null; this.TL.Enabled = false; this.TL.Dispose(); this.TL = (TraceLogger)null; this.sw.Stop(); this.sw = (Stopwatch)null; this.swSupport.Stop(); this.swSupport = (Stopwatch)null; this.ProfileMutex.Close(); this.ProfileMutex = (Mutex)null; } catch (Exception ex) { //ProjectData.SetProjectError(ex); int num = (int)Interaction.MsgBox((object)("XMLAccess:Dispose Exception - " + ex.ToString()), MsgBoxStyle.OkOnly, (object)null); //ProjectData.ClearProjectError(); } } this.disposedValue = true; }
internal CommandController(IDatabase database, IFileStoreProvider fileStore) { this.database = database; this.fileStore = fileStore; var thread = new Thread(SaveLoop); thread.Start(); }
public override bool Delete(SampleEventMap map, bool fileOnly) { if (map != null) { SampleEventMapItem id = map.Get(KnownDetType.Fish); if (id != null) { IFileStoreProvider p = FileStore; if (p != null) { ICatchEffortProvider wqProv = FishManager.Instance.GetCatchEffortProvider(this.Context); if (wqProv != null && wqProv.CanDelete()) { if (p.Delete(id.DetId)) { if (fileOnly) { return(true); } return(DeleteData(map)); } } } } } return(false); }
public CommandProvider(Func <IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { FluentTest.ProviderInstance = null; this.lazyWebDriver = new Lazy <IWebDriver>(() => { var webDriver = webDriverFactory(); if (FluentTest.ProviderInstance == null) { FluentTest.ProviderInstance = webDriver; } else { FluentTest.IsMultiBrowserTest = true; } webDriver.Manage().Cookies.DeleteAllCookies(); webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); if (FluentAutomation.Settings.WindowHeight.HasValue && FluentAutomation.Settings.WindowWidth.HasValue) { webDriver.Manage().Window.Size = new Size(FluentAutomation.Settings.WindowWidth.Value, FluentAutomation.Settings.WindowHeight.Value); } return(webDriver); }); this.fileStoreProvider = fileStoreProvider; }
public XMLAccess(bool p_IgnoreTest) { this.disposedValue = false; this.TL = new TraceLogger("", "XMLAccess"); this.TL.Enabled = RegistryCommonCode.GetBool("Trace XMLAccess", false); VersionCode.RunningVersions(this.TL); this.sw = new Stopwatch(); this.swSupport = new Stopwatch(); this.FileStore = (IFileStoreProvider) new AllUsersFileSystemProvider(); this.ProfileMutex = new Mutex(false, "ASCOMProfileMutex"); if (p_IgnoreTest) { return; } try { if (!this.FileStore.get_Exists("\\Profile.xml")) { throw new ProfileNotFoundException("Utilities Error Base key does not exist"); } this.GetProfile("\\", "PlatformVersion"); } catch (Exception ex) { //ProjectData.SetProjectError(ex); this.TL.LogMessageCrLf("XMLAccess.New Unexpected exception:", ex.ToString()); throw; } }
private void Scavenge() { prov = FileStoreManager.Instance.GetProvider(); if (prov != null) { scavengeTimer = new System.Threading.Timer(this.DoScavenge, null, 0, 60000); //1 minute } }
public FilestoreFile Create(SampleEventMap map, EntityBundle sites, EntityBundle instruments) { if (this.CanModify(map)) { Guid id = Guid.NewGuid(); WaterQualityDET det = new WaterQualityDET(); det.Id = id; det.Owner = "originator:" + sites.PrincipalOrgId.Identity.ToString() + ":" + instruments.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 instruments.Elements) { InstrumentDTO tmp = new InstrumentDTO(); tmp.Key = cur.LocalKey; tmp.Name = cur.DisplayName; det.Instruments.Add(tmp); ct++; } if (ct > 0) { det.Validate(); if (det.ValidationIssues.Count == 0) { IFileStoreProvider prov = this.FileStore; if (prov != null) { FilestoreFile fil = prov.Make(id); if (fil != null) { ExcelWaterQualityDET excel = new ExcelWaterQualityDET(det); excel.Save(fil); fil.Flush(); fil.Seek(0, System.IO.SeekOrigin.Begin); return(fil); } } } } } } return(null); }
public CommandProvider(IFileStoreProvider fileStoreProvider) { this.fileStoreProvider = fileStoreProvider; this.portNumber = this.getRandomUnusedPort(); this.phantomWebSocket = new WebSocketServer(string.Format("ws://0.0.0.0:{0}", this.portNumber)); this.OpenPhantomWebSocket(); this.phantomProcess = this.startPhantomJS(this.portNumber); this.waitForPhantomReady(); }
public CommandProvider(Func <IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { FluentTest.ProviderInstance = null; this.lazyWebDriver = new Lazy <IWebDriver>(() => { var webDriver = webDriverFactory(); if (!FluentTest.IsMultiBrowserTest && FluentTest.ProviderInstance == null) { FluentTest.ProviderInstance = webDriver; } webDriver.Manage().Cookies.DeleteAllCookies(); webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); // If an alert is open, the world ends if we touch the size property. Ignore this and let it get set by the next command chain try { if (this.Settings.WindowMaximized) { // store window size back before maximizing so we can 'undo' this action if necessary var windowSize = webDriver.Manage().Window.Size; if (!this.Settings.WindowWidth.HasValue) { this.Settings.WindowWidth = windowSize.Width; } if (!this.Settings.WindowHeight.HasValue) { this.Settings.WindowHeight = windowSize.Height; } webDriver.Manage().Window.Maximize(); } else if (this.Settings.WindowHeight.HasValue && this.Settings.WindowWidth.HasValue) { webDriver.Manage().Window.Size = new Size(this.Settings.WindowWidth.Value, this.Settings.WindowHeight.Value); } else { var windowSize = webDriver.Manage().Window.Size; this.Settings.WindowHeight = windowSize.Height; this.Settings.WindowWidth = windowSize.Width; } } catch (UnhandledAlertException) { } this.mainWindowHandle = webDriver.CurrentWindowHandle; return(webDriver); }); this.fileStoreProvider = fileStoreProvider; }
public CommandProvider(Func <IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { this.lazyWebDriver = new Lazy <IWebDriver>(() => { var webDriver = webDriverFactory(); webDriver.Manage().Cookies.DeleteAllCookies(); webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); return(webDriver); }); this.fileStoreProvider = fileStoreProvider; }
internal CommandController(IDatabase database, IFileStoreProvider fileStore) { // This is so that we can read config settings from DLL config file string configFile = Assembly.GetExecutingAssembly().Location + ".config"; AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile); ConfigurationManager.RefreshSection("appSettings"); this.database = database; this.fileStore = fileStore; var thread = new Thread(SaveLoop); thread.Start(); }
public CommandProvider(Func<IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { this.lazyWebDriver = new Lazy<IWebDriver>(() => { var webDriver = webDriverFactory(); webDriver.Manage().Cookies.DeleteAllCookies(); webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); return webDriver; }); this.fileStoreProvider = fileStoreProvider; }
internal CommandController(IDatabase database, IFileStoreProvider fileStore) { _waitPeriodDictionary = new Dictionary<Runspace, DirectoryWaitPeriod>(); // This is so that we can read config settings from DLL config file string configFile = Assembly.GetExecutingAssembly().Location + ".config"; AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile); ConfigurationManager.RefreshSection("appSettings"); this.database = database; this.fileStore = fileStore; // We don't want write data to disk very often. // It's fine to lose jump data for last 2 seconds. saveTimer = new Timer(SaveCallback, null, 0, 2 * 1000); }
public CommandProvider(Func<IWebDriver> webDriverFactory, IFileStoreProvider fileStoreProvider) { FluentTest.ProviderInstance = null; this.lazyWebDriver = new Lazy<IWebDriver>(() => { var webDriver = webDriverFactory(); if (!FluentTest.IsMultiBrowserTest && FluentTest.ProviderInstance == null) FluentTest.ProviderInstance = webDriver; webDriver.Manage().Cookies.DeleteAllCookies(); webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); // If an alert is open, the world ends if we touch the size property. Ignore this and let it get set by the next command chain try { if (this.Settings.WindowMaximized) { // store window size back before maximizing so we can 'undo' this action if necessary var windowSize = webDriver.Manage().Window.Size; if (!this.Settings.WindowWidth.HasValue) this.Settings.WindowWidth = windowSize.Width; if (!this.Settings.WindowHeight.HasValue) this.Settings.WindowHeight = windowSize.Height; webDriver.Manage().Window.Maximize(); } else if (this.Settings.WindowHeight.HasValue && this.Settings.WindowWidth.HasValue) { webDriver.Manage().Window.Size = new Size(this.Settings.WindowWidth.Value, this.Settings.WindowHeight.Value); } else { var windowSize = webDriver.Manage().Window.Size; this.Settings.WindowHeight = windowSize.Height; this.Settings.WindowWidth = windowSize.Width; } } catch (UnhandledAlertException) { } this.mainWindowHandle = webDriver.CurrentWindowHandle; return webDriver; }); this.fileStoreProvider = fileStoreProvider; }
public override FilestoreFile Get(SampleEventMap map) { if (map != null) { SampleEventMapItem id = map.Get(KnownDetType.Fish); if (id != null) { IFileStoreProvider p = FileStore; if (p != null) { return(p.Get(id.DetId)); //TODO add validation checking if we want } } } return(null); }
internal CommandController(IDatabase database, IFileStoreProvider fileStore) { _waitPeriodDictionary = new Dictionary <Runspace, DirectoryWaitPeriod>(); // This is so that we can read config settings from DLL config file string configFile = Assembly.GetExecutingAssembly().Location + ".config"; AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configFile); ConfigurationManager.RefreshSection("appSettings"); this.database = database; this.fileStore = fileStore; // We don't want write data to disk very often. // It's fine to lose jump data for last 2 seconds. saveTimer = new Timer(SaveCallback, null, 0, 2 * 1000); }
public void Close() { lock (this) { if (this.inner != null) { this.CleanClose(); IFileStoreProvider prov = FileStoreManager.Instance.GetProvider(); if (prov != null) { prov.Update(this); } } } }
protected bool DeleteFile(SampleEventMap map, KnownDetType type) { SampleEventMapItem id = map.Get(type); if (id != null) { IFileStoreProvider p = this.FileStore; if (p != null) { if (p.Delete(id.DetId)) { map.Remove(id.DetId); return(true); } } } return(false); }
private Guid CreateCsvFile(Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict, Dictionary <CompoundIdentity, Tuple <int, SamplingEvent> > eventDict, Dictionary <CompoundIdentity, Tuple <int, WaterQualityDeployment> > deploymentDict, List <Tuple <int, WaterQualityMeasurement> > measurementList, Dictionary <CompoundIdentity, Organization> orgDict, Dictionary <CompoundIdentity, FieldTrip> fieldTripDict, Dictionary <CompoundIdentity, FieldActivity> fieldActivityDict, Dictionary <CompoundIdentity, Project> projectDict) { IFileStoreProvider provider = FileStoreManager.Instance.GetProvider(); //Setting up temp file FilestoreFile deployFile = provider.MakeTemp(DateTime.UtcNow.AddHours(4)); CsvDb csv = CsvDb.Create(deployFile); CreateSampleEventCsv(csv, eventDict, orgDict, fieldTripDict, fieldActivityDict, projectDict); CreateMeasurementsCsv(csv, siteDict, eventDict, deploymentDict, measurementList); CreateSitesCsv(csv, siteDict); csv.Flush(); csv.Dispose(); deployFile.Close(); return(deployFile.FileId); }
// IDisposable protected virtual void Dispose(bool disposing) { if (!this.disposedValue) { try { FileStore = null; // Clean up the filestore and keycache TL.Enabled = false; // Clean up the logger TL.Dispose(); TL = null; sw.Stop(); // Clean up the stopwatches sw = null; swSupport.Stop(); swSupport = null; ProfileMutex.Close(); ProfileMutex = null; } catch (Exception ex) { Interaction.MsgBox("XMLAccess:Dispose Exception - " + ex.ToString()); } } this.disposedValue = true; }
public override void Handle(HttpContext context, CancellationToken cancel) { if (context != null) { UserIdentityBase user = Security.Session.GetUser(context); if (user != null) { UserSecurityContext ctx = new UserSecurityContext(user); string localUrl = RestUtils.LocalUrl(this, context.Request); string meth = RestUtils.StripLocal(this.BaseUrl, localUrl); if (!string.IsNullOrEmpty(meth)) { if (meth.StartsWith(Upload, StringComparison.OrdinalIgnoreCase)) { string err = null; try { string fName = MetaInfo.GetFileName(context); //TODO -- add origin filename handling if (fName != null && MetaInfo.SupportedUploadType(fName)) //this might be a bogus way to go { if (prov == null) { prov = FileStoreManager.Instance.GetProvider(); } if (prov != null) { Stream input = context.Request.Body; if (input != null) { FilestoreFile fil = prov.MakeTemp(); if (fil != null) { input.CopyTo(fil); fil.Flush(); fil.Close(); fil.FileName = fName; prov.Update(fil); RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, "\"" + fil.FileId.ToString() + "\"")); return; } else { err = "failed to make"; } } else { err = "no file received"; } } else { err = "no provider"; } } else { err = "unsupported file extension"; //this might be a bogus way to go } } catch { err = "unknown error"; } if (err == null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed, "\"" + err + "\"")); } return; } if (meth.StartsWith(Download, StringComparison.OrdinalIgnoreCase)) { string err = null; try { //this should be a Guid string string filename = Uri.UnescapeDataString(meth.Substring(Download.Length)); Guid fileId; if (Guid.TryParse(filename, out fileId)) { if (prov == null) { prov = FileStoreManager.Instance.GetProvider(); } if (prov != null) { FilestoreFile fil = prov.Get(fileId); if (fil != null) { if (fil.Length > -1) { //send the bytes of a file in the response body context.Response.Headers.Add("Content-Disposition", "attachment ; filename=\"" + fil.FileName + "\""); context.Response.StatusCode = HttpStatusCodes.Status200OK; context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; fil.CopyTo(context.Response.Body); return; } else { err = "no stream"; } } else { err = "no such file"; } } else { err = "no provider"; } } else { err = "fileid is not legal"; } } catch { err = "unknown error"; } if (err == null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed, "\"" + err + "\"")); } return; } } } else { context.Response.StatusCode = HttpStatusCodes.Status401Unauthorized; return; } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }
public FileComponentService(IFileStoreProvider provider, IFileRepository repository) { _provider = provider; _repository = repository; }
static void Main(string[] args) { ConfigurationManager.Instance.Bootstrap(); ConfigurationManager.Instance.Initialize(); ConfigurationManager.Instance.Start(); Console.WriteLine("ConfigurationManager: " + ConfigurationManager.Instance.State.ToString()); LogManager.Instance.Bootstrap(); LogManager.Instance.Initialize(); LogManager.Instance.Start(); Console.WriteLine("LogManager: " + LogManager.Instance.State.ToString()); FileStoreManager.Instance.Initialize(); FileStoreManager.Instance.Start(); Console.WriteLine("FileStore: " + FileStoreManager.Instance.State.ToString()); IFileStoreProvider prov = FileStoreManager.Instance.GetProvider(); Console.WriteLine("Prov: " + (prov == null).ToString()); if (prov != null) { Guid id = Guid.NewGuid(); FilestoreFile fil = prov.Make(id); if (fil != null) { Console.WriteLine("Got file"); string s = "Hello from testing"; TextWriter wr = new StreamWriter(fil); for (int i = 0; i < 100; i++) { wr.WriteLine(s); } wr.Flush(); wr.Close(); fil.Dispose(); Console.WriteLine("Done"); fil = prov.Get(id); if (fil != null) { Console.WriteLine("Opened file"); wr = new StreamWriter(fil); for (int i = 0; i < 100; i++) { wr.WriteLine(s); } wr.Flush(); wr.Close(); fil.Dispose(); Console.WriteLine("Wrote"); prov.Delete(id); Console.WriteLine("Done"); } } prov.DeleteExpired(); } Console.WriteLine("Enter to exit"); Console.ReadLine(); }
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); }
private Guid CreateExcelFile(Dictionary <CompoundIdentity, Tuple <int, Site> > siteDict, Dictionary <CompoundIdentity, Tuple <int, SamplingEvent> > eventDict, Dictionary <CompoundIdentity, Tuple <int, WaterQualityDeployment> > deploymentDict, List <Tuple <int, WaterQualityMeasurement> > measurementList, Dictionary <CompoundIdentity, Organization> orgDict, Dictionary <CompoundIdentity, FieldTrip> fieldTripDict, Dictionary <CompoundIdentity, FieldActivity> fieldActivityDict, Dictionary <CompoundIdentity, Project> projectDict) { IFileStoreProvider provider = FileStoreManager.Instance.GetProvider(); //Setting up file and Excel Workbook FilestoreFile deployFile = provider.MakeTemp(DateTime.UtcNow.AddHours(4)); XlWorkbook book = new XlWorkbook(); XlWorksheets sheets = book.Worksheets; //Generating Sampling Event Sheet XlSchema eventSchema = GetSampleEventSchema(); XlWorksheet eventSheet = sheets.AddWorksheet("SamplingEvents", XlColor.White, eventSchema); XlRows eventRows = eventSheet.Rows; var orderedEvents = eventDict.OrderBy(x => x.Value.Item1); foreach (var evt in orderedEvents) { string orgName = na; if (orgDict.ContainsKey(evt.Value.Item2.PrincipalOrgId)) { orgName = orgDict[evt.Value.Item2.PrincipalOrgId].Name; } string ftripName = na; string factivityName = na; string projName = na; if (fieldTripDict.ContainsKey(evt.Value.Item2.FieldTripId)) { FieldTrip ftrip = fieldTripDict[evt.Value.Item2.FieldTripId]; ftripName = ftrip.Name; if (fieldActivityDict.ContainsKey(ftrip.FieldActivityId)) { FieldActivity factivity = fieldActivityDict[ftrip.FieldActivityId]; factivityName = factivity.Name; if (projectDict.ContainsKey(factivity.ProjectId)) { projName = projectDict[factivity.ProjectId].Name; } } } List <string> evtItems = new List <string>(); evtItems.Add(orgName); evtItems.Add(projName); evtItems.Add(factivityName); evtItems.Add(ftripName); evtItems.Add(evt.Value.Item2.Name); evtItems.Add(evt.Value.Item1.ToString()); evtItems.Add(evt.Value.Item2.Description); //evtItems.Add(evt.Value.Item2.DateRange.Min.ToString()); //evtItems.Add(evt.Value.Item2.DateRange.Max.ToString()); SchemaRowData row = new SchemaRowData(eventSchema, evtItems); eventRows.AddRow(row); } //Generating Deployment/Measurement Sheet XlSchema measSchema = GetDeployMeasurementSchema(); XlWorksheet measSheet = sheets.AddWorksheet("WaterQualityMeasurements", XlColor.White, measSchema); XlRows measRows = measSheet.Rows; var orderedMeasurements = measurementList.OrderBy(x => x.Item1); foreach (var meas in orderedMeasurements) { WaterQualityDeployment deploy = deploymentDict[meas.Item2.DeploymentId].Item2; WaterQualityMeasurement measurement = meas.Item2; int eventIndex = eventDict[deploy.SampleEventId].Item1; //deploy.SiteId could be a dangling reference string siteFK = na; if (siteDict.ContainsKey(deploy.SiteId)) { siteFK = siteDict[deploy.SiteId].Item1.ToString(); } List <string> measItems = new List <string>(); measItems.Add(meas.Item1.ToString()); measItems.Add(deploy.Name); measItems.Add(deploy.Description); measItems.Add(eventIndex.ToString()); measItems.Add(siteFK); measItems.Add(deploy.Range.StartDate.ToString()); measItems.Add(deploy.Range.EndDate.ToString()); measItems.Add(measurement.SampleDate.ToString()); measItems.Add(measurement.SurfaceElevation.ToString()); measItems.Add(measurement.Temperature.ToString()); measItems.Add(measurement.pH.ToString()); measItems.Add(measurement.DissolvedOxygen.ToString()); measItems.Add(measurement.Conductivity.ToString()); measItems.Add(measurement.Salinity.ToString()); measItems.Add(measurement.Velocity.ToString()); SchemaRowData row = new SchemaRowData(measSchema, measItems); measRows.AddRow(row); } //Generating Site Sheet XlSchema siteSchema = GetSiteSchema(); XlWorksheet siteSheet = sheets.AddWorksheet("Sites", XlColor.White, siteSchema); XlRows siteRows = siteSheet.Rows; var orderedSites = siteDict.OrderBy(x => x.Value.Item1); foreach (var site in orderedSites) { Site s = site.Value.Item2; List <string> siteItems = new List <string>(); siteItems.Add(site.Value.Item1.ToString()); siteItems.Add(s.Name); siteItems.Add(s.Description); IGeometry2 <double> geom = s.Location; if (geom != null) { if (geom is PolygonBag2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as PolygonBag2 <double>).ToString()); } else if (geom is Polygon2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as Polygon2 <double>).ToString()); } else if (geom is Polyline2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as Polyline2 <double>).ToString()); } else if (geom is PolylineBag2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as PolylineBag2 <double>).ToString()); } else if (geom is Point2 <double> ) { siteItems.Add(WktUtils.ToWkt(geom as Point2 <double>).ToString()); } } else { siteItems.Add(""); } Point2 <double> geom2 = s.LocationMark; if (geom2 != null) { siteItems.Add(WktUtils.ToWkt(geom2 as Point2 <double>).ToString()); } else { siteItems.Add(""); } SchemaRowData row = new SchemaRowData(siteSchema, siteItems); siteRows.AddRow(row); } book.Save(deployFile); deployFile.Flush(); deployFile.Close(); deployFile.Dispose(); return(deployFile.FileId); }
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)); }