コード例 #1
0
 private void CopyLocal(long length)
 {
     // Make sure that we have copied locally enough data to fill the stream to the given length
     if ((length >= _stream.Length) && (_stream.Length < SourceLength))
     {
         _stream.Position = _stream.Length;
         EnsureSourcePosition();
         StreamUtility.CopyStreamWithBufferSize(SourceStream, _stream, length - _stream.Length, StreamUtility.CopyBufferSize);
     }
 }
コード例 #2
0
        public string GetFile(LocalProcess AProcess, string ALibraryName, string AFileName, DateTime AFileDate, bool AIsDotNetAssembly, out bool AShouldLoad)
        {
            AShouldLoad = false;
            string LFullFileName = GetLocalFileName(ALibraryName, AFileName, AIsDotNetAssembly);

            if (!_filesCached.Contains(AFileName))
            {
                if (!File.Exists(LFullFileName) || (File.GetLastWriteTimeUtc(LFullFileName) < AFileDate))
                {
                                        #if LOGFILECACHEEVENTS
                    if (!File.Exists(LFullFileName))
                    {
                        _internalServer.LogMessage(String.Format(@"Downloading file ""{0}"" from server because it does not exist on the client.", LFullFileName));
                    }
                    else
                    {
                        _internalServer.LogMessage(String.Format(@"Downloading newer version of file ""{0}"" from server. Client write time: ""{1}"". Server write time: ""{2}"".", LFullFileName, File.GetLastWriteTimeUtc(LFullFileName), AFileDate.ToString()));
                    }
                                        #endif
                    using (Stream LSourceStream = new RemoteStreamWrapper(AProcess.RemoteProcess.GetFile(ALibraryName, AFileName)))
                    {
                        Alphora.Dataphor.Windows.FileUtility.EnsureWriteable(LFullFileName);
                        try
                        {
                            using (FileStream LTargetStream = File.Open(LFullFileName, FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                StreamUtility.CopyStreamWithBufferSize(LSourceStream, LTargetStream, FileCopyBufferSize);
                            }

                            File.SetLastWriteTimeUtc(LFullFileName, AFileDate);
                        }
                        catch (IOException E)
                        {
                            _internalServer.LogError(E);
                        }
                    }

                                        #if LOGFILECACHEEVENTS
                    _internalServer.LogMessage("Download complete");
                                        #endif
                }

                _filesCached.Add(AFileName);

                // Indicate that the assembly should be loaded
                if (AIsDotNetAssembly)
                {
                    AShouldLoad = true;
                }
            }

            return(LFullFileName);
        }