Ejemplo n.º 1
0
 public StreamErrorWrapper GetAppDataFiles(AppDataFileParameterMessage appDataFileParameterMessage)
 {
     return(Channel.GetAppDataFiles(appDataFileParameterMessage));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the XML files (in the form of an array of bytes) that hold general or advert condition data, if different from the client's
        /// </summary>
        /// <param name="appDataFileParameterMessage">Message contract to pass as a parameter</param>
        /// <returns>a StreamErrorWrapper with the relevant stream or with a code that specifies that the file is the same as the one on the client side or with error information</returns>
        public StreamErrorWrapper GetAppDataFiles(AppDataFileParameterMessage appDataFileParameterMessage)
        {
            StreamErrorWrapper streamErrorWrapper = new StreamErrorWrapper();

            // close returned stream on completion
            OperationContext clientContext = OperationContext.Current;

            clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (streamErrorWrapper.ReturnStream != null)
                {
                    streamErrorWrapper.ReturnStream.Dispose();
                }
            });

            if (appDataFileParameterMessage.SystemPassPhrase != _systemPassPhrase)
            {
                streamErrorWrapper.ErrorCode     = "ERR:001";
                streamErrorWrapper.Message       = "Authentication failure";
                streamErrorWrapper.ErrorSeverity = ErrorSeverity.Retriable;
                streamErrorWrapper.ErrorStatus   = ErrorStatus.Failure;
                streamErrorWrapper.ReturnStream  = new MemoryStream(new byte[0]);

                return(streamErrorWrapper);
            }

            string appDataFullPath = "";

            switch (appDataFileParameterMessage.DataFileType)
            {
            case DataFileType.AdvertConditions:
                appDataFullPath = _appDataPath + "ss_adcond_data.dat";
                break;

            case DataFileType.GeneralConfiguration:
                appDataFullPath = _appDataPath + "ss_general_data.dat";
                break;

            case DataFileType.ChannelData:
                appDataFullPath = _channelDataPath + appDataFileParameterMessage.ChannelID + "_channel.dat";
                break;
            }

            if (!File.Exists(appDataFullPath))
            {
                _applicationLog.Warn(appDataFullPath + " does not exist.");
                streamErrorWrapper.ErrorStatus   = ErrorStatus.Failure;
                streamErrorWrapper.ErrorSeverity = ErrorSeverity.Retriable;
                streamErrorWrapper.ErrorCode     = "ERR:002";
                streamErrorWrapper.Message       = "File does not exist";
                streamErrorWrapper.ReturnStream  = new MemoryStream(new byte[0]); // stream must not be null as it is the message body
                return(streamErrorWrapper);
            }

            string serverSideChecksum = ReadStringFromFile(Path.GetDirectoryName(appDataFullPath) + "\\" + Path.GetFileNameWithoutExtension(appDataFullPath) + ".chk");

            if (appDataFileParameterMessage.Checksum == serverSideChecksum)
            {
                streamErrorWrapper.ErrorStatus  = ErrorStatus.ChecksumEqual;
                streamErrorWrapper.ReturnStream = new MemoryStream(new byte[0]);
                return(streamErrorWrapper);
            }

            TryReadFileWithReadLock(streamErrorWrapper, appDataFullPath);

            return(streamErrorWrapper);
        }