private void UploadMemoryStream(string fileNameWithoutPath, Stream stream, long channelID) { LogDataParameterMessage lp = new LogDataParameterMessage(); lp.FileName = fileNameWithoutPath; lp.SystemPassPhrase = _systemPassPhrase; lp.UserGUID = _userGUID; lp.MachineGUID = _machineGUID; lp.ChannelID = channelID.ToString(); lp.LogFileStream = stream; _logger.WriteTimestampedMessage("Filename without path: " + fileNameWithoutPath); SimpleErrorWrapperMessage sw = null; try { sw = _userDataMarshallerStreamerClient.ProcessLogData(lp); } catch (CommunicationException ex) { throw ex; } if (sw.ErrorStatus == ErrorStatus.Failure) { throw new RemoteServerException(sw.ErrorCode, sw.ErrorSeverity.ToString(), sw.Message); } }
private void SaveLogStreamAndDispose(SimpleErrorWrapperMessage simpleErrorWrapper, Stream readStream, string path, string fileName) { FileStream fileStream = null; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } fileStream = new FileStream(path + "\\" + DateTime.Now.Ticks + "_" + fileName, FileMode.CreateNew); SaveStream(readStream, fileStream); } catch (Exception ex) { // _eventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error); simpleErrorWrapper.ErrorCode = "ERR:003"; simpleErrorWrapper.Message = "Could not save file"; simpleErrorWrapper.ErrorSeverity = ErrorSeverity.Retriable; simpleErrorWrapper.ErrorStatus = ErrorStatus.Failure; return; } finally { OperationContext clientContext = OperationContext.Current; clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs e) { if (readStream != null) { readStream.Dispose(); } if (fileStream != null) { fileStream.Dispose(); } }); } simpleErrorWrapper.ErrorStatus = ErrorStatus.Success; }
/// <summary> /// Receives log data from the client /// </summary> /// <param name="logDataParameterMessage">Message Wrapper that holds the system pass phrase, the user's GUID, the asset type, the log type and the stream with the log file</param> /// <returns>A SimpleErrorWrapperMessage object with the operation result</returns> public SimpleErrorWrapperMessage ProcessLogData(LogDataParameterMessage logDataParameterMessage) { SimpleErrorWrapperMessage simpleErrorWrapper = new SimpleErrorWrapperMessage(); if (logDataParameterMessage.SystemPassPhrase != _systemPassPhrase) { simpleErrorWrapper.ErrorCode = "ERR:001"; simpleErrorWrapper.Message = "Authentication failure"; simpleErrorWrapper.ErrorSeverity = ErrorSeverity.Retriable; simpleErrorWrapper.ErrorStatus = ErrorStatus.Failure; return(simpleErrorWrapper); } try { LogDataFile(logDataParameterMessage); } catch (Exception ex) { _applicationLog.Error(ex.ToString()); } return(simpleErrorWrapper); }