Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added MorseCodeLib/.vs/MorseCodeLib/v14/.suo
Binary file not shown.
1,065 changes: 1,065 additions & 0 deletions MorseCodeLib/.vs/config/applicationhost.config

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions MorseCodeLib/MorseCodeLib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MorseCodeLib</RootNamespace>
<AssemblyName>MorseCodeLib</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MorseCodeTranslator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
11 changes: 11 additions & 0 deletions MorseCodeLib/MorseCodeLib.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Project</StartAction>
<StartProgram>
</StartProgram>
</PropertyGroup>
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
31 changes: 31 additions & 0 deletions MorseCodeLib/MorseCodeLib.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeLib", "MorseCodeLib.csproj", "{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorseCodeTest", "..\MorseCodeTest\MorseCodeTest.csproj", "{3486F442-5440-4C9D-9839-E002D0E9449D}"
ProjectSection(ProjectDependencies) = postProject
{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A} = {00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00AE359F-B94F-49E8-AFC1-CDA2D0B26B9A}.Release|Any CPU.Build.0 = Release|Any CPU
{3486F442-5440-4C9D-9839-E002D0E9449D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3486F442-5440-4C9D-9839-E002D0E9449D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3486F442-5440-4C9D-9839-E002D0E9449D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3486F442-5440-4C9D-9839-E002D0E9449D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
129 changes: 129 additions & 0 deletions MorseCodeLib/MorseCodeTranslator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace MorseCodeLib
{
public class MorseCodeTranslator
{
private static Dictionary<string, char> _dictonary;

/// <summary>
/// Morse Code dictonary obtained from the Morse Code wikipedia page.
/// Contains alphanumeric characters and as a subset of symbols and punctuation.
/// </summary>
static MorseCodeTranslator()
{
_dictonary = new Dictionary<string, char>()
{
{".-",'a'},
{"-...",'b'},
{"-.-.",'c'},
{"-..",'d'},
{".",'e'},
{"..-.",'f'},
{"--.",'g'},
{"....",'h'},
{"..",'i'},
{".---",'j'},
{"-.-",'k'},
{".-..",'l'},
{"--",'m'},
{"-.",'n'},
{"---",'o'},
{".--.",'p'},
{"--.-",'q'},
{".-.",'r'},
{"...",'s'},
{"-",'t'},
{"..-",'u'},
{"...-",'v'},
{".--",'w'},
{"-..-",'x'},
{"-.--",'y'},
{"--..",'z'},
{"-----",'0'},
{".----",'1'},
{"..---",'2'},
{"...--",'3'},
{"....-",'4'},
{".....",'5'},
{"-....",'6'},
{"--...",'7'},
{"---..",'8'},
{"----.",'9'},
{".-.-.-",'.'},
{"..--..",'?'},
{"--..--",','},
{"-..-.",'/'},
{".--.-.",'@'},
{"---...",':'},
{"-.-.-.",';'},
{".----.",'\''},
{"-....-",'-'},
{".-.-.",'+'},
{"-.--.",'('},
{"-.--.-",')'},
{".-..-.",'\"'},
{"-...-",'='},
{"..--.-",'_'},
{"...-..-",'$'},
{".-...",'&'},
{"-.-.--",'!'}
};
}

/// <summary>
/// Reads each line of a file
/// </summary>
/// <param name="fileName">A filepath to MyTests where the uploaded test files reside</param>
/// <returns></returns>
public StringBuilder TranslateInput(string fileName)
{
StringBuilder builtString = new StringBuilder();
MatchCollection invalidChar = null;
string[] lines = File.ReadAllLines(fileName);
for(int i = 0; i < lines.Length; i++)
{
invalidChar = Regex.Matches(lines[i], @"[^*-|]");
if (invalidChar.Count > 0)
{ //Exception will need to be caught in that class utilizing this method
throw new System.ArgumentException($"Line #{i} contains an invalid character: \"{invalidChar[0]}\"\n This translator can only translate morse code characters: \"*\", \"-\", and \"|\"");
}

builtString.Append(translate(lines[i]));
}
return builtString;
}

/// <summary>
/// Translates the Morse Code into English
/// </summary>
/// <param name="input">A single line from the file</param>
/// <returns></returns>
public StringBuilder translate(string input)
{
StringBuilder sb = new StringBuilder();
string[] wordDelimiter = new string[] { "||||" };
string[] letterDelimiter = new string[] { "||" };
string[] morseWords = input.Split(wordDelimiter, StringSplitOptions.None);

foreach (string word in morseWords)
{
string[] morseLetters = word.Split(letterDelimiter, StringSplitOptions.None);
foreach (string letter in morseLetters)
{
if (_dictonary.ContainsKey(letter))
{
sb.Append(_dictonary[letter]); //Appends the cooresponding letter to the english word
}
}
if (morseWords.Last() != word) { sb.Append(' '); } //Append a space to all words except the last
}
return sb;
}
}
}
36 changes: 36 additions & 0 deletions MorseCodeLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MorseCodeLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MorseCodeLib")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("00ae359f-b94f-49e8-afc1-cda2d0b26b9a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added MorseCodeLib/bin/Debug/MorseCodeLib.dll
Binary file not shown.
Binary file added MorseCodeLib/bin/Debug/MorseCodeLib.pdb
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions MorseCodeLib/obj/Debug/MorseCodeLib.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
C:\Users\Pat-Gamer\Source\Repos\MorseCodeLib\bin\Debug\MorseCodeLib.dll
C:\Users\Pat-Gamer\Source\Repos\MorseCodeLib\bin\Debug\MorseCodeLib.pdb
C:\Users\Pat-Gamer\Source\Repos\MorseCodeLib\obj\Debug\MorseCodeLib.csprojResolveAssemblyReference.cache
C:\Users\Pat-Gamer\Source\Repos\MorseCodeLib\obj\Debug\MorseCodeLib.dll
C:\Users\Pat-Gamer\Source\Repos\MorseCodeLib\obj\Debug\MorseCodeLib.pdb
C:\Users\Pat-Gamer\Source\Repos\MorseCode\MorseCodeLib\bin\Debug\MorseCodeLib.dll
C:\Users\Pat-Gamer\Source\Repos\MorseCode\MorseCodeLib\bin\Debug\MorseCodeLib.pdb
C:\Users\Pat-Gamer\Source\Repos\MorseCode\MorseCodeLib\obj\Debug\MorseCodeLib.csprojResolveAssemblyReference.cache
C:\Users\Pat-Gamer\Source\Repos\MorseCode\MorseCodeLib\obj\Debug\MorseCodeLib.dll
C:\Users\Pat-Gamer\Source\Repos\MorseCode\MorseCodeLib\obj\Debug\MorseCodeLib.pdb
Binary file not shown.
Binary file added MorseCodeLib/obj/Debug/MorseCodeLib.dll
Binary file not shown.
Binary file added MorseCodeLib/obj/Debug/MorseCodeLib.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
</configuration>
Binary file not shown.
Loading