/// <summary> /// Gets the event handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args"> /// The <see cref="GSeries.Filesystem.FilesysEventArgs"/> instance /// containing the event data.</param> /// <returns> /// The event handler. Returns <see cref="NopFilesysEventHandler"/> /// if no other handler matches. /// </returns> protected override IFilesysEventHandler GetEventHandler(IFilesys sender, FilesysEventArgs args) { if (IsPathIgnored(args.VritualRawPath)) { return new NopFilesysEventHandler(); } var handlerName = GetHandlerName(args.VritualRawPath); if(string.IsNullOrEmpty(handlerName)) { return new NopFilesysEventHandler(); } else { // The decision depends solely on the first segment of the path. IFilesysEventHandler handler = null; try { handler = _container.Resolve<IFilesysEventHandler>(handlerName); } catch (ResolutionFailedException) { Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Failed to resovle hanlder for the given path: {0}.", args.VritualRawPath.PathString)); } if (handler == null) { return new NopFilesysEventHandler(); } else { return handler; } } }
/// <summary> /// Gets the event handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args"> /// The <see cref="GSeries.Filesystem.FilesysEventArgs"/> instance /// containing the event data.</param> /// <returns> /// The event handler. Returns <see cref="NopFilesysEventHandler"/> /// if no other handler matches. /// </returns> protected override IFilesysEventHandler GetEventHandler(IFilesys sender, FilesysEventArgs args) { if (IsPathIgnored(args.VritualRawPath)) { return(new NopFilesysEventHandler()); } var handlerName = GetHandlerName(args.VritualRawPath); if (string.IsNullOrEmpty(handlerName)) { return(new NopFilesysEventHandler()); } else { // The decision depends solely on the first segment of the path. IFilesysEventHandler handler = null; try { handler = _container.Resolve <IFilesysEventHandler>(handlerName); } catch (ResolutionFailedException) { Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Failed to resovle hanlder for the given path: {0}.", args.VritualRawPath.PathString)); } if (handler == null) { return(new NopFilesysEventHandler()); } else { return(handler); } } }
public override void HandleGettingPathStatus(IFilesys sender, GetPathStatusEventArgs args) { // First decide the path conforms to the pattern, then check its existence. UriTemplateMatch match; var succ = TryMatchPath(BasicTemplateString, args.VritualRawPath.PathString, out match); if (succ) { // Does it already exist? var shadowFullPath = _pathFactory.CreateShadowFullPath4Read( new VirtualPath(args.VritualRawPath)); if (IOUtil.FileOrDirectoryExists(shadowFullPath.PathString)) { // @TODO return for now but the path could be stale. return; } else { String nameStr = match.BoundVariables[2]; if (nameStr.StartsWith(".")) { // We don't deal with hidden files. return; } } // The path doesn't exsit locally. Check the server. Uri reqUri; reqUri = BasicPathMatch2ReqUri(match, new NameValueCollection() { { PeekParamName, "true" } }); Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Requesting meta info from Uri {0}", reqUri.ToString())); string xmlString; try { // This can be a while. xmlString = _serverProxy.GetUTF8String(reqUri, System.Threading.Timeout.Infinite); } catch (WebException ex) { Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Exception thrown from server: {0}", ex)); // Handle different types of error accodingly. if (ex is WebException) { if (((HttpWebResponse)((ex as WebException).Response)).StatusCode == HttpStatusCode.NotFound) { // Normal. Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Server says {0} doesn't exist online.", args.VritualRawPath)); return; } else { // Other protocol level errors. throw; } } else { // Non-procotol-level errors. throw; } } // If everything is fine so far, we are good for subsequent read! CreateVirtualFiles(new ShadowMetaFullPath(sender.ShadowDirPath, new VirtualPath(args.VritualRawPath)), xmlString); } }
public FilesysEventDispatcher(IFilesys fushareFilesys) { Filesys = fushareFilesys; Filesys.GettingPathStatus += new EventHandler <GetPathStatusEventArgs>(FushareFilesys_GettingPathStatus); Filesys.ReadingFile += new EventHandler <ReadFileEventArgs>(FushareFilesys_ReadingFile); Filesys.ReleasedFile += new EventHandler <ReleaseFileEventArgs>(FushareFilesys_ReleasedFile); Filesys.OpeningFile += new EventHandler <OpenFileEventArgs>(FushareFilesys_OpeningFile); }
public FilesysEventDispatcher(IFilesys fushareFilesys) { Filesys = fushareFilesys; Filesys.GettingPathStatus += new EventHandler<GetPathStatusEventArgs>(FushareFilesys_GettingPathStatus); Filesys.ReadingFile += new EventHandler<ReadFileEventArgs>(FushareFilesys_ReadingFile); Filesys.ReleasedFile += new EventHandler<ReleaseFileEventArgs>(FushareFilesys_ReleasedFile); Filesys.OpeningFile += new EventHandler<OpenFileEventArgs>(FushareFilesys_OpeningFile); }
/// <summary> /// Handles the opening file event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="GSeries.Filesystem.OpenFileEventArgs"/> instance containing the event data.</param> public override void HandleOpeningFile(IFilesys sender, OpenFileEventArgs args) { UriTemplateMatch match; var succ = TryMatchPath(BasicTemplateString, args.VritualRawPath.PathString, out match); if (succ && args.FileAccess == FileAccess.Read) { Uri reqUri; if (!string.IsNullOrEmpty(match.QueryParameters[OnDemandParamName])) { // It's on-demand read, downloading is postponed to read(). } else { // Otherwise, we download the file now. reqUri = BasicPathMatch2ReqUri(match, null); Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Requesting meta info from Uri {0}", reqUri.ToString())); string xmlString; try { // This can be a while. xmlString = _serverProxy.GetUTF8String(reqUri, System.Threading.Timeout.Infinite); } catch (WebException ex) { Logger.WriteLineIf(LogLevel.Error, _log_props, string.Format( "Exception thrown from server: {0}", ex)); // Handle different types of error accodingly. if (ex is WebException) { if (((HttpWebResponse)((ex as WebException).Response)).StatusCode == HttpStatusCode.NotFound) { // Normal. Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format("Server says requested file/directory doesn't exist.")); return; } else { // Other protocol level errors. throw; } } else { // Non-procotol-level errors. throw; } } } } }
public override void HandleReadingFile(IFilesys sender, ReadFileEventArgs args) { // A read here should be preceded by a path status inquiry. OpenFileInfo ofi; VirtualFile vf; if (_filesysContext.TryGetOpenFileInfo(args.Handle, out ofi)) { vf = ofi.VirtualFile; } else { throw new InvalidOperationException(); } if (vf.OnDemand) { Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format("Virtual file suggests on demand retrieval, requesting data...")); UriTemplateMatch match; var succ = TryMatchPath(BasicTemplateString, args.VritualRawPath.PathString, out match); if (succ) { var extraParams = new NameValueCollection(); extraParams.Add(BytesToReadParamName, Convert.ToString(args.Buffer.Length)); extraParams.Add(OffsetParamName, Convert.ToString(args.Offset)); var uri = BasicPathMatch2ReqUri(match, extraParams); byte[] data = _serverProxy.Get(uri); // Size of data should be less than or equal to size of args.Buffer using (var ms = new MemoryStream(args.Buffer)) { ms.Write(data, 0, data.Length); } args.BytesRead = data.Length; Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format("Successfully read {0} bytes.", args.BytesRead)); } } else { args.BytesRead = _fileManager.Read(vf, args.Buffer, args.Offset); } }
public override void HandleReleasedFile(IFilesys sender, ReleaseFileEventArgs args) { UriTemplateMatch match; var succ = TryMatchPath(BasicTemplateString, args.VritualRawPath.PathString, out match); // Only files under /bt directory are supported. if (succ) { IntPtr handle = args.Handle; OpenFileInfo openFileInfo; if (_filesysContext.TryGetOpenFileInfo(handle, out openFileInfo) && openFileInfo.FileAccess != FileAccess.Read) { // Stage in the file for publishing. _fileManager.CopyToServer(new VirtualPath(args.VritualRawPath)); var uri = BasicPathMatch2ReqUri(match, null); Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "POSTing to server to publish the file: {0}", uri)); _serverProxy.Post(uri, new byte[] { }); } } }
public void HandleReleasedFile(IFilesys sender, ReleaseFileEventArgs args) { // Do nothing. }
public void HandleGettingPathStatus(IFilesys sender, GetPathStatusEventArgs args) { // Do nothing. }
public void HandleReadingFile(IFilesys sender, ReadFileEventArgs args) { throw new NotImplementedException(); }
public abstract void HandleReadingFile(IFilesys sender, ReadFileEventArgs args);
public abstract void HandleReleasedFile(IFilesys sender, ReleaseFileEventArgs args);
/// <summary> /// Gets the event handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args"> /// The <see cref="GSeries.Filesystem.FilesysEventArgs"/> instance /// containing the event data.</param> /// <returns>The event handler. Returns <see cref="NopFilesysEventHandler"/> /// if no other handler matches.</returns> protected abstract IFilesysEventHandler GetEventHandler(IFilesys sender, FilesysEventArgs args);
public abstract void HandleOpeningFile(IFilesys sender, OpenFileEventArgs args);
public abstract void HandleGettingPathStatus(IFilesys sender, GetPathStatusEventArgs args);
public void HandleOpeningFile(IFilesys sender, OpenFileEventArgs args) { throw new NotImplementedException(); }
public UnityFilesysEventDispatcher(IFilesys fushareFilesys, IUnityContainer container) : base(fushareFilesys) { _container = container; }