public void Should_Throw_Exception_If_Asset_Does_Not_Exist_On_Disk() { string source = "~/image.png"; var file = new FileSystemFile("../../Files/Images/does-not-exist.png"); var asset = new FileSystemAsset(file); Assert.Throws<Exception>(() => factory.Create(asset)); }
public S3V4FileSystemStream(FileSystemFile file, Action<FileSystemStream> disposeAction, int timeoutMs) : base(file, disposeAction) { m_Handle = (S3V4FileSystem.S3V4FSH)file.Handle; m_timeoutMs = timeoutMs; m_Session = file.Session as S3V4FileSystemSession; m_IsNewFile = !S3V4.FileExists(m_Handle.Path, m_Session.AccessKey, m_Session.SecretKey, m_Session.Bucket, m_Session.Region, timeoutMs); }
public void Should_Get_Dimensions_For_Png() { var root = TestHelper.RootPath; IFile file = new FileSystemFile(root + "/Files/Images/ImageHelperTests.png"); SizeF dimensions = ImageHelper.GetDimensions(file); //second call should trigger exception if stream was not closed properly dimensions = ImageHelper.GetDimensions(file); Assert.AreEqual(187.0f, dimensions.Height); Assert.AreEqual(196.0f, dimensions.Width); }
public LocalFileSystemStream(FileSystemFile file, Action<FileSystemStream> disposeAction) : base(file, disposeAction) { var fa = FileAccess.ReadWrite; var hndl = file.Handle as LocalFileSystem.FSH; if (hndl!=null) { if (((FileInfo)hndl.m_Info).IsReadOnly) fa = FileAccess.Read; } m_FS = new FileStream(file.Path, FileMode.OpenOrCreate, fa, FileShare.ReadWrite); }
public void Should_Create_Bundle_From_Asset() { string source = "~/image.png"; var file = new FileSystemFile("../../Files/Images/ImageBundleFactoryTests.png"); var asset = new FileSystemAsset(file); ImageBundle returnBundle = factory.Create(asset); Assert.AreEqual(1, returnBundle.Assets.Count); Assert.AreEqual("093e4bfea387f8f7f7948f0853b29f1d-ImageBundleFactoryTests-png", returnBundle.Name); Assert.AreEqual("image/png", returnBundle.ContentType); Assert.AreEqual(187, returnBundle.Height); Assert.AreEqual(196, returnBundle.Width); }
protected internal override FileSystemStream DoGetFileStream(FileSystemFile file, Action<FileSystemStream> disposeAction) { return new SVNFileSystemStream(file, (fs) => {}); }
protected override void DoHandleWork(WorkContext work) { var fp = work.MatchedVars[VAR_FILE_PATH].AsString("none"); var attachment = work.MatchedVars[VAR_ATTACHMENT].AsBool(true); var chunked = work.MatchedVars[VAR_CHUNKED].AsBool(true); //Sanitize fp = fp.Replace("..", string.Empty) .Replace(":/", string.Empty) .Replace(@"\\", @"\"); string fileName = null; IFileSystem fs = null; FileSystemSession fsSession = null; FileSystemFile fsFile = null; bool exists = false; if (m_UsePortalHub) { var hub = PortalHub.Instance; fs = hub.ContentFileSystem; fileName = m_RootPath != null?fs.CombinePaths(hub.ContentFileSystemRootPath, m_RootPath, fp) : fs.CombinePaths(hub.ContentFileSystemRootPath, fp); fsSession = fs.StartSession(hub.ContentFileSystemConnectParams); fsFile = fsSession[fileName] as FileSystemFile; exists = fsFile != null; } else { fileName = Path.Combine(RootPath, fp); exists = File.Exists(fileName); } try { if (!exists) { var text = StringConsts.FILE_DL_HANDLER_NOT_FOUND_INFO.Args(fileName); if (m_Throw) { throw new HTTPStatusException(WebConsts.STATUS_404, WebConsts.STATUS_404_DESCRIPTION, text); } work.Response.ContentType = ContentType.TEXT; work.Response.Write(text); work.Response.StatusCode = WebConsts.STATUS_404; work.Response.StatusDescription = WebConsts.STATUS_404_DESCRIPTION; return; } if (!work.Response.WasWrittenTo) { work.Response.Buffered = !chunked; } if (m_CacheMaxAgeSec > 0) { work.Response.Headers[HttpResponseHeader.CacheControl] = "private, max-age={0}, must-revalidate".Args(m_CacheMaxAgeSec); } else { work.Response.Headers[HttpResponseHeader.CacheControl] = "no-cache"; } if (fsFile == null) { work.Response.WriteFile(fileName, attachment: attachment); } else { var ext = Path.GetExtension(fsFile.Name); work.Response.ContentType = NFX.Web.ContentType.ExtensionToContentType(ext, NFX.Web.ContentType.BINARY); work.Response.WriteStream(fsFile.FileStream, attachmentName: attachment ? Path.GetFileName(fileName) : null); } } finally { DisposableObject.DisposeAndNull(ref fsSession); } }
protected internal override FileSystemStream DoGetFileStream(FileSystemFile file, Action<FileSystemStream> disposeAction) { return new S3V4FileSystemStream(file, disposeAction, ((S3V4FileSystemSession)file.Session).TimeoutMs); }
protected internal override FileSystemStream DoGetFileStream(FileSystemFile file, Action <FileSystemStream> disposeAction) { return(new LocalFileSystemStream(file, disposeAction)); }
public GoogleDriveStream(FileSystemFile file, Action <FileSystemStream> disposeAction) : base(file, disposeAction) { m_Handle = (GoogleDriveHandle)file.Handle; m_Session = file.Session as GoogleDriveSession; }
protected override void DoHandleWork(WorkContext work) { var fp = work.MatchedVars[VAR_FILE_PATH].AsString("none"); var attachment = work.MatchedVars[VAR_ATTACHMENT].AsBool(true); var chunked = work.MatchedVars[VAR_CHUNKED].AsBool(true); //Sanitize fp = fp.Replace("..", string.Empty) .Replace(":/", string.Empty) .Replace(@"\\", @"\"); //Cut the surrogate out of path, i.e. '/static/img/@@767868768768/picture.png' -> '/static/img/picture.png' fp = CutVersionSegment(fp, m_VersionSegmentPrefix); string fileName = null; IFileSystem fs = null; FileSystemSession fsSession = null; FileSystemFile fsFile = null; bool exists = false; if (m_UsePortalHub) { var hub = App.GetPortalHub(); fs = hub.ContentFileSystem; fileName = m_RootPath != null?fs.CombinePaths(hub.ContentFileSystemRootPath, m_RootPath, fp) : fs.CombinePaths(hub.ContentFileSystemRootPath, fp); fsSession = fs.StartSession(hub.ContentFileSystemConnectParams); fsFile = fsSession[fileName] as FileSystemFile; exists = fsFile != null; } else { fileName = Path.Combine(RootPath, fp); exists = File.Exists(fileName); } try { if (!exists) { var text = StringConsts.FILE_DL_HANDLER_NOT_FOUND_INFO.Args(fileName); if (m_Throw) { throw new HTTPStatusException(WebConsts.STATUS_404, WebConsts.STATUS_404_DESCRIPTION, text); } work.Response.ContentType = ContentType.TEXT; work.Response.Write(text); work.Response.StatusCode = WebConsts.STATUS_404; work.Response.StatusDescription = WebConsts.STATUS_404_DESCRIPTION; return; } if (!work.Response.WasWrittenTo) { work.Response.Buffered = !chunked; } work.Response.SetCacheControlHeaders(CacheControl); if (fsFile == null) { work.Response.WriteFile(fileName, attachment: attachment); } else { var ext = Path.GetExtension(fsFile.Name); work.Response.ContentType = App.GetContentTypeMappings().MapFileExtension(ext).ContentType; work.Response.WriteStream(fsFile.FileStream, attachmentName: attachment ? Path.GetFileName(fileName) : null); } } finally { DisposableObject.DisposeAndNull(ref fsSession); } }
private IEnumerable <StreamSample> enumerateStreamData(enumerateStreamDataArgs args, FileSystemFile file) { var candle = args.Candle; using (var stream = file.FileStream) { //Stream data start per candle if (candle.IsAssigned) { stream.Seek((long)candle.FirstStreamOffset, SeekOrigin.Begin); } else { stream.Seek((long)(m_Streams_DataOffset + sizeof(int)), SeekOrigin.Begin); } DateTime currentTS = candle.TimeStamp; StreamSample[] prior = new StreamSample[(int)StreamID.MAX_ID + 1]; while (true) { var hdr = stream.ReadByte(); if (hdr == -1) { yield break; //END OF FILE } var isDelta = (hdr & 0x80) != 0; var sid = hdr & 0x7f; if ((StreamID)sid > StreamID.MAX_ID || sid >= STREAM_SAMPLE_FACTORIES.Length) { throw new FinancialException(StringConsts.SECDB_STREAM_CORRUPTED_ERROR + "enumerateStreamData(sid>StreamIS.MAX_ID)"); } if (sid == (int)StreamID.Seconds) { int ts = SecDBPrimitives.ReadMidnightSecond(stream); currentTS = new DateTime(m_SystemHeader.Date.Year, m_SystemHeader.Date.Month, m_SystemHeader.Date.Day, 0, 0, 0, DateTimeKind.Utc).AddSeconds(ts); //Second resets all other for (var i = 0; i < prior.Length; i++) { prior[i] = null; } } else { var mcsDiff = SecDBPrimitives.ReadDiffTimeMcs(stream); var ticks = mcsDiff * 10; currentTS = currentTS.AddTicks((long)ticks); } var priorSampleOfThisType = prior[sid]; if (priorSampleOfThisType == null && isDelta) { throw new FinancialException(StringConsts.SECDB_STREAM_CORRUPTED_ERROR + "prior sample of '{0}' type is null, but IsDelta = 1".Args((StreamID)sid)); } var priorSecond = prior[0] as SecondSample; if (sid != 0 && priorSecond == null) { throw new FinancialException(StringConsts.SECDB_STREAM_CORRUPTED_ERROR + "missing SecondSample before '{0}' sample".Args((StreamID)sid)); } var sample = STREAM_SAMPLE_FACTORIES[sid](this, priorSampleOfThisType, currentTS, stream); yield return(sample); prior[sid] = sample; } }//using stream }
protected internal override FileSystemStream DoGetFileStream(FileSystemFile file, Action<FileSystemStream> disposeAction) { return new GoogleDriveStream(file, disposeAction); }
public FileSystemFile(FileSystemFile file) { Data = file.Data; Attributes = file.Attributes; LastWriteTimeUtc = file.LastWriteTimeUtc; }
public SVNFileSystemStream(FileSystemFile file, Action <FileSystemStream> disposeAction) : base(file, disposeAction) { m_wdFile = ((SVNFileSystem.SVNFSH)file.Handle).Item as WebDAV.File; SVNFileSystem fs = file.FileSystem as SVNFileSystem; }
private bool fileExists(FileSystemFile file) { var handle = (S3V4FSH)file.Handle; return(S3V4.FileExists(handle.Path, S3_ACCESSKEY, S3_SECRETKEY, S3_BUCKET, S3_REGION, 0)); }
public void Parallel_CreateWriteReadFile_Async() { using (new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { var fs = FS.FileSystem.Instances[NFX_S3]; var tasks = new List <Task>(); System.Threading.Tasks.Parallel.For(PARALLEL_FROM, PARALLEL_TO, (i) => { var fn = FN_PARALLEL_MASK.Args(i); var session = fs.StartSession(); FileSystemDirectory dir = null; FileSystemFile file = null; var t = session.GetItemAsync(S3_ROOT_FS) .OnOk(item => { dir = item as FileSystemDirectory; return(dir.CreateFileAsync(fn)); }).OnOk(f => { Console.WriteLine("file '{0}' created", f.Name); file = f; return(file.WriteAllTextAsync("Hello, {0}".Args(i))); }) .OnOkOrError(_ => { Console.WriteLine("text written into '{0}'", file.Name); if (file != null && !file.Disposed) { file.Dispose(); Console.WriteLine("file '{0}' disposed", file.Name); } }) .OnOk(() => session.GetItemAsync(fs.CombinePaths(S3_ROOT_FS, fn))) .OnOk(item => { file = item as FileSystemFile; Console.WriteLine("file {0} got", file.Name); return(file.ReadAllTextAsync()); }) .OnOk(txt => { Console.WriteLine("file '{0}' red {1}", file.Name, txt); Assert.AreEqual("Hello, {0}".Args(i), txt); return(file.DeleteAsync()); }) .OnOkOrError(_ => { Console.WriteLine("file '{0}' deleted", file.Name); if (file != null && !file.Disposed) { file.Dispose(); Console.WriteLine("file '{0}' disposed", file.Name); } }) .OnOk(() => session.GetItemAsync(fs.CombinePaths(S3_ROOT_FS, fn))) .OnOk(item => { Assert.IsNull(item); }) .OnOkOrError(_ => { if (!session.Disposed) { session.Dispose(); } }); tasks.Add(t); });//Parallel.For Console.WriteLine("all tasks created"); Task.WaitAll(tasks.ToArray()); Assert.AreEqual(0, fs.Sessions.Count());//checking item registation via .ctor/.dctor Console.WriteLine("done"); } }
protected internal override FileSystemStream DoGetFileStream(FileSystemFile file, Action <FileSystemStream> disposeAction) { return(new SVNFileSystemStream(file, (fs) => {})); }
public OpenWeatherMap(FileSystemFile file) { command = "owm"; owm = new owmAPI(file); methods = new Dictionary <string, Func <CommandEventArgs, Task> >(); queuesRunning = new Dictionary <string, Queue>(); methods.Add("get", async(command) => { if (command.GetArg(1).Equals("")) { await command.Channel.SendMessage(command.Message.User.Mention + " location was not specified."); return; } weatherToday curWeather = owm.querySearch(command.GetArg(1)); if (curWeather.main == null) { await command.Channel.SendMessage("Location not found"); } else { await command.Channel.SendMessage(command.User.Name + " searched for weather for " + command.GetArg(1)); await command.Channel.SendMessage(curWeather.name + " is " + owmAPI.convertToFar(curWeather.main.temp) + " F"); } await command.Message.Delete(); }); methods.Add("queue", async(command) => { int delay; string query = command.GetArg(1); if (command.GetArg(2) == null || !Int32.TryParse(command.GetArg(2), out delay)) { await command.Channel.SendMessage("!weather queue <search> <delay in mins>"); return; } await command.Message.Delete(); if (!queuesRunning.ContainsKey(query)) { await command.Channel.SendMessage(query + " queue has been started"); queuesRunning.Add(query, new WeatherQueue(query, new TimeSpan(0, delay, 0), false, command, owm)); queuesRunning[query].Start(); } else { await command.Channel.SendMessage(query + " queue has already been started"); } }); methods.Add("stopqueue", async(command) => { string query = command.GetArg(1); await command.Message.Delete(); if (queuesRunning.ContainsKey(query)) { queuesRunning[query].Stop(); queuesRunning.Remove(query); await command.Channel.SendMessage(query + " queue stopped"); } else { await command.Channel.SendMessage(query + " queue not found"); } }); methods.Add("stopqueues", async(command) => { lock (queuesRunning) { foreach (string entry in queuesRunning.Keys.ToArray()) { command.Channel.SendMessage(entry + " queue stopped"); if (queuesRunning.ContainsKey(entry)) { queuesRunning[entry].Stop(); queuesRunning.Remove(entry); } else { command.Channel.SendMessage("huh where did it go? " + entry); } } } await command.Message.Delete(); await command.Channel.SendMessage("All Image queues stopped"); }); methods.Add("help", async(command) => { await command.Channel.SendMessage(getHelp()); }); }
protected abstract IFileSystem CreateArchiveFileSystem(FileSystemFile archiveFile);
private IEnumerable <CandleData> enumerateCandleData(enumerateCandleDataArgs args, FileSystemFile file) { var header = args.Header; var skipSec = args.SkipSeconds; using (var stream = file.FileStream) { //Candle data start stream.Seek(header.DataOffset, SeekOrigin.Begin); DateTime ts = header.StartTime; var i = 0; if (skipSec > 0) { var skipSamples = skipSec / header.ResolutionSec;//int division. Resolution was already checked for 0 if (skipSamples >= header.CandleCount) { yield break; } i = skipSamples; stream.Seek(skipSamples * CandleData.BYTE_SIZE, SeekOrigin.Current); ts = ts.AddSeconds(skipSamples * header.ResolutionSec); } for (; i < header.CandleCount; i++) { yield return(new CandleData(this, i, ts, stream)); ts = ts.AddSeconds(header.ResolutionSec); } }//using stream }
public GoogleDriveStream(FileSystemFile file, Action<FileSystemStream> disposeAction) : base(file, disposeAction) { m_Handle = (GoogleDriveHandle)file.Handle; m_Session = file.Session as GoogleDriveSession; }
public SVNFileSystemStream(FileSystemFile file, Action<FileSystemStream> disposeAction) : base(file, disposeAction) { m_wdFile = ((SVNFileSystem.SVNFSH)file.Handle).Item as WebDAV.File; SVNFileSystem fs = file.FileSystem as SVNFileSystem; }
protected internal override FileSystemStream DoGetFileStream(FileSystemFile file, Action <FileSystemStream> disposeAction) { return(new S3V4FileSystemStream(file, disposeAction, ((S3V4FileSystemSession)file.Session).TimeoutMs)); }
public WeatherUnderGround(FileSystemFile file) { command = "wu"; wu = new wuAPI(file); methods = new Dictionary <string, Func <CommandEventArgs, Task> >(); queuesRunning = new Dictionary <string, Queue>(); methods.Add("get", async(command) => { if (command.GetArg(1).Equals("")) { await command.Channel.SendMessage(command.Message.User.Mention + " location was not specified."); return; } await command.Channel.SendMessage(command.User.Name + " searched for weather for " + command.GetArg(1)); await command.Channel.SendMessage(wu.getCurrentWeather(command.GetArg(1))); await command.Message.Delete(); }); /*methods.Add("queue", async (command) => * { * int delay; * string query = command.GetArg(1); * if (command.GetArg(2) == null || !Int32.TryParse(command.GetArg(2), out delay)) * { * await command.Channel.SendMessage("!weather queue <search> <delay in mins>"); * return; * } * await command.Message.Delete(); * if (!queuesRunning.ContainsKey(query)) * { * await command.Channel.SendMessage(query + " queue has been started"); * queuesRunning.Add(query, new WeatherQueue(query, new TimeSpan(0, delay, 0), false, command, owm)); * queuesRunning[query].Start(); * } * else * { * await command.Channel.SendMessage(query + " queue has already been started"); * } * }); * methods.Add("stopqueue", async (command) => * { * string query = command.GetArg(1); * await command.Message.Delete(); * if (queuesRunning.ContainsKey(query)) * { * queuesRunning[query].Stop(); * queuesRunning.Remove(query); * await command.Channel.SendMessage(query + " queue stopped"); * } * else * { * await command.Channel.SendMessage(query + " queue not found"); * } * }); * methods.Add("stopqueues", async (command) => * { * lock (queuesRunning) * { * foreach (string entry in queuesRunning.Keys.ToArray()) * { * command.Channel.SendMessage(entry + " queue stopped"); * if (queuesRunning.ContainsKey(entry)) * { * queuesRunning[entry].Stop(); * queuesRunning.Remove(entry); * } * else * command.Channel.SendMessage("huh where did it go? " + entry); * } * } * await command.Message.Delete(); * await command.Channel.SendMessage("All Image queues stopped"); * });*/ methods.Add("help", async(command) => { await command.Channel.SendMessage(getHelp()); }); }