I´m new in this topic about Firebase in C#, the online documetation is bad, I only find 2 (FireSharp and FireBaseDataBase) API for connect my Desktop App with Firebase and also I try to connect my app with JSON HttpRequest. In all the case when i try to PUT, UPDATE, DELETE, the response time delay 4 seconds and i´m sure that my internet have a good Connection.
On the other hand and as a main question (using the API FirebaseDataBase for C# WPF) is why i can´t put the real time data in a List(). First I try to do this.
//Example//`
public void StreamData()
{
List<Dinosaur> group= new List<Dinosaur>();
var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");
var observable = firebase
.Child("dinosaurs")
.AsObservable<Dinosaur>()
.Subscribe(d => group.Add(d.Object));
}
But the problem here is that "group" dont Add "d.Object".
Then I try to use this code:
public void StreamData()
{
List<Persona> g = new List<Persona>();
var observable = firebaseClient.Child("Information").AsObservable<Persona>();
var t= observable.ObserveOnDispatcher().AsObservableCollection();
}
But I have this problem :
System.InvalidOperationException: 'The current thread has no
Dispatcher associated with it.'
In summary i try to get a real time data from Firebase with the API FireBaseDataBase, as a List() because i want to insert in my Datagrid.
Related
I'm trying to build an app that detects product from android and send it in real-time to the desktop application via firebase but I don't know firebase doesn't work in real-time when I get value on C# app (I mean when I change values it doesn't change in the app automatically.)
Rq: I'm using FireSharp reference and My code for receiving:
public void getdata()
{
var res = client.Get(#"Store/");
Store str = res.ResultAs<Store>();
store.Text = str.Tags;
nb.Text = str.nb;
}
By calling the Get method, you're calling the server to get the data only once.
If you want to instead get the data now and then continue to listen for updates, use the OnAsync method. From the linked documentation:
EventStreamResponse response = await _client.OnAsync("chat", (sender, args, context) => {
System.Console.WriteLine(args.Data);
});
//Call dispose to stop listening for events
response.Dispose();
I'm polling data to my angular app from a c# web api. Every time all data is polled, even though much of the data haven't changed. I would like to poll only the objects which have actually been updated in any sort of way.
This is my code in my Controller.cs
//Get all details of the available vehicles
[HttpGet]
[Route("api/details")]
public object GetFleetStatusDetails()
{
var fmsData = this.fmsdb.Value.GetFleetStatusDetails();
var data = fmsData.Entries;
List<VehicleDetails> result = new List<VehicleDetails>();
foreach (var item in data)
{
if (item != null)
{
var details = ConvertVehicleDetail(item);
result.Add(details);
}
}
return result;
}
As you can see im converting the data into VehicleDetails which I later add to my VehicleDetails list. The data im getting is in JSON-format. Is there a way of comparing my last poll with the current poll without going to much deeper down into the database? If so how would I do that?
I suggest saving the last state either through the Browser's local storage or using ngrx.
Without knowing what this.fmsdb.Value.GetFleetStatusDetails(); does or the schema of the database you're calling the best guess answer would be to create two endpoints in the API.
The first would use this.fmsdb.Value.GetFleetStatusDetails(); to get the full set of results. Once the data has been downloaded from the endpoint store the current date/time in the angular view and pass that to the second endpoint...
The second endpoint would get the records that have been changed since the date/time you got the first set of data. This assumes that you are storing the updated date time.
[HttpGet]
[Route("api/updateddetails")]
public object GetUpdatedFleetStatusDetails([FromUrl]DateTime date)
{
var fmsData = this.fmsdb.Value.GetUpdatedFleetStatusDetails(date);
return fmsData.Entries
.Where(x => x != null)
.Select(ConvertVehicleDetail);
}
Could give more details if knew what was in this.fmsdb.Value.GetFleetStatusDetails()
PS Haven't tested this code.
I have a c# script task in an ssis package designed to geocode data through my company's proprietary system. It currently works like this:
1) Pull query of addresses and put in data table
2) Loop through that table and Foreach row, build request, send request, wait for response, then insert back into the database.
The issue is that each call takes forever to return, because before going out and getting a new address on the api side, it checks a current database(string match) to ensure the address does not already exist. If not exists, then go out and get me new data from a service like google.
Because I'm doing one at a time, it makes it easy to keep the ID field with the record when I go back to insert it into the database.
Now comes the issue at hand... I was told to configure this as multi-thread or asynchronous. Here is the page I was reading on here about this topic:
ASP.NET Multithreading Web Requests
var urls = new List<string>();
var results = new ConcurrentBag<OccupationSearch>();
Parallel.ForEach(urls, url =>
{
WebRequest request = WebRequest.Create(requestUrl);
string response = new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();
var result = JsonSerializer().Deserialize<OccupationSearch>(new JsonTextReader(new StringReader(response)));
results.Add(result);
});
Perhaps I'm thinking about this wrong, but if I send 2 requests(A & B) and lets say B actually returns first, how can I ensure that when I go back to update my database I'm updating the correct record? Can I send the ID with the API call and return it?
My thoughts are to create an array of requests, burn through them without waiting for a response and return those value in another array, that I will then loop through on my insert statement.
Is this a good way of going about this? I've never used Parrallel.ForEach, and all the info I find on it is too technical for me to visualize and apply to my situation.
Perhaps I'm thinking about this wrong, but if I send 2 requests(A & B) and lets say B actually returns first, how can I ensure that when I go back to update my database I'm updating the correct record? Can I send the ID with the API call and return it?
None of your code contains anything that looks like an "ID," but I assume everything you need is in the URL. If that is the case, one simple answer is to use a Dictionary instead of a Bag.
List<string> urls = GetListOfUrlsFromSomewhere();
var results = new ConcurrentDictionary<string, OccupationSearch>();
Parallel.ForEach(urls.Distinct(), url =>
{
WebRequest request = WebRequest.Create(url);
string response = new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();
var result = JsonSerializer().Deserialize<OccupationSearch>(new JsonTextReader(new StringReader(response)));
results.TryAdd(url, result);
});
After this code is done, the results dictionary will contain entries that correlate each response back to the original URL.
Note: you might want to use HttpClient instead of WebClient, and you should take care to dispose of your disposable objects, e.g. StreamReader and StringReader.
I have a requirement to hang up the current phone call programmatically in Genesys Workspace Desktop edition. Here is what I have:
public class SomeService
{
private readonly IEnterpriseServiceProvider _esp;
public SomeService(IEnterpriseServiceProvider esp)
{
_esp = esp;
}
public void HangupCurrentCall()
{
var iv = _esp.Resolve<IInteractionVoice>();
iv.Release();
}
}
The code above is executing with no error, but the call is not being hung up.
You can't hangup current call just from enterprise service. WDE providing API for that. You can check from developer guide document. Actually you have two options to achieve this. First way using WDE API command calls. Second way using universal SDK (PSDK) to hangup current call.
First of all you need to collect current call's interactionId. After that can call a command like that,
commandManager.CommandsByName["InteractionVoiceReleaseCall"].Insert(0, new CommandActivator()
{
CommandType = typeof(CustomCommand.ReleaseCall),
Name = "InteractionVoiceReleaseCall"
});
You can find all commands list from WDE api guide.
On your command type (class) you must return boolean. If you return false, its ok to continue, sending true like break the command.
Or you can directly execute a command like this;
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("CommandParameter", interaction);
parameters.Add("Reasons", reasons);
parameters.Add("Extensions", extensions);
commandManager.GetChainOfCommandByName("InteractionVoiceReleaseCall").Execute();
As a SDK certificated developer, i always prefer PSDK(universal genesys sdk). You can retrieve current SIP Server connection and send request to it. Like this code block
IChannelService channelService = agent.EntrepriseService.Resolve<IChannelService>("channelService");
IClientChannel tServerChannel = channelService.ListChannels<Genesyslab.Platform.Voice.Protocols.TServerProtocol>().FirstOrDefault();
channelService.RegisterEvents(tServerChannel, new Action<Genesyslab.Enterprise.Model.Channel.IClientChannel>(ChannelEvent));
TServerProtocol tServerProtocol = tServerChannel.Protocol as TServerProtocol;
After this you have current connection on tserverPorotocol object. Then you can send a request to SIP Server.
Like this:
Genesyslab.Platform.Voice.Protocols.TServer.Requests.Voice.RequestReleaseCall releaseCall = Genesyslab.Platform.Voice.Protocols.TServer.Requests.Voice.RequestReleaseCall.Create();
releaseCall.ThisDN = "7000"; //(for example)(you can retrieve agent's DN from agent object)
releaseCall.ConnID = interaction.ConnectionId // you can retrieve from interactionhandler event.
tServerProtocol.Send(releaseCall);
//or tServerProtocol.Request(releaseCall); for async request. request return a ack message from the server.
I tried to explain basics. I hope its helpful. If you got a question about sip or etc. please let me know.
I have a small problem, I am working on an aggregation application that is collecting messages from pages in realtime.
This is working fine, but I get the same message on every call and then filter out the messages that I have already seen manually.
This means that a large amount of data is being transferred every time I make a call to the graph api.
Is there a way to limit the message as messages since this message id?
currently using the c# Facebook SDK
var fb = new FacebookClient("access_token");
dynamic parameters = new ExpandoObject();
parameters.limit = _facebookMessagesToRetrieveAtATime.ToString(CultureInfo.InvariantCulture);
//Want to add a new param here to say messages since this id.
var facebookUrl = String.Format("{0}/feed", "Page ID");
dynamic resp = fb.Get(facebookUrl, parameters);
Thanks in advance.
You can use the since url parameter in your calls, as described at https://developers.facebook.com/docs/graph-api/using-graph-api/v2.1#paging
This would make it necessary that you store somewhere in your application the timestamp when you last requested the respective feed
This would yield in
var facebookUrl = String.Format("{0}/feed?since={last_update_timestamp}", "Page ID");
where {last_update_timestamp} is the timestamp (unixtime in seconds) of the last update.