Skip to content

Commit

Permalink
Add W2 D3 projects (not finished yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvpfus committed Sep 13, 2023
1 parent f97bd77 commit 70f5027
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 0 deletions.
30 changes: 30 additions & 0 deletions FormulatrixBootcamp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NonGenericCollection", "W2
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Delegate", "W2 D2\Delegate\Delegate.csproj", "{8CBF3A9D-D792-4ECC-92A3-0E2782673234}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelegatePubSub", "W2 D2\DelegatePubSub\DelegatePubSub.csproj", "{22303F7C-8C80-4381-AA31-D1A260E37F2F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelegateReturnValue", "W2 D2\DelegateReturnValue\DelegateReturnValue.csproj", "{48A4309F-4E43-419D-8ECD-E8A441359E83}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "W2 D3", "W2 D3", "{82AE1F6C-47FF-4067-89F3-87EBEFDA524C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventHandler", "W2 D3\EventHandler\EventHandler.csproj", "{D5027177-A81C-44F1-9F12-7C7CDFB6C458}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventHandlerGeneric", "W2 D3\EventHandlerGeneric\EventHandlerGeneric.csproj", "{6A2EF45B-F734-4A5F-8D67-90443EB39056}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -189,6 +199,22 @@ Global
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CBF3A9D-D792-4ECC-92A3-0E2782673234}.Release|Any CPU.Build.0 = Release|Any CPU
{22303F7C-8C80-4381-AA31-D1A260E37F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22303F7C-8C80-4381-AA31-D1A260E37F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22303F7C-8C80-4381-AA31-D1A260E37F2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22303F7C-8C80-4381-AA31-D1A260E37F2F}.Release|Any CPU.Build.0 = Release|Any CPU
{48A4309F-4E43-419D-8ECD-E8A441359E83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48A4309F-4E43-419D-8ECD-E8A441359E83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48A4309F-4E43-419D-8ECD-E8A441359E83}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48A4309F-4E43-419D-8ECD-E8A441359E83}.Release|Any CPU.Build.0 = Release|Any CPU
{D5027177-A81C-44F1-9F12-7C7CDFB6C458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5027177-A81C-44F1-9F12-7C7CDFB6C458}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5027177-A81C-44F1-9F12-7C7CDFB6C458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5027177-A81C-44F1-9F12-7C7CDFB6C458}.Release|Any CPU.Build.0 = Release|Any CPU
{6A2EF45B-F734-4A5F-8D67-90443EB39056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A2EF45B-F734-4A5F-8D67-90443EB39056}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A2EF45B-F734-4A5F-8D67-90443EB39056}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A2EF45B-F734-4A5F-8D67-90443EB39056}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -222,5 +248,9 @@ Global
{367138CF-7021-4354-B364-6A674AA8E4D5} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{51504E3A-4A98-45D9-B64B-C657E7CC95B9} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{8CBF3A9D-D792-4ECC-92A3-0E2782673234} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{22303F7C-8C80-4381-AA31-D1A260E37F2F} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{48A4309F-4E43-419D-8ECD-E8A441359E83} = {747633C8-D663-4492-9F60-E01A9F09A1CA}
{D5027177-A81C-44F1-9F12-7C7CDFB6C458} = {82AE1F6C-47FF-4067-89F3-87EBEFDA524C}
{6A2EF45B-F734-4A5F-8D67-90443EB39056} = {82AE1F6C-47FF-4067-89F3-87EBEFDA524C}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions W2 D2/DelegatePubSub/DelegatePubSub.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
15 changes: 15 additions & 0 deletions W2 D2/DelegatePubSub/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using DelegatePubSub;
public delegate void Publish(string x);
public class Program
{
static void Main()
{
Youtuber yt = new();
Subscriber sub1 = new();

yt.AddSubscriber(sub1.Notify);
yt.SendNotification();

yt.RemoveSubscriber(sub1.Notify);
}
}
8 changes: 8 additions & 0 deletions W2 D2/DelegatePubSub/Subscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DelegatePubSub;
public class Subscriber
{
public void Notify(string message)
{
Console.WriteLine(message);
}
}
35 changes: 35 additions & 0 deletions W2 D2/DelegatePubSub/Youtuber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace DelegatePubSub;
public class Youtuber
{
private Publish? _sub;
public void SendNotification()
{
if (_sub != null)
{
_sub.Invoke("Notify");
}
}

public void AddSubscriber(Publish sub)
{
if (_sub == null || !_sub.GetInvocationList().Contains(sub))
{
_sub += sub;
}
else
{
Console.WriteLine("Error: Subscriber already exist.");
}
}

public void RemoveSubscriber(Publish sub)
{
if (_sub != null)
{
_sub -= sub;
} else
{
Console.WriteLine("Error: No subscriber.");
}
}
}
10 changes: 10 additions & 0 deletions W2 D2/DelegateReturnValue/DelegateReturnValue.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
43 changes: 43 additions & 0 deletions W2 D2/DelegateReturnValue/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
public delegate decimal Calculator(decimal a, decimal b);
public class Program {
static void Main()
{
Calculator calc = Add;
calc += Subtract;
calc += Multiply;
calc += Divide;

Delegate[] del = calc.GetInvocationList();
List<decimal> results = new List<decimal>();

foreach (Calculator d in del)
{
results.Add(d.Invoke(5.1M, 5.1M));
}

foreach (decimal result in results)
{
Console.WriteLine(result);
}
}

static decimal Add(decimal a, decimal b)
{
return a + b;
}

static decimal Subtract(decimal a, decimal b)
{
return a - b;
}

static decimal Multiply(decimal a, decimal b)
{
return a * b;
}

static decimal Divide(decimal a, decimal b)
{
return a / b;
}
}
10 changes: 10 additions & 0 deletions W2 D2/EventHandler/EventHandler.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions W2 D2/EventHandler/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
10 changes: 10 additions & 0 deletions W2 D3/EventHandler/EventHandler.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions W2 D3/EventHandler/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using EventHandlerExample;
public class Program
{
static void Main()
{
Youtuber yt1 = new Youtuber("Windah Basudara");
Subscriber sub1 = new Subscriber("Yusuf");

yt1.AddSubscriber(sub1.GetNotification);
yt1.UploadVideo();
}
}
16 changes: 16 additions & 0 deletions W2 D3/EventHandler/Subscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace EventHandlerExample;
public class Subscriber
{
private string? _name;

public Subscriber(string name)
{
_name = name;
}

public void GetNotification(object? sender, EventArgs e)
{

Console.WriteLine($"{_name} is getting notification from Youtuber ({sender}).");
}
}
54 changes: 54 additions & 0 deletions W2 D3/EventHandler/Youtuber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace EventHandlerExample;
public class Youtuber
{
private EventHandler? _sub;
private string _name;

public Youtuber(string name)
{
_name = name;
}

public void AddSubscriber(EventHandler sub)
{
if (_sub == null || !_sub.GetInvocationList().Contains(sub))
{
_sub += sub;
}
else
{
Console.WriteLine("Error: Subscriber already exist.");
}
}

public void RemoveSubscriber(EventHandler sub)
{
if (_sub != null)
{
_sub -= sub;
}
else
{
Console.WriteLine("Error: No subscriber.");
}
}

public void UploadVideo()
{
Console.WriteLine("Video is being uploaded..");
Console.WriteLine("Video uploaded.");
SendNotification();
}

private void SendNotification()
{
if (_sub != null)
{
_sub.Invoke(this, EventArgs.Empty);
}
}
public override string ToString()
{
return _name;
}
}
6 changes: 6 additions & 0 deletions W2 D3/EventHandlerGeneric/EventData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace EventHandlerGeneric;
public class EventData : EventArgs
{
public string? message;
public int viewCount;
}
10 changes: 10 additions & 0 deletions W2 D3/EventHandlerGeneric/EventHandlerGeneric.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
16 changes: 16 additions & 0 deletions W2 D3/EventHandlerGeneric/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using EventHandlerGeneric;

public class Program
{
static void Main()
{
Youtuber yt = new Youtuber("Windah Basudara");
Subscriber sub1 = new Subscriber("Yusuf");

yt.AddSubscriber(sub1.GetNotification);
yt.UploadVideo("Game Horror");

yt.AddViewCount(sub1.WatchVideo);

}
}
27 changes: 27 additions & 0 deletions W2 D3/EventHandlerGeneric/Subscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace EventHandlerGeneric;
public class Subscriber
{
private string? _name;
EventData data = new();

public Subscriber(string name)
{
_name = name;
}

public void WatchVideo(object? sender, EventData e)
{
Console.WriteLine($"{_name} is watching youtube video");
data.viewCount += 1;
}

public void GetNotification(object? sender, EventData e)
{
Console.WriteLine(e.message);
}

// public void GetViewCount(object? sender, EventData e)
// {
// Console.WriteLine($"Youtube view count: {e.viewCount}");
// }
}
Loading

0 comments on commit 70f5027

Please sign in to comment.