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
4 changes: 4 additions & 0 deletions Clean CaDET/Clean CaDET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="Model\PlatformConnection\DTOs\NewEducationContentDTO.cs" />
<Compile Include="Model\PlatformConnection\DTOs\NewEducationSnippetDTO.cs" />
<Compile Include="Model\PlatformConnection\DTOs\SnippetType.cs" />
<Compile Include="Model\PlatformConnection\DTOs\Tag.cs" />
<Compile Include="Model\PlatformConnection\IPlatformConnection.cs" />
<Compile Include="View\Commands\ExamineProjectItemCommand.cs" />
<Compile Include="Model\SolutionParser\Data\CSharpProject.cs" />
Expand Down
61 changes: 54 additions & 7 deletions Clean CaDET/Model/PlatformConnection/CaDETConnection.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,70 @@
using System.Net.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Clean_CaDET.Model.PlatformConnection.DTOs;
using Newtonsoft.Json;

namespace Clean_CaDET.Model.PlatformConnection
{
public sealed class CaDETConnection: IPlatformConnection
public sealed class CaDETConnection : IPlatformConnection
{
private readonly HttpClient _httpClient = new HttpClient();
//TODO:Refactor to be read from configuration
private readonly string codeUrl = "https://localhost:44325/api/repository/education/class";
private readonly string codeUrlRepositoryCompiler = "https://localhost:44325/api/repository/education/class";
private readonly string codeUrlSmartTutor = "https://localhost:44333/api/smarttutor/education/class";

//TODO: Delete this two Lists and Logic about them in this method, only testing purposes
List<Guid> sentRequests = new List<Guid>();
List<Guid> recivedRequests = new List<Guid>();

public async Task<ClassQualityAnalysisResponse> GetClassQualityAnalysisAsync(string sourceCode)
{
StringContent request = new StringContent(JsonConvert.SerializeObject(sourceCode), Encoding.UTF8, "application/json");
HttpResponseMessage response = await _httpClient.PostAsync(codeUrl, request);
string content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<ClassQualityAnalysisResponse>(content);
StringContent requestRepositoryCompiler = new StringContent(JsonConvert.SerializeObject(sourceCode), Encoding.UTF8, "application/json");
HttpResponseMessage responseRepositoryCompiler = await _httpClient.PostAsync(codeUrlRepositoryCompiler, requestRepositoryCompiler);
string contentRepositoryCompiler = await responseRepositoryCompiler.Content.ReadAsStringAsync();

ClassQualityAnalysisResponse repositoryCompilerResponse = JsonConvert.DeserializeObject<ClassQualityAnalysisResponse>(contentRepositoryCompiler);



ClassQualityAnalysisResponse analysis = await SendRequestToSmartTutor(repositoryCompilerResponse);

var EmptyGuid = new Guid(new Byte[16]);
Guid sentRequest = repositoryCompilerResponse.Id;
Guid recivedRequest = analysis.Id;

sentRequests.Add(sentRequest);
recivedRequests.Add(recivedRequest);

while (recivedRequest.Equals(EmptyGuid) || !(sentRequest.Equals(recivedRequest)))
{
analysis = await SendRequestToSmartTutor(repositoryCompilerResponse);
}


if (sentRequests.All(recivedRequests.Contains) && sentRequests.Count == recivedRequests.Count)
{
System.Diagnostics.Debug.WriteLine("All sent messages have arrived");
}
else
{
System.Diagnostics.Debug.WriteLine("Not all sent messages have arrived");
}

return analysis;
}

private async Task<ClassQualityAnalysisResponse> SendRequestToSmartTutor(ClassQualityAnalysisResponse repositoryCompilerResponse)
{
StringContent requestSmartTutor = new StringContent(JsonConvert.SerializeObject(repositoryCompilerResponse.Id), Encoding.UTF8, "application/json");
HttpResponseMessage responseSmartTutor = await _httpClient.PostAsync(codeUrlSmartTutor, requestSmartTutor);
string contentSmartTutor = await responseSmartTutor.Content.ReadAsStringAsync();

var analysis = JsonConvert.DeserializeObject<ClassQualityAnalysisResponse>(contentSmartTutor);
return analysis;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Clean_CaDET.Model.PlatformConnection.DTOs
using System;

namespace Clean_CaDET.Model.PlatformConnection.DTOs
{
public class ClassQualityAnalysisResponse
{
public ClassMetricsDTO Metrics { get; set; }
public EducationalContentDTO Content { get; set; }
public Guid Id { get; set; }
public NewEducationContentDTO NewContent { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clean_CaDET.Model.PlatformConnection.DTOs
{
public class NewEducationContentDTO
{
public int ContentQuality { get; set; }
public int ContentDifficulty { get; set; }
public ObservableCollection<NewEducationSnippetDTO> EducationSnippets { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clean_CaDET.Model.PlatformConnection.DTOs
{
public class NewEducationSnippetDTO
{
public int SnippetQuality { get; set; }
public int SnippetDifficulty { get; set; }
public SnippetType SnippetType { get; set; }
public List<Tag> Tags { get; set; }
public string Content { get; set; }
}
}
12 changes: 12 additions & 0 deletions Clean CaDET/Model/PlatformConnection/DTOs/SnippetType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Clean_CaDET.Model.PlatformConnection.DTOs
{
public enum SnippetType
{
CodeSnippet,
LongText,
ShortText,
Video,
Image,
Diagram
}
}
9 changes: 9 additions & 0 deletions Clean CaDET/Model/PlatformConnection/DTOs/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Clean_CaDET.Model.PlatformConnection.DTOs
{
public enum Tag
{
Funny,
MustKnow,
Interesting
}
}
24 changes: 14 additions & 10 deletions Clean CaDET/View/Commands/ExamineProjectItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,23 @@ public static async Task InitializeAsync(AsyncPackage package)
}
private async void Execute(object sender, EventArgs e)
{
ClassQualityAnalysisResponse codeQualityAnalysis = await _service.AnalyzeClassQualityAsync(_selectedFilePath);
/* Uncomment this for loop if you want to test sending more than one request*/
/* for (int i = 0; i < 100; i++)
{*/
ClassQualityAnalysisResponse codeQualityAnalysis = await _service.AnalyzeClassQualityAsync(_selectedFilePath);

ToolWindowPane window = _package.FindToolWindow(typeof(TutoringWindow), 0, true);
if (window?.Frame == null)
{
throw new NotSupportedException("Cannot create tool window");
}
ToolWindowPane window = _package.FindToolWindow(typeof(TutoringWindow), 0, true);
if (window?.Frame == null)
{
throw new NotSupportedException("Cannot create tool window");
}

var tutoringWindow = window as TutoringWindow;
tutoringWindow?.UpdateVMContent(codeQualityAnalysis.Content, codeQualityAnalysis.Metrics);
var tutoringWindow = window as TutoringWindow;
tutoringWindow?.UpdateVMContent(codeQualityAnalysis.NewContent);

IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
ErrorHandler.ThrowOnFailure(windowFrame.Show());
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
ErrorHandler.ThrowOnFailure(windowFrame.Show());
/* }*/
}
}
}
5 changes: 2 additions & 3 deletions Clean CaDET/View/TutoringWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ public TutoringWindow() : base(null)
Content = new TutoringWindowControl();
}

public void UpdateVMContent(EducationalContentDTO content, ClassMetricsDTO metrics)
public void UpdateVMContent(NewEducationContentDTO newEducationContent)
{
var windowControl = Content as TutoringWindowControl;
windowControl.ViewModel.Content = content;
windowControl.ViewModel.Metrics = metrics;
windowControl.ViewModel.NewContent = newEducationContent;
}
}
}
94 changes: 88 additions & 6 deletions Clean CaDET/View/TutoringWindowControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,96 @@
</Style>
</UserControl.Resources>

<Grid Name="TutorGrid">
<Grid Background="#DBE4EE" Name="TutorGrid">
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden">
<StackPanel MaxWidth="{Binding ElementName=TutorGrid, Path=ActualWidth}" Orientation="Vertical" CanVerticallyScroll="True">
<TextBox Text="{Binding Content.Title}" Style="{StaticResource TitleContentStyle}"/>
<TextBox Text="{Binding Content.GeneralDescription}" Style="{StaticResource TextContentStyle}"/>
<TextBox Text="{Binding Content.DetectedIssue}" Style="{StaticResource TextContentStyle}"/>
<Image Source="{Binding Content.Image}"/>
<TextBox Text="{Binding Content.Recommendations}" Style="{StaticResource TextContentStyle}"/>
<!-- Education content START -->
<StackPanel Margin="20 20" Width="600">
<!-- Content description START -->
<StackPanel HorizontalAlignment="Center" Margin="0 10 0 0" Orientation="Horizontal">
<TextBlock Text="Content Difficulty"></TextBlock>
<TextBox IsEnabled="False" Text="{Binding NewContent.ContentDifficulty}" Margin="10 0 0 0"></TextBox>
<Decorator Width="50"></Decorator>
<TextBlock Text="Content Quality" ></TextBlock>
<TextBox IsEnabled="False" Text="{Binding NewContent.ContentQuality}" Margin="10 0 0 0"></TextBox>
</StackPanel>
<!-- Content description END -->

<!-- Education Snippets START -->
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"
>
<ItemsControl ItemsSource="{Binding NewContent.EducationSnippets}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- Snippet START -->
<Border BorderBrush="#054A91" CornerRadius="5" BorderThickness="1" Width="300" Margin="10" >
<StackPanel>
<!-- Snippet Type START -->
<StackPanel Margin="25 10 25 0" Orientation="Horizontal">
<TextBlock Text="Snippet Type:"></TextBlock>
<TextBox IsEnabled="False" Text="{Binding SnippetType}" Margin="5 0 35 0"></TextBox>
</StackPanel>
<!-- Snippet Type END -->

<!-- Snippet Content START -->
<Border Background="#81A4CD" Width="250" Margin="10" MinHeight="150" CornerRadius="5">
<Grid Height="Auto" Margin="7" HorizontalAlignment="Center" VerticalAlignment="Center">
<!--<TextBox Margin="10" TextWrapping="Wrap" Text="{Binding Content}"></TextBox>-->
<TextBox Foreground="White" Background="Transparent" BorderThickness="0" Text="{Binding Content, Mode=OneWay}" IsReadOnly="True" TextWrapping="Wrap" />
<Image Source="{Binding Content}" Stretch="Fill"/>
</Grid>
</Border>
<!-- Snippet Content END -->

<!-- Difficulty & Quality START -->
<StackPanel Margin="25 10 25 20 " Orientation="Horizontal">
<TextBlock Text="Snippet Difficulty:"></TextBlock>
<TextBox IsEnabled="False" Text="{Binding SnippetDifficulty}" Margin="5 0 35 0"></TextBox>
<TextBlock Text="Snippet Quality:"></TextBlock>
<TextBox IsEnabled="False" Text="{Binding SnippetQuality}" Margin="5 0 15 0"></TextBox>
</StackPanel>
<!-- Difficulty & Quality END -->

<!-- Tags START -->
<StackPanel >
<ItemsControl ItemsSource ="{Binding Tags}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="#3E7CB1" Margin="25 3 0 10" Height="30" CornerRadius="5">
<StackPanel HorizontalAlignment="Center" Margin="5" VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock Foreground="White" Text="{Binding}"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<!-- Tags END -->
</StackPanel>
</Border>
<!-- Snippet END -->
</DataTemplate>

</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
<!-- Education Snippets END -->

</StackPanel>
<!-- Education content END -->



</StackPanel>
</ScrollViewer>
</Grid>
Expand Down
39 changes: 37 additions & 2 deletions Clean CaDET/View/TutoringWindowControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Clean_CaDET.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Clean_CaDET.Model;
using Clean_CaDET.View.ViewModel;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -27,7 +29,40 @@ public TutoringWindowControl()
"Our analysis shows that this class has low cohesion. This signals that there might be two or more concepts represented by this class. Looking at the figure, we see how the class can be split into three classes, each containing a method and related field. Importantly, we presume the methods are not accessors (getters and setters).",
Recommendations =
"See if you can split the class by grouping the fields (or their subset) with methods that utilize them. If you can find suitable names for the two groups than you should perform the Extract Class refactoring. If one group is hard to define and sufficiently large, this might mean you have even more classes to extract."
}
},
NewContent = new NewEducationContentDTO()
{
ContentDifficulty = 4,
ContentQuality = 3,
EducationSnippets = new ObservableCollection<NewEducationSnippetDTO>()
{
new NewEducationSnippetDTO()
{
SnippetType = SnippetType.ShortText,
Content = "Some short text",
SnippetDifficulty = 3,
SnippetQuality = 2,
Tags = new List<Tag>()
{
Model.PlatformConnection.DTOs.Tag.Funny,
Model.PlatformConnection.DTOs.Tag.Interesting
}
},
new NewEducationSnippetDTO()
{
SnippetType = SnippetType.LongText,
Content = "Some must know long text",
SnippetDifficulty = 5,
SnippetQuality = 5,
Tags = new List<Tag>()
{
Model.PlatformConnection.DTOs.Tag.MustKnow
}
}
}
}


};

DataContext = ViewModel;
Expand Down
Loading