コード例 #1
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);
 }
コード例 #2
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());
        }