Skip to content

Commit

Permalink
Update .net framework 4.5 to 4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
konraddysput committed Jan 26, 2024
1 parent e521862 commit 47766ac
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 12 deletions.
15 changes: 15 additions & 0 deletions Backtrace.FrameworkExample/ApplicationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Framework45Example
{
public static class ApplicationSettings
{
public const string Host = @"https://myserver.sp.backtrace.io:6097";
public const string Token = "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0";
public const string DatabasePath = "";
}
}
15 changes: 15 additions & 0 deletions Backtrace.FrameworkExample/Backtrace.FrameworkExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Backtrace\Backtrace.csproj" />
</ItemGroup>

</Project>
81 changes: 81 additions & 0 deletions Backtrace.FrameworkExample/Model/Node.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Framework45Example.Model
{
public class Node
{
public virtual char Key { get; set; }
public virtual bool IsTerminal { get; set; }
public virtual Node Parent { get; set; }
public virtual Dictionary<char, Node> Children { get; set; }

public Node(char key) : this(key, false) { }

public Node(char key, bool isTerminal)

Check warning on line 18 in Backtrace.FrameworkExample/Model/Node.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Parent' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 18 in Backtrace.FrameworkExample/Model/Node.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Parent' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
Key = key;
IsTerminal = isTerminal;
Children = new Dictionary<char, Node>();
}

/// <summary>
/// Return the word at this node if the node is terminal; otherwise, return null
/// </summary>
public virtual string Word
{
get
{
if (!IsTerminal)
return null;

Check warning on line 33 in Backtrace.FrameworkExample/Model/Node.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 33 in Backtrace.FrameworkExample/Model/Node.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

var curr = this;
var stack = new Stack<char>();

while (curr.Parent != null)
{
stack.Push(curr.Key);
curr = curr.Parent;
}

return new String(stack.ToArray());
}

}

///// <summary>
///// Returns an enumerable collection of terminal child nodes.
///// </summary>
public virtual IEnumerable<Node> GetTerminalChildren()
{
foreach (var child in Children.Values)
{
if (child.IsTerminal)
yield return child;

foreach (var grandChild in child.GetTerminalChildren())
if (grandChild.IsTerminal)
yield return grandChild;
}
}

/// <summary>
/// Remove this element upto its parent.
/// </summary>
public virtual void Remove()
{
IsTerminal = false;

if (Children.Count == 0 && Parent != null)
{
Parent.Children.Remove(Key);

if (!Parent.IsTerminal)
Parent.Remove();
}
}
}
}
100 changes: 100 additions & 0 deletions Backtrace.FrameworkExample/Model/Tree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Framework45Example.Model
{
public class Tree : IEnumerable<String>
{
private Node _root { get; set; }

public Tree()
{
_root = new Node(' ', false);
}

/// <summary>
/// Add word to tree
/// </summary>
public void Add(string word)
{
if (string.IsNullOrEmpty(word))
{
throw new ArgumentException("Word is empty or null.");
}

var current = _root;
for (int i = 0; i < word.Length; ++i)
{
if (!current.Children.ContainsKey(word[i]))
{
var newTreeNode = new Node(word[i])
{
Parent = current
};
current.Children.Add(word[i], newTreeNode);
}

current = current.Children[word[i]];
}

if (current.IsTerminal)
{
throw new InvalidOperationException("Word already exists in Tree.");
}
current.IsTerminal = true;
}

/// <summary>
/// Removes a word from the tree.
/// </summary>
public void Remove(string word)
{
if (string.IsNullOrEmpty(word))
{
throw new ArgumentException("Word is empty or null.");
}

var current = _root;

for (int i = 0; i < word.Length; ++i)
{
if (!current.Children.ContainsKey(word[i]))
{
var exception = new KeyNotFoundException("Word doesn't belong to tree.");
throw exception;
}
current = current.Children[word[i]];
}

if (!current.IsTerminal)
{
var exception = new KeyNotFoundException("Word doesn't belong to tree.");
throw exception;
}
current.Remove();
}

#region IEnumerable<String> Implementation
/// <summary>
/// IEnumerable\<String\>.IEnumerator implementation.
/// </summary>
public IEnumerator<string> GetEnumerator()
{
return _root.GetTerminalChildren().Select(node => node.Word).GetEnumerator();
}

/// <summary>
/// IEnumerable\<String\>.IEnumerator implementation.
/// </summary>
/// <returns></returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion IEnumerable<String> Implementation

}
}
Loading

0 comments on commit 47766ac

Please sign in to comment.