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
35 changes: 0 additions & 35 deletions .github/copilot-instructions.md

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,6 @@ autom4te.cache/
tarballs/
test-results/

# Mac bundle stuff
*.dmg
*.app

# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore
# General
.DS_Store
Expand Down
119 changes: 119 additions & 0 deletions MyMonkeyApp/DefaultMonkeys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[
{
"Name": "Baboon",
"Location": "Africa \u0026 Asia",
"Details": "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.",
"Image": "https: //raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/baboon.jpg",
"Population": 10000,
"Latitude": -8.783195,
"Longitude": 34.508523
},
{
"Name": "Capuchin Monkey",
"Location": "Central \u0026 South America",
"Details": "The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/capuchin.jpg",
"Population": 23000,
"Latitude": 12.769013,
"Longitude": -85.602364
},
{
"Name": "Blue Monkey",
"Location": "Central and East Africa",
"Details": "The blue monkey or diademed monkey is a species of Old World monkey native to Central and East Africa, ranging from the upper Congo River basin east to the East African Rift and south to northern Angola and Zambia",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/bluemonkey.jpg",
"Population": 12000,
"Latitude": 1.957709,
"Longitude": 37.297204
},
{
"Name": "Squirrel Monkey",
"Location": "Central \u0026 South America",
"Details": "The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/saimiri.jpg",
"Population": 11000,
"Latitude": -8.783195,
"Longitude": -55.491477
},
{
"Name": "Golden Lion Tamarin",
"Location": "Brazil",
"Details": "The golden lion tamarin also known as the golden marmoset, is a small New World monkey of the family Callitrichidae.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/tamarin.jpg",
"Population": 19000,
"Latitude": -14.235004,
"Longitude": -51.92528
},
{
"Name": "Howler Monkey",
"Location": "South America",
"Details": "Howler monkeys are among the largest of the New World monkeys. Fifteen species are currently recognised. Previously classified in the family Cebidae, they are now placed in the family Atelidae.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/alouatta.jpg",
"Population": 8000,
"Latitude": -8.783195,
"Longitude": -55.491477
},
{
"Name": "Japanese Macaque",
"Location": "Japan",
"Details": "The Japanese macaque, is a terrestrial Old World monkey species native to Japan. They are also sometimes known as the snow monkey because they live in areas where snow covers the ground for months each",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/macasa.jpg",
"Population": 1000,
"Latitude": 36.204824,
"Longitude": 138.252924
},
{
"Name": "Mandrill",
"Location": "Southern Cameroon, Gabon, and Congo",
"Details": "The mandrill is a primate of the Old World monkey family, closely related to the baboons and even more closely to the drill. It is found in southern Cameroon, Gabon, Equatorial Guinea, and Congo.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/mandrill.jpg",
"Population": 17000,
"Latitude": 7.369722,
"Longitude": 12.354722
},
{
"Name": "Proboscis Monkey",
"Location": "Borneo",
"Details": "The proboscis monkey or long-nosed monkey, known as the bekantan in Malay, is a reddish-brown arboreal Old World monkey that is endemic to the south-east Asian island of Borneo.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/borneo.jpg",
"Population": 15000,
"Latitude": 0.961883,
"Longitude": 114.55485
},
{
"Name": "Sebastian",
"Location": "Seattle",
"Details": "This little trouble maker lives in Seattle with James and loves traveling on adventures with James and tweeting @MotzMonkeys. He by far is an Android fanboy and is getting ready for the new Google Pixel 9!",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/sebastian.jpg",
"Population": 1,
"Latitude": 47.606209,
"Longitude": -122.332071
},
{
"Name": "Henry",
"Location": "Phoenix",
"Details": "An adorable Monkey who is traveling the world with Heather and live tweets his adventures @MotzMonkeys. His favorite platform is iOS by far and is excited for the new iPhone Xs!",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/henry.jpg",
"Population": 1,
"Latitude": 33.448377,
"Longitude": -112.074037
},
{
"Name": "Red-shanked douc",
"Location": "Vietnam",
"Details": "The red-shanked douc is a species of Old World monkey, among the most colourful of all primates. The douc is an arboreal and diurnal monkey that eats and sleeps in the trees of the forest.",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/douc.jpg",
"Population": 1300,
"Latitude": 16.111648,
"Longitude": 108.262122
},
{
"Name": "Mooch",
"Location": "Seattle",
"Details": "An adorable Monkey who is traveling the world with Heather and live tweets his adventures @MotzMonkeys. Her favorite platform is iOS by far and is excited for the new iPhone 16!",
"Image": "https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/Mooch.PNG",
"Population": 1,
"Latitude": 47.608013,
"Longitude": -122.335167
}
]
37 changes: 19 additions & 18 deletions MyMonkeyApp/Helpers/MonkeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace MyMonkeyApp.Helpers;
using System.Text.Json;
using System.Threading.Tasks;
using MyMonkeyApp.Models;
using System.Security.Cryptography;
using System.Text;
using System.Security;

/// <summary>
/// Static helper that manages an in-memory collection of monkeys seeded from the MCP sample data.
Expand All @@ -22,22 +25,28 @@ public static class MonkeyHelper
PropertyNameCaseInsensitive = true
};

// Embedded JSON copied from the MCP sample data.
private const string _embeddedJson = @"[{""Name"":""Baboon"",""Location"":""Africa \u0026 Asia"",""Details"":""Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/baboon.jpg"",""Population"":10000,""Latitude"":-8.783195,""Longitude"":34.508523},{""Name"":""Capuchin Monkey"",""Location"":""Central \u0026 South America"",""Details"":""The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/capuchin.jpg"",""Population"":23000,""Latitude"":12.769013,""Longitude"":-85.602364},{""Name"":""Blue Monkey"",""Location"":""Central and East Africa"",""Details"":""The blue monkey or diademed monkey is a species of Old World monkey native to Central and East Africa, ranging from the upper Congo River basin east to the East African Rift and south to northern Angola and Zambia"",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/bluemonkey.jpg"",""Population"":12000,""Latitude"":1.957709,""Longitude"":37.297204},{""Name"":""Squirrel Monkey"",""Location"":""Central \u0026 South America"",""Details"":""The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/saimiri.jpg"",""Population"":11000,""Latitude"":-8.783195,""Longitude"":-55.491477},{""Name"":""Golden Lion Tamarin"",""Location"":""Brazil"",""Details"":""The golden lion tamarin also known as the golden marmoset, is a small New World monkey of the family Callitrichidae."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/tamarin.jpg"",""Population"":19000,""Latitude"":-14.235004,""Longitude"":-51.92528},{""Name"":""Howler Monkey"",""Location"":""South America"",""Details"":""Howler monkeys are among the largest of the New World monkeys. Fifteen species are currently recognised. Previously classified in the family Cebidae, they are now placed in the family Atelidae."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/alouatta.jpg"",""Population"":8000,""Latitude"":-8.783195,""Longitude"":-55.491477},{""Name"":""Japanese Macaque"",""Location"":""Japan"",""Details"":""The Japanese macaque, is a terrestrial Old World monkey species native to Japan. They are also sometimes known as the snow monkey because they live in areas where snow covers the ground for months each"",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/macasa.jpg"",""Population"":1000,""Latitude"":36.204824,""Longitude"":138.252924},{""Name"":""Mandrill"",""Location"":""Southern Cameroon, Gabon, and Congo"",""Details"":""The mandrill is a primate of the Old World monkey family, closely related to the baboons and even more closely to the drill. It is found in southern Cameroon, Gabon, Equatorial Guinea, and Congo."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/mandrill.jpg"",""Population"":17000,""Latitude"":7.369722,""Longitude"":12.354722},{""Name"":""Proboscis Monkey"",""Location"":""Borneo"",""Details"":""The proboscis monkey or long-nosed monkey, known as the bekantan in Malay, is a reddish-brown arboreal Old World monkey that is endemic to the south-east Asian island of Borneo."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/borneo.jpg"",""Population"":15000,""Latitude"":0.961883,""Longitude"":114.55485},{""Name"":""Sebastian"",""Location"":""Seattle"",""Details"":""This little trouble maker lives in Seattle with James and loves traveling on adventures with James and tweeting @MotzMonkeys. He by far is an Android fanboy and is getting ready for the new Google Pixel 9!"",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/sebastian.jpg"",""Population"":1,""Latitude"":47.606209,""Longitude"":-122.332071},{""Name"":""Henry"",""Location"":""Phoenix"",""Details"":""An adorable Monkey who is traveling the world with Heather and live tweets his adventures @MotzMonkeys. His favorite platform is iOS by far and is excited for the new iPhone Xs!"",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/henry.jpg"",""Population"":1,""Latitude"":33.448377,""Longitude"":-112.074037},{""Name"":""Red-shanked douc"",""Location"":""Vietnam"",""Details"":""The red-shanked douc is a species of Old World monkey, among the most colourful of all primates. The douc is an arboreal and diurnal monkey that eats and sleeps in the trees of the forest."",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/douc.jpg"",""Population"":1300,""Latitude"":16.111648,""Longitude"":108.262122},{""Name"":""Mooch"",""Location"":""Seattle"",""Details"":""An adorable Monkey who is traveling the world with Heather and live tweets his adventures @MotzMonkeys. Her favorite platform is iOS by far and is excited for the new iPhone 16!"",""Image"":""https://raw.githubusercontent.com/jamesmontemagno/app-monkeys/master/Mooch.PNG"",""Population"":1,""Latitude"":47.608013,""Longitude"":-122.335167}]";

static MonkeyHelper()
{
using (SHA512 sha = SHA512.Create())
{
string hash = Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(File.ReadAllText("DefaultMonkeys.json"))));
if (hash != "HpLvjmzqGi8UmYYam3SDZiwq7rbqBw/Uac9l20SjjOzBrPlumXum+hUfWoS+QCRm++fTMwC5wnhAeAifzZmMPw==")
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Basic Security Check Failed: File to get monkeys was edited 🙈🙉");
Console.ResetColor();
throw new SecurityException("Default monkey file should not be edited (Basic security check)");
}
}
try
{
_monkeys = JsonSerializer.Deserialize<List<Monkey>>(_embeddedJson, _jsonOptions) ?? new();
_monkeys = JsonSerializer.Deserialize<List<Monkey>>(File.ReadAllText("DefaultMonkeys.json"), _jsonOptions) ?? new();

// initialize access counts (no lock required here; static ctor is thread-safe)
foreach (var m in _monkeys)
foreach (Monkey m in _monkeys)
{
if (!string.IsNullOrWhiteSpace(m.Name) && !_accessCounts.ContainsKey(m.Name))
{
if (!(string.IsNullOrWhiteSpace(m.Name) && _accessCounts.ContainsKey(m.Name)))
_accessCounts[m.Name] = 0;
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -80,25 +89,19 @@ public static Task<IReadOnlyList<Monkey>> GetMonkeysAsync()
return Task.FromResult<Monkey?>(null);
}

var index = Random.Shared.Next(_monkeys.Count);
var selected = _monkeys[index];
int index = Random.Shared.Next(_monkeys.Count);
Monkey selected = _monkeys[index];

lock (_lock)
{
if (string.IsNullOrWhiteSpace(selected.Name))
{
// do nothing for unnamed entries
return Task.FromResult<Monkey?>(selected);
}

if (_accessCounts.ContainsKey(selected.Name))
{
_accessCounts[selected.Name]++;
}
else
{
_accessCounts[selected.Name] = 1;
}
}

return Task.FromResult<Monkey?>(selected);
Expand All @@ -110,9 +113,7 @@ public static Task<IReadOnlyList<Monkey>> GetMonkeysAsync()
public static int GetAccessCount(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
return 0;
}

lock (_lock)
{
Expand Down
2 changes: 1 addition & 1 deletion MyMonkeyApp/MyMonkeyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Loading