PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync generates every time a new channel URI - c#

Is it correct that everytime i call PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync() to get my push channel a new Uri for my App is generated? I'mean the expiration time of the channel is about 1 month, but why is there generated a new one if it is not expired? I'need to send the URI everytime to my push server who needs to update the database. For 100 Users this might be okay, but we got > 2mio users.

It shouldn't change that often but may change before the expiry time if requested again. How are you making multiple calls?
If I put this in an app I get the same thing both times.
var uri = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
System.Diagnostics.Debug.WriteLine(uri.Uri);
var uri2 = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
System.Diagnostics.Debug.WriteLine(uri2.Uri);
If you're testing this by making the call after restarting the app, during development, and you're rebuilding between launches that may be the cause, as rebuilding can change the app's identity and so be seen as a different client to the notification system.

Related

Write an independent job which has no impact to the current system in .net core API

I'm working on a CRM application and my client wants to download some information within last 6 months. At the moment I have created an API endpoint which returns FileContentResult object and that will open a new tab in browser and automatically download an Excel file.
But this process is time consuming (since it has over 500K data) and users don't wait in the same page until the process is done. So, once an user change between pages I get issues and sometimes the application return timeout error since the API response is slow.
Now, I'm planning to enhance that same function/API endpoint by introducing some silent job. Which means once user click on "Download" button, process will start and it will send a message stating that "Your download process has been started. You will receive an email with the report within next 15minutes". In this way, users don't have to wait and they can do something else in the system.
Currently, I'm using async task and awaits until the job is done.
public async Task<FileContentResult> ExportData()
{
//...
//... process data and create excel file
//...
//...
return new FileContentResult(*some byte array*, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
FileDownloadName = $"Data.xlsx"
};
}
and I'm calling this method by
await exportService.ExportData();
My concern is what are the things I should change here in order to avoid any impact on other processes and run this as a background job. Once I get the result, I will send an email with an attachment.
Please help me with your valuable ideas. Thanks in advance
what are the things I should change here in order to avoid any impact on other processes and run this as a background job. Once I get the result, I will send an email with an attachment.
You should use a basic distributed architecture, as I describe on my blog. Specifically:
Instead of creating the report in your ASP.NET app, your ASP.NET app should just create a message indicating that the report should be created, and place that message into a durable queue.
Have a separate, independent process read the messages from that queue, generate the report, and send the email.

How to define HttpClient BaseAdress dynamically

I have an Asp.Net webpage written in c#. This webpage is communicating with a host on a server. The server adress is actually hardcoded in my controller methods as
static PatientController()
{
//Create the HttpClient once and use it
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:9002/prom2etheus/v1/");
_patientList = new List<Patient>();
}
How can I configure the URI as a parameter, that a user can enter at the start of the UI? My problem is, that the host is running on a server, and my UI is running on the same server, but in a Docker container. So the IP of the host can change, and I don't want to hardcode the IP of the host in my controller method. Which is the better way to do?
It depends. If you want the url to persist, then storing it in a database or a file is a good idea.
On the other hand, if it is okay to propt user every time the app starts, it could be stored in memory. This would jave the added benefit that, it would be much faster to read/write since there's no IO. There could be othet storage options such as third party storage provides too. In both cases, you would have to think about thread safety.

WPF CefSharp: Session restoring does not work

I have a question.
I develop a WPF application using CefSharp v75.1.141 from NuGet.
The application contains several instances of ChromiumWebBrowser with separate containers cookie cache, etc. where each instance is authorized on the site https://web.whatsapp.com/ under different account. On other sites, session are saved and restored successfully, but not at WhatsApp.
WhatsApp, as I understand it, uses cookies, local storage and file system for authorization.
All this seems to be saved on disk, but authorization is always required after a restart.
I tried many configuration options for Cef, but nothing worked.
But if you use Cef in normal mode (without separate storage), everything works fine.
Browser Initialization Code on app startup:
var settings = new CefSettings();
settings.RootCachePath = "Cache";
// For FHD+
Cef.EnableHighDPISupport();
// Initialize cef with the provided settings
Cef.Initialize(settings);
Browser instance setup:
if (UID == null)
UID = Guid.NewGuid().ToString();
var requestContextSettings = new RequestContextSettings
{
CachePath = Path.Combine("Cache", UID),
PersistSessionCookies = true,
PersistUserPreferences = true
};
Browser = new ChromiumWebBrowser("https://web.whatsapp.com/);
Browser.RequestContext = new RequestContext(requestContextSettings);
I really need your help. Ty.
WhatsApp is really.. kinda special. But there's a solution for your problem.
What you need to do is to give WhatsApp Web App little bit more time to process its stuff. Don't close your app too early (give it about 20-40 seconds to let it finish saving data).

is it possible to clean the cache of a service? [UWP]

I'm doing an application in UWP and since I'm managing a connection to a service in Azure that points to a database ... but I have this problem that saves me a previous error:
Clear API errors [UWP]
So it occurred to me that maybe that error is being stored in the service cache. and I do not know, is it possible to clean the cache of a service? or clean the cache somewhere in the controller so that this error is not stored.
I have looked at this documentation but I still do not know how to implement it
https://learn.microsoft.com/en-us/dotnet/api/system.web.caching.cache.remove?view=netframework-4.7.2
https://msdn.microsoft.com/en-us/library/edfcywt6.aspx
How can I programmatically clear cache?
https://www.codeproject.com/Questions/302329/How-to-force-clear-cache-in-asp-net
As #Martin Zikmund said, you'd better manage the outputcache in server side. If you want turn off the cache of httpclient, you could try this.
var RootFilter = new HttpBaseProtocolFilter();
RootFilter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent;
RootFilter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache;
var HttpClient = new HttpClient(RootFilter);

Content webservice call not refreshed in windows phone

Currently, I'm developing a Windows Phone 8.0 application that displays some 100 GPS locations on a map. The GPS data is obtained by calling a RESTful webservice as follows:
public async Task<string> GetWebContent(string uri)
{
string result = null;
using (var client = new HttpClient())
{
result = await client.GetStringAsync(new Uri(uri));
}
return result;
}
Here, the HttpClient is taken from the Nuget Package "Microsoft HTTP Client Libraries".
The first time the code is called, data is obtained and the GPS locations are nicely plotted on a map. However, since the GPS devices move constantly, I have to refresh the data every 30 seconds. This is where I hit the wall; the data contained in the variable "result" never changes. Even after several minutes the data is the same. The raw data contain a datetime property, which clearly tells me that the data is old and not just the GPS devices standing still. If I paste the uri into a webbrowser, and hit the refresh butten every 15 sec, the data does changed hence the webservice is working properly.
Since the HttpClient is contained in a using-statement, it is disposed off every time and some hidden caching mechanism seems impossible. So, does anyone have an idea?
cheers
Update
I tried using Fiddler, but had to follow a lengthy instruction to make it connect with the emulator. Once done, nothing worked anymore :-s Reverting all the certificates that Fiddler installed and copied the code to a regular WPF application and there it works als a charm.I'm no closer to an understanding of what's going on, but the problem seems to be related to the fact that it's a windows phone project.
It maybe caching the result from the first call. You may need to set the IfModifiedSince property in the request header before each subsequent call to ensure that its getting the latest value.
Example code from: https://stackoverflow.com/a/17884734/61226
client.DefaultRequestHeaders.IfModifiedSince = DateTime.UtcNow;
See similar issues here:
No cache with HttpClient in Windows Phone 8
Caching issue with WebClient/HttpClient

Categories

Resources