/** * Pulls a remote channel from the remote agent via the remote connection parameter. * * @param Remote Remote connection. * @param ChannelName The name of the file to pull. * @param JobGuid A guid of the job. * @param RetriesOnFailure How many times should the pull fail until return a failure. * * @returns True on success. False otherwise. */ public bool PullChannel(RemoteConnection Remote, string ChannelName, AgentGuid JobGuid, int RetriesOnFailure = int.MaxValue) { StartTiming("PullChannel-Internal", true); // The remote connection's handle can be used for all interaction because // it has the same meaning on both ends of the connection Int32 ConnectionHandle = Remote.Handle; // Request the file, which will push it back, and keep doing so until we get it // or until the connection is dead, which ever comes first bool bChannelTransferred = false; int TryId = 0; while ((Remote.Interface.IsAlive()) && (bChannelTransferred == false) && (TryId < RetriesOnFailure)) { try { bChannelTransferred = Remote.Interface.RequestChannel(ConnectionHandle, ChannelName, JobGuid); } catch (Exception Ex) { Log(EVerbosityLevel.Verbose, ELogColour.Red, "[PullChannel] Exception message: " + Ex.ToString()); } if(!bChannelTransferred) { Log(EVerbosityLevel.Verbose, ELogColour.Red, string.Format("[PullChannel] Pulling the channel {0} has failed! Retry {1} of {2}.", ChannelName, TryId + 1, RetriesOnFailure)); } ++TryId; } StopTiming(); return bChannelTransferred; }
/** * Pushes a local channel to the remote agent via the remote connection parameter * by calling SendChannel on the remote agent */ public bool PushChannel(RemoteConnection Remote, string ChannelName, AgentGuid JobGuid) { StartTiming("PushChannel-Internal", true); bool bChannelTransferred = false; // The remote connection's handle can be used for all interaction because // it has the same meaning on both ends of the connection Int32 ConnectionHandle = Remote.Handle; EChannelFlags ChannelFlags = EChannelFlags.ACCESS_READ; if (JobGuid == null) { ChannelFlags |= EChannelFlags.TYPE_PERSISTENT; } else { ChannelFlags |= EChannelFlags.TYPE_JOB_ONLY; } Hashtable OpenInParameters = new Hashtable(); OpenInParameters["Version"] = ESwarmVersionValue.VER_1_0; OpenInParameters["ChannelName"] = ChannelName; OpenInParameters["ChannelFlags"] = ChannelFlags; Hashtable OpenOutParameters = null; Int32 LocalChannelHandle = OpenChannel_1_0(ConnectionHandle, OpenInParameters, ref OpenOutParameters); if (LocalChannelHandle >= 0) { try { string FullChannelName; if (JobGuid == null) { FullChannelName = Path.Combine(AgentApplication.Options.CacheFolder, ChannelName); } else { string AllJobsFolder = Path.Combine(AgentApplication.Options.CacheFolder, "Jobs"); string ThisJobFolder = Path.Combine(AllJobsFolder, "Job-" + JobGuid.ToString()); FullChannelName = Path.Combine(ThisJobFolder, ChannelName); } // Read the entire file into a byte stream byte[] ChannelData = File.ReadAllBytes(FullChannelName); // Send the entire channel at once bChannelTransferred = Remote.Interface.SendChannel(ConnectionHandle, ChannelName, ChannelData, JobGuid); // If the channel was transferred, track the number of bytes that actually moved across the network if (bChannelTransferred) { FileInfo ChannelInfo = new FileInfo(FullChannelName); Remote.NetworkBytesSent += ChannelInfo.Length; if (Remote.Job != null) { Remote.Job.NetworkBytesSent += ChannelInfo.Length; } if (Remote.Parent != null) { Remote.Parent.NetworkBytesSent += ChannelInfo.Length; } } } catch (Exception Ex) { Log(EVerbosityLevel.Verbose, ELogColour.Red, "[PushChannel] Exception message: " + Ex.ToString()); } Hashtable CloseInParameters = new Hashtable(); CloseInParameters["Version"] = ESwarmVersionValue.VER_1_0; CloseInParameters["ChannelHandle"] = LocalChannelHandle; Hashtable CloseOutParameters = null; CloseChannel_1_0(ConnectionHandle, CloseInParameters, ref CloseOutParameters); if (bChannelTransferred) { Log(EVerbosityLevel.Verbose, ELogColour.Green, "[Channel] Successful channel push of " + ChannelName); } else { Log(EVerbosityLevel.Verbose, ELogColour.Red, string.Format("[PushChannel] Pushing the channel {0} has failed!", ChannelName)); } } else { Log(EVerbosityLevel.Informative, ELogColour.Red, string.Format("[PushChannel] Cannot open local channel {0}.", ChannelName)); } StopTiming(); return bChannelTransferred; }
public OpenJobOnRemoteData( AgentJob NewJob, RemoteConnection NewRemote ) { Job = NewJob; Remote = NewRemote; }