コード例 #1
0
        public Stream ReadRecordingFile(int id)
        {
            try
            {
                WebRecordingFileInfo info = GetRecordingFileInfo(id);

                // read it as a regular file
                if (info.Exists && info.IsLocalFile && !info.OnNetworkDrive && File.Exists(info.Path))
                {
                    return(new FileStream(info.Path, FileMode.Open, FileAccess.Read));
                }

                // try to load it from a network drive
                if (info.Exists && info.IsLocalFile && info.OnNetworkDrive)
                {
                    using (var context = NetworkContextFactory.Create())
                        return(new FileStream(context.RewritePath(info.Path), FileMode.Open, FileAccess.Read));
                }

                // failed
                Log.Warn("No method to read file for recording {0} with path {1}", id, info.Path);
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return(Stream.Null);
            }
            catch (Exception ex)
            {
                Log.Warn(String.Format("Failed to read file for recording {0}", id), ex);
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError);
                return(Stream.Null);
            }
        }
コード例 #2
0
 public bool Setup()
 {
     try
     {
         using (var context = NetworkContextFactory.CreateImpersonationContext())
         {
             DataOutputStream = new FileStream(context.RewritePath(source), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         }
     }
     catch (Exception e)
     {
         StreamLog.Error(identifier, "Failed to setup ImpersonationInputUnit", e);
         return(false);
     }
     return(true);
 }
コード例 #3
0
        public WebRecordingFileInfo GetRecordingFileInfo(int id)
        {
            string filename = String.Empty;

            try
            {
                filename = GetRecordingById(id).FileName;

                bool tryImpersonation = false;
                try
                {
                    var fileInfo = new WebRecordingFileInfo(new FileInfo(filename));
                    if (fileInfo != null && fileInfo.Exists)
                    {
                        return(fileInfo);
                    }

                    tryImpersonation = PathUtil.MightBeOnNetworkDrive(filename);
                }
                catch (UnauthorizedAccessException)
                {
                    tryImpersonation = true;
                }

                if (tryImpersonation && Configuration.Services.NetworkImpersonation.IsEnabled())
                {
                    using (var context = NetworkContextFactory.CreateImpersonationContext())
                    {
                        var ret = new WebRecordingFileInfo(context.RewritePath(filename));
                        ret.IsLocalFile    = true;
                        ret.OnNetworkDrive = true;
                        return(ret);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Log.Info("Failed to load fileinfo for recording {0} because it does not exists at path {1}", id, filename);
            }
            catch (Exception ex)
            {
                Log.Warn("Failed to load fileinfo for recording", ex);
            }

            return(new WebRecordingFileInfo());
        }
コード例 #4
0
 public INetworkContext CreateNetworkContext()
 {
     return(NetworkContextFactory.Create(NeedsImpersonation));
 }