{
"error": {
"code": "",
"message": "The request is invalid. Details: The parameter 'value' in the request payload is not a valid parameter for the operation 'search'."
}
}
Then the problem is probably the “search” in the URL.
Try “index” instead:
1
POST {{url}}/indexes/user-index-2021-03-25/docs/index?api-version=2023-07-01-preview
The presentation I held at the p2p-k1darch conference
Ola Fjelddahl Göteborgskontoret https://selfelected.com https://github.com/LosManos/
10. Me, myself and I
11. Me, myself and I
Idag skall vi prata om automatgenererad kod i allmänhet och Roslyn code generator i synnerhet
20. T4
Kör när filer ändras. Minns inte hur man kopplar det. Också Framework. https://learn.microsoft.com/en-gb/previous-versions/visualstudio/visual-studio-2015/modeling/code-generation-and-t4-text-templates
30. Roslyn
Analyzer och Code generator
Vid “kompilering”
Känner endast till syntaxen. Plus något sorts kompilierings-context
Skapa kod via sträng eller kod/syntaxträd.
Lägger endast till kod
Borde inte kunna användas för AOP
Gamla sättet
Vid kompilering, får allt. Du söker ut det intressanta.
Inkrementellt
Nya inkrementella sättet, får anrop vid kompilering.
40. Var man startar
https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview Den skapar dock enligt gamla sättet.
Gå vidare till Andrew Lock https://andrewlock.net/creating-a-source-generator-part-1-creating-an-incremental-source-generator/
Skapa kod med kod https://carlos.mendible.com/2017/03/02/create-a-class-with-net-core-and-roslyn/ https://roslynquoter.azurewebsites.net
Min kod https://github.com/LosManos/FactoryMethodCodeGenerato
If you prefer video instead of text James Montemagno has a similar Youtube video.
Plans
Investigate the code. In MainPage.xaml there is a tight coupling from the xaml file to the code behind through
1
Clicked="OnCounterClicked"
. That method has code like
1
CounterBtn.Text = $"Clicked {count} time";
which means it is tightly coupled with the GUI.
When running the code, the counter and button text, will be updated by the code above.
Let’s get rid of the tight coupling.
Note: I am not satisfied how the click command will be wired up in the final solution. Please comment and help me make it better.
View model
MVVM works by GUI logic writing to an object/data structure (the view model) and the GUI graphic reading from it. And vice verse. It can be compared to a data contract with talking over the wire
This means we can test the logic without having a GUI and the GUI won’t have to rely on complicated GUI logic.
Create a class “MainPageViewModel.cs”, in a new folder “ViewModel”. We want to replace the counter.
To make it easier to react on the changes of the values we will use CommunityToolkit. To make it work the MVVM class must be public and partial. The field must be a field (not a property, and it must be with a leading lower case. Add a counter and a buttonText. Add a method to update the counter and replace the button text.
The reason for the above is that CommunityToolkit creates a Property for every field with ObservableProperty. You can find the rendered code in MauiApp1/Dependencies/.net7.0-xxxx/Analyzers. I have some reason for the view model to be public but won’t delve into it here.
Pressing play should work now as we only have added a class. Not changed or connected anything.
Connect
As per the readme you received when installing CommunityToolkit we have to manipulate the startup. Make it use the CommunityToolkit. Open MauiProgram.cs and add
1
.UseMauiCommunityToolkit()
Then we need to wire up the dependency injection. Alas add
In MainPage.xaml.cs we get rid of the OnCounterClicked method and the counter. We also need to inject the view model to the main page MainPage.xaml.cs. All that is left is:
1 2 3 4 5 6 7 8 9 10
namespace MauiApp1;
public partial class MainPage : ContentPage
{
public MainPage(ViewModel.MainPageViewModel vm)
{
InitializeComponent();
BindingContext = vm;
}
}
Do the xaml dance
As we have removed the event handler we also need to remove it from the xaml. Find the button and get rid of “Clicked=”OnCounterClicked””. We also don’t need the name as the code does not reference the button any more. The result looks like
1 2 3 4 5
<Button
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
HorizontalOptions="Center"
/>
If you press play now the program will start but nothing will happen if you press play.
Add dynamic button text and the the cryptic command binding to the button
1 2 3 4 5 6
<Button
Text="{Binding ButtonText}"
SemanticProperties.Hint="Counts the number of times you click"
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MainPageViewModel}}, Path=IncreaseCountCommand}"
HorizontalOptions="Center"
/>
The above will not work unless we tell the xaml where to find the command. So update the ContentPage element
PRAISE: Nice refactoring SUGGESTION: Isn’t it an Article?, not a Device. CHECK: Have you investigated all uses of the enum?
ola fjelddahl göteborgskontoret
Förvänta dig inte att din Pull request går igenom
PRAISE: Nice refactoring! SUGGESTION: Split line. CHECK: Do you use the enum the correct way? Are all cases considered? EXPLAIN: How do this work?
ola fjelddahl göteborgskontoret
Förvänta dig inte att din Pull request går igenom
PRAISE: Nice refactoring! SUGGESTION: Split line. CHECK: Do you use the enum the correct way? Are all cases considered? EXPLAIN: How do this work? FIX: Check for null.
ola fjelddahl göteborgskontoret
Förvänta dig inte att din Pull request går igenom
PRAISE: Nice refactoring! SUGGESTION: Split line. CHECK: Do you use the enum the correct way? Are all cases considered? EXPLAIN: How do this work? FIX: Check for null. QUESTION: Is this a HasA or a IsA
Föredraget förutsätter en vag förståelse av ORM. Fet orm (EF/Hibernate/cache). Micro-orm. (mappning av data och datatyper) Att det är en översättning från RDb:ns mängdbaserade struktur till det imperativa språkets list-baserade; och tvärtom.
3 skäl Typsäkerhet ändras inte så ofta det så när det väl är mappat Höger-vänster ändras ofta i början men tenderar att stabiliseras Refaktorering man kan bara automatrefaktorera namn och typer. strukturer är manuellt arbete
The idea is this: There are certain requirements on a data contract; like it being serializable and whatnot.
To verify this automagically the test program must be able to find them. It can be done through: 1) they are all in the same namespace. 2) their names are all suffixed with “DataContract” 3) they all implement “IDataContract”
Then through reflection/RTTI a test can get all data contracts and verify they are all ok.
Unfortunately Aspnet does not have a way to verify that an endpoint returns a data contract through unit testing; it has to be solved through integration testing or surveillance of production.
var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider();
var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();