eduardoA
Reatime update
Hello, I am using firestore, to store some values
And I have a service, the get the value updated every second
that gets updated every second in the data in the database
like this
https://reccloud.com/u/edxlrsd
I am trying to bind this value and see when the value rise in my collection view
but when I bind I get 0
private async void InitializeAsync() {
if (_firestoreDb != null) {
await LoadOrInitializeTurbineAsync();
InitializeTimer();
}
}
async Task LoadOrInitializeTurbineAsync() {
var turbinesRef = _firestoreDb!.Collection(collectionName);
var snapshot = await turbinesRef.GetSnapshotAsync();
if (snapshot.Count == 0) {
var turbine = new Turbine {
Id = "EC-G-SB",
Country = "Ecuador",
Name = "Estación Ciudadela Simón Bolívar",
Address = "Av. de las Américas, Guayaquil 090513, Ecuador",
Latitude = -2.151993,
Longitude = -79.886109,
};
turbine.RemovedCo2Kilograms = Math.Round(turbine.EnergyProduced * turbine.Co2EmissionOffset, 5);
var turbineDocRef = turbinesRef.Document(turbine.Id);
private async void InitializeAsync() {
if (_firestoreDb != null) {
await LoadOrInitializeTurbineAsync();
InitializeTimer();
}
}
async Task LoadOrInitializeTurbineAsync() {
var turbinesRef = _firestoreDb!.Collection(collectionName);
var snapshot = await turbinesRef.GetSnapshotAsync();
if (snapshot.Count == 0) {
var turbine = new Turbine {
Id = "EC-G-SB",
Country = "Ecuador",
Name = "Estación Ciudadela Simón Bolívar",
Address = "Av. de las Américas, Guayaquil 090513, Ecuador",
Latitude = -2.151993,
Longitude = -79.886109,
};
turbine.RemovedCo2Kilograms = Math.Round(turbine.EnergyProduced * turbine.Co2EmissionOffset, 5);
var turbineDocRef = turbinesRef.Document(turbine.Id);
private void InitializeTimer() {
_timer = new System.Timers.Timer(1000);
_timer.Elapsed += async (sender, e) => await UpdateCO2ValueAsync();
_timer.AutoReset = true;
_timer.Enabled = true;
}
private async Task UpdateCO2ValueAsync() {
var turbineRef = _firestoreDb!.Collection("turbines").Document("EC-G-SB");
var snapshot = await turbineRef.GetSnapshotAsync();
var turbine = snapshot.ConvertTo<Turbine>();
var beforeUpdate = turbine.RemovedCo2Kilograms;
turbine.RemovedCo2Kilograms = Math.Round(beforeUpdate + 0.0007, 5);
turbine.FinalCo2Removed = turbine.RemovedCo2Kilograms;
await turbineRef.SetAsync(turbine, SetOptions.Overwrite);
private void InitializeTimer() {
_timer = new System.Timers.Timer(1000);
_timer.Elapsed += async (sender, e) => await UpdateCO2ValueAsync();
_timer.AutoReset = true;
_timer.Enabled = true;
}
private async Task UpdateCO2ValueAsync() {
var turbineRef = _firestoreDb!.Collection("turbines").Document("EC-G-SB");
var snapshot = await turbineRef.GetSnapshotAsync();
var turbine = snapshot.ConvertTo<Turbine>();
var beforeUpdate = turbine.RemovedCo2Kilograms;
turbine.RemovedCo2Kilograms = Math.Round(beforeUpdate + 0.0007, 5);
turbine.FinalCo2Removed = turbine.RemovedCo2Kilograms;
await turbineRef.SetAsync(turbine, SetOptions.Overwrite);
[ObservableProperty]
public double finalCo2Removed;
[ObservableProperty]
public double finalCo2Removed;
6 replies
Start an app on fullSreem on mac
I did this for Windows
.ConfigureLifecycleEvents(events => {
#if WINDOWS
events.AddWindows(windows => windows
.OnWindowCreated((window) => {
window.ExtendsContentIntoTitleBar = false;
var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
switch (appWindow.Presenter) {
case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
overlappedPresenter.Maximize();
break;
}
}));
#endif
.ConfigureLifecycleEvents(events => {
#if WINDOWS
events.AddWindows(windows => windows
.OnWindowCreated((window) => {
window.ExtendsContentIntoTitleBar = false;
var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
switch (appWindow.Presenter) {
case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
overlappedPresenter.Maximize();
break;
}
}));
#endif
1 replies
Login Flow with shell
the fir time I login, everything is fine, but if I do it again I get this
This also happens if I navigate to the same page twice within the app shell
An item with the same key has already been added. Key: 0'
An item with the same key has already been added. Key: 0'
public partial class LoginPageViewModel
[ObservableProperty]
bool isPopOpen;
[ObservableProperty]
User user = new();
[RelayCommand]
void OpenPopUp() {
IsPopOpen = true;
}
[RelayCommand]
async Task Login() {
IsBusy = true;
//var user = await authenticationService.LoginWithEmailAndPassword(User.Email!, User.Password!);
//var user = await authenticationService.LoginWithEmailAndPassword("[email protected]", "123456");
await appService.NavigateTo($"{nameof(NewLecturePage)}");
public partial class LoginPageViewModel
[ObservableProperty]
bool isPopOpen;
[ObservableProperty]
User user = new();
[RelayCommand]
void OpenPopUp() {
IsPopOpen = true;
}
[RelayCommand]
async Task Login() {
IsBusy = true;
//var user = await authenticationService.LoginWithEmailAndPassword(User.Email!, User.Password!);
//var user = await authenticationService.LoginWithEmailAndPassword("[email protected]", "123456");
await appService.NavigateTo($"{nameof(NewLecturePage)}");
<ShellContent
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="loginPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />
<FlyoutItem>
<ShellContent
ContentTemplate="{DataTemplate pages:NewLecturePage}"
Route="NewLecturePage" />
</FlyoutItem>
<ShellContent
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="loginPage"
Shell.FlyoutBehavior="Disabled"
Shell.FlyoutItemIsVisible="False" />
<FlyoutItem>
<ShellContent
ContentTemplate="{DataTemplate pages:NewLecturePage}"
Route="NewLecturePage" />
</FlyoutItem>
public class StartupPageViewModel : BaseViewModel {
private readonly IAppService _appService;
private readonly IConnectivity _connectivity;
public StartupPageViewModel(IAppService appService, IConnectivity connectivity) {
_appService = appService;
_connectivity = connectivity;
CheckInternet(_connectivity.NetworkAccess);
}
private void CheckInternet(NetworkAccess networkAccess) {
if(networkAccess is not NetworkAccess.Internet) {
_appService.NavigateTo($"{nameof(NoInternetPage)}");
} else {
_appService.NavigateTo($"{nameof(LoginPage)}");
}
}
}
public class StartupPageViewModel : BaseViewModel {
private readonly IAppService _appService;
private readonly IConnectivity _connectivity;
public StartupPageViewModel(IAppService appService, IConnectivity connectivity) {
_appService = appService;
_connectivity = connectivity;
CheckInternet(_connectivity.NetworkAccess);
}
private void CheckInternet(NetworkAccess networkAccess) {
if(networkAccess is not NetworkAccess.Internet) {
_appService.NavigateTo($"{nameof(NoInternetPage)}");
} else {
_appService.NavigateTo($"{nameof(LoginPage)}");
}
}
}
1 replies
Microsoft MVVM toolkit
I have a very simple question
I have two entries and a button
[RelayCommand]
async Task Register() {
IsPopOpen = false;
//await dataService.AddAsync("Users", Student);
}
```
what I want to do is enable the button only if the email and password are entered
<inputLayout:SfTextInputLayout
ContainerBackground="White"
ContainerType="Outlined"
Hint="Email"
IsHintAlwaysFloated="True"
OutlineCornerRadius="8">
<Entry />
</inputLayout:SfTextInputLayout>
<inputLayout:SfTextInputLayout
Grid.Row="1"
ContainerBackground="White"
ContainerType="Outlined"
Hint="Password"
IsHintAlwaysFloated="True"
OutlineCornerRadius="8">
<Entry />
</inputLayout:SfTextInputLayout>
this is the command I am executing
<inputLayout:SfTextInputLayout
ContainerBackground="White"
ContainerType="Outlined"
Hint="Email"
IsHintAlwaysFloated="True"
OutlineCornerRadius="8">
<Entry />
</inputLayout:SfTextInputLayout>
<inputLayout:SfTextInputLayout
Grid.Row="1"
ContainerBackground="White"
ContainerType="Outlined"
Hint="Password"
IsHintAlwaysFloated="True"
OutlineCornerRadius="8">
<Entry />
</inputLayout:SfTextInputLayout>
this is the command I am executing
9 replies
❔ Problems stopping the speech
Even though Microsoft tell you to call the stop, dosen't stop the speech
I have two buttons: play and stop
my VM
and my service
The service reads my text, but when I press stop, it dosent work
<Button
Margin="10,0,0,0"
Command="{Binding SpeakButtonCommand}"
Content="{x:Static res:Lang.Read}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsPlayingEnabled}" />
<Button
Margin="10,0,0,0"
Command="{Binding StopSpeakButtonCommand}"
Content="{x:Static res:Lang.Stop}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsStopEnabled}" />
<Button
Margin="10,0,0,0"
Command="{Binding SpeakButtonCommand}"
Content="{x:Static res:Lang.Read}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsPlayingEnabled}" />
<Button
Margin="10,0,0,0"
Command="{Binding StopSpeakButtonCommand}"
Content="{x:Static res:Lang.Stop}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsStopEnabled}" />
IsPlayingEnabled = true;
AzureTextToSpeech = new AzureTextToSpeechService();
IsStopEnabled = false;
sb = new();
Text = GetFile(file);
ColorPairs = ColorHelper.GetColors();
SpeakButtonCommand = new AsyncCommand(SpeakButtonction);
StopSpeakButtonCommand = new AsyncCommand(StopSpeakButtonAction);
}
private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}
private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
IsPlayingEnabled = true;
AzureTextToSpeech = new AzureTextToSpeechService();
IsStopEnabled = false;
sb = new();
Text = GetFile(file);
ColorPairs = ColorHelper.GetColors();
SpeakButtonCommand = new AsyncCommand(SpeakButtonction);
StopSpeakButtonCommand = new AsyncCommand(StopSpeakButtonAction);
}
private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}
private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);
switch (lang.Iso6391Name) {
...//
}
speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);
}
public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);
switch (lang.Iso6391Name) {
...//
}
speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);
}
public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
2 replies
Making a shortcut for checking null component in unity
Evetime I create a new component in unity, I something like
So I created a shortcut
but when I use it, I get this
this is not what I want, where is my message? and why there is nothing here for me to edit? and hi it dosent close the if
if (!TryGetComponent(out _rb2D)) {
Debug.LogError($"There is no rigidbody component in the {transform.name}");
}
if (!TryGetComponent(out _rb2D)) {
Debug.LogError($"There is no rigidbody component in the {transform.name}");
}
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity null check components</Title>
<Shortcut>ucnc</Shortcut>
<Description>This code snippet, will allow you to check you component, to see if they are null</Description>
<Author>Eduardo Gomez</Author>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
if(!TryGetComponent(out $ComponentName$))
{
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
}
]]>
</Code>
<Declarations>
<Literal>
<ID>ComponentName</ID>
<ToolTip>The component name that you want to check for null</ToolTip>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity null check components</Title>
<Shortcut>ucnc</Shortcut>
<Description>This code snippet, will allow you to check you component, to see if they are null</Description>
<Author>Eduardo Gomez</Author>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
if(!TryGetComponent(out $ComponentName$))
{
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
}
]]>
</Code>
<Declarations>
<Literal>
<ID>ComponentName</ID>
<ToolTip>The component name that you want to check for null</ToolTip>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets>
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
if (!TryGetComponent(out )) {
if (!TryGetComponent(out )) {
5 replies
❔ snippet help
In unity, is always s good practice to null check component. I made this
but when I use it, I get
it dosent close the if.
it dosent put all of the debug statement.
it dosent put in $Component Nam$ so I can edit it
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity null check components</Title>
<Shortcut>ucnc</Shortcut>
<Description>This code snippet, will allow you to check you component, to see if they are null</Description>
<Author>Eduardo Gomez</Author>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
if(!TryGetComponent(out $ComponentName$))
{
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
}
]]>
</Code>
<Declarations>
<Literal>
<ID>ComponentName</ID>
<ToolTip>The component name that you want to check for null</ToolTip>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unity null check components</Title>
<Shortcut>ucnc</Shortcut>
<Description>This code snippet, will allow you to check you component, to see if they are null</Description>
<Author>Eduardo Gomez</Author>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[
if(!TryGetComponent(out $ComponentName$))
{
Debug.LogError($"There is no $ComponentName$ component in your {transform.name}");
}
]]>
</Code>
<Declarations>
<Literal>
<ID>ComponentName</ID>
<ToolTip>The component name that you want to check for null</ToolTip>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets>
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName
if (!TryGetComponent(out )) {
Debug.LogError(ComponentName
2 replies
❔ Azure Speech Service wont shut up
I am using azure in a WPF app, where I have two buttons, Read, and Stop
The problem is, that when I click on Stop, it dosent do anything.
I already tried to wrap the entire speak process into a thread and cancelling it, and it works 3 times and that it
private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}
private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}
private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
SpeechSynthesizer speechSynthesizer;
public async Task ReadOutLoudAsync(string text) {
Response<DetectedLanguage> response = textClient.DetectLanguage(text);
DetectedLanguage lang = response.Value;
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);
switch (lang.Iso6391Name) {
case "en":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)";
config.SpeechSynthesisLanguage = "en-us";
break;
case "es":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (es-VE, PaolaNeural)";
config.SpeechSynthesisLanguage = "es-VE";
break;
default:
break;
}
speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);
}
public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
SpeechSynthesizer speechSynthesizer;
public async Task ReadOutLoudAsync(string text) {
Response<DetectedLanguage> response = textClient.DetectLanguage(text);
DetectedLanguage lang = response.Value;
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);
switch (lang.Iso6391Name) {
case "en":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)";
config.SpeechSynthesisLanguage = "en-us";
break;
case "es":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (es-VE, PaolaNeural)";
config.SpeechSynthesisLanguage = "es-VE";
break;
default:
break;
}
speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);
}
public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
2 replies
❔ My Azure service do not Stop
I have a text to speech service, and for some reason, when I press the button to stop it dosent do anything
I call like this
public class AzureTextToSpeechService {
private SpeechSynthesizer? synthesizer;
public async Task ReadOutLoudAsync(string text) {
AzureKeyCredential credentials = new(key);
TextAnalyticsClient textClient = new(endpoint, credentials);
Response<DetectedLanguage> response = textClient.DetectLanguage(text);
DetectedLanguage lang = response.Value;
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);
switch (lang.Iso6391Name) {
case "en":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)";
config.SpeechSynthesisLanguage = "en-us";
break;
case "es":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (es-VE, PaolaNeural)";
config.SpeechSynthesisLanguage = "es-VE";
break;
}
synthesizer = new SpeechSynthesizer(config);
IsSpeaking = true;
await synthesizer.SpeakTextAsync(text);
}
public async Task StopSpeaking() {
if (synthesizer != null && IsSpeaking == true) {
await synthesizer.StopSpeakingAsync();
]
}
}
}
public class AzureTextToSpeechService {
private SpeechSynthesizer? synthesizer;
public async Task ReadOutLoudAsync(string text) {
AzureKeyCredential credentials = new(key);
TextAnalyticsClient textClient = new(endpoint, credentials);
Response<DetectedLanguage> response = textClient.DetectLanguage(text);
DetectedLanguage lang = response.Value;
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);
switch (lang.Iso6391Name) {
case "en":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, SaraNeural)";
config.SpeechSynthesisLanguage = "en-us";
break;
case "es":
config.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (es-VE, PaolaNeural)";
config.SpeechSynthesisLanguage = "es-VE";
break;
}
synthesizer = new SpeechSynthesizer(config);
IsSpeaking = true;
await synthesizer.SpeakTextAsync(text);
}
public async Task StopSpeaking() {
if (synthesizer != null && IsSpeaking == true) {
await synthesizer.StopSpeakingAsync();
]
}
}
}
private void StopSpeakButtonAction() {
AzureTextToSpeechService.StopSpeech();
IsPlayingEnabled = true;
IsStopEnabled = false;
}
private async void SpeakButtonction() {
await AzureTextToSpeechService.ReadOutLoudAsync(Text);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
private void StopSpeakButtonAction() {
AzureTextToSpeechService.StopSpeech();
IsPlayingEnabled = true;
IsStopEnabled = false;
}
private async void SpeakButtonction() {
await AzureTextToSpeechService.ReadOutLoudAsync(Text);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
13 replies