Пример #1
0
        public Message[] SaveMessages(params Message[] messages)
        {
            var outputFileMessages = new Dictionary <string, List <Message> >();

            foreach (var message in messages)
            {
                var filePath = _filePathGetter.GetFilePath(message);
                if (outputFileMessages.ContainsKey(filePath))
                {
                    outputFileMessages[filePath].Add(message);
                }
                else
                {
                    outputFileMessages.Add(filePath, new List <Message> {
                        message
                    });
                }
            }
            foreach (var filePath in outputFileMessages.Keys)
            {
                var sb = new StringBuilder();
                foreach (var message in outputFileMessages[filePath])
                {
                    sb.Append(_messageTextFormatter.GetMessageAsText(message));
                }
                File.AppendAllText(filePath, sb.ToString());
            }
            return(messages);
        }
        /// <summary>
        /// Retrieve file path from FilePathHandler by an index, using that file path retrieve an Image from model then set '_pictureBoxes' image to it.
        /// </summary>
        private void GetImage()
        {
            // DECLARE & INSTANIATE an temporary Image variable to null. Call it 'newImage':
            Image newImage = null;

            // DECLARE & INSTANIATE a temporary string variable. Give it the file path returned from the GetFilePath method after passing current _imgIndex. Call it 'filePath':
            string filePath = _filePathHandler.GetFilePath(_imgIndex);

            // Check if a filePath was found for that index
            if (filePath != null)
            {
                // Call getImage method, passing filePath and _pictureBox's width and height properties, save result in 'newImage'
                newImage = _model.getImage(filePath, _pictureBox.Width, _pictureBox.Height);
            }

            // If the 'newImage' value is not null an image was found
            if (newImage != null)
            {
                // Apply 'newImage' to '_pictureBox's Image property
                _pictureBox.Image = newImage;
            }
            else if (_imgIndex < 0)
            {
                // Set index to 0 to prevent index going out of bounds
                _imgIndex = 0;
            }
            else
            {
                // Decrement the 'imgIndex' value to prevent index going out of bounds
                _imgIndex--;
            }
        }