public void RedrectToLocalFile(IEnumerable <FileEntry> lines, FileType type)
        {
            var writer = new LocalFileWriter();

            if (type == FileType.Json)
            {
                var jsonStringList = lines.Select(JsonConvert.SerializeObject).ToList();
                if (!writer.WriteToFile(DeviceSendingDetails.RedirectFileName, jsonStringList))
                {
                    throw new ApplicationException(String.Format("Error writing lines to file {0}", DeviceSendingDetails.RedirectFileName));
                }
            }
            else
            {
                var csvStringList = new List <String>();
                foreach (var line in lines)
                {
                    var key = line.PartitionKey;

                    switch (key)
                    {
                    case "temperature":
                        var tempObj = JsonConvert.DeserializeObject <TemperatureData>(line.Message);
                        csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, tempObj.Timestamp.ToString("o"), tempObj.Deviceid, tempObj.RoomNumber, tempObj.Temperature));
                        break;

                    case "energy":
                        var energyObj = JsonConvert.DeserializeObject <EnergyData>(line.Message);
                        csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, energyObj.Timestamp.ToString("o"), energyObj.Deviceid, energyObj.RoomNumber, energyObj.Kwh));
                        break;

                    case "humidity":
                        var humidityObj = JsonConvert.DeserializeObject <HumidityData>(line.Message);
                        csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, humidityObj.Timestamp.ToString("o"), humidityObj.Deviceid, humidityObj.RoomNumber, humidityObj.Humidity));
                        break;

                    case "light":
                        var lightObj = JsonConvert.DeserializeObject <LightData>(line.Message);
                        csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, lightObj.Timestamp.ToString("o"), lightObj.Deviceid, lightObj.RoomNumber, lightObj.Lumens));
                        break;
                    }
                }

                if (!writer.WriteToFile(DeviceSendingDetails.RedirectFileName, csvStringList))
                {
                    throw new ApplicationException(String.Format("Error writing lines to file {0}", DeviceSendingDetails.RedirectFileName));
                }
            }
        }
        public void RedrectToLocalFile(IEnumerable<FileEntry> lines, FileType type)
        {
            var writer = new LocalFileWriter();

            if (type == FileType.Json)
            {
                var jsonStringList = lines.Select(JsonConvert.SerializeObject).ToList();
                if (!writer.WriteToFile(DeviceSendingDetails.RedirectFileName, jsonStringList))
                    throw new ApplicationException(String.Format("Error writing lines to file {0}", DeviceSendingDetails.RedirectFileName));

            }
            else
            {
                var csvStringList = new List<String>();
                foreach (var line in lines)
                {
                    var key = line.PartitionKey;

                    switch (key)
                    {
                        case "temperature":
                            var tempObj = JsonConvert.DeserializeObject<TemperatureData>(line.Message);
                            csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, tempObj.Timestamp.ToString("o"), tempObj.Deviceid, tempObj.RoomNumber, tempObj.Temperature));
                            break;
                        case "energy":
                            var energyObj = JsonConvert.DeserializeObject<EnergyData>(line.Message);
                            csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, energyObj.Timestamp.ToString("o"), energyObj.Deviceid, energyObj.RoomNumber, energyObj.Kwh));
                            break;
                        case "humidity":
                            var humidityObj = JsonConvert.DeserializeObject<HumidityData>(line.Message);
                            csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, humidityObj.Timestamp.ToString("o"), humidityObj.Deviceid, humidityObj.RoomNumber, humidityObj.Humidity));
                            break;
                        case "light":
                            var lightObj = JsonConvert.DeserializeObject<LightData>(line.Message);
                            csvStringList.Add(String.Format("{0},{1},{2},{3},{4}", key, lightObj.Timestamp.ToString("o"), lightObj.Deviceid, lightObj.RoomNumber, lightObj.Lumens));
                            break;
                    }
                }

                if (!writer.WriteToFile(DeviceSendingDetails.RedirectFileName, csvStringList))
                    throw new ApplicationException(String.Format("Error writing lines to file {0}", DeviceSendingDetails.RedirectFileName));
            }
            
        }