I did so that only logged in users can go after clicking the button. When I'm not logged in, he throws an exception that authentication is missing. I tried this way but still throws an exception. Sorry for my english.
private async void OnMyRoutesClicked(object sender, EventArgs e)
{
try
{
await Navigation.PushAsync(new MyRoutesPage());
}
catch(Exception xde)
{
await DisplayAlert("Uwaga!", "Nie masz odpowiednich uprawnień na kreatora! Skontaktuj się z administratorem", "Anuluj");
}
}
Related
I have this code:
async void openPage(object sender, EventArgs e)
{
await Navigation.PushAsync(new CFSPage());
// some code here that gets executed only after CFSPage is closed
}
What I would like to do is to only execute the code after the CFS page has returned.
Is there some way that I can do this?
What about using OnDisappearing() in the CFSPage?
You could pass a reference from the pushing page to CFSPage and the react on the disappearing of the pushed page.
async void openPage(object sender, EventArgs e)
{
await Navigation.PushAsync(new CFSPage(this));
}
On CFSPage:
protected override void OnDisappearing()
{
base.OnDisappearing();
this.ActionsOnPushedPageDisappears();
}
Is there any possible way to record an audio and upload to a server using xamarin forms.
The best result I got after searching was this
https://github.com/HoussemDellai/UploadFileToServer
The library used in the solution supports only Image and Video.
Thanks in advance
Is there any possible way to record an audio and upload to a server using xamarin forms.
There are many ways realizing this feature. For recording an audio within Xamarin.Forms, you could use Plugin.AudioRecorder to realize. Fore more you could refer the following code.
private AudioRecorderService _recoder;
protected override void OnAppearing()
{
_recoder = new AudioRecorderService
{
StopRecordingOnSilence = true,
StopRecordingAfterTimeout = true,
AudioSilenceTimeout = TimeSpan.FromSeconds(60)
};
_recoder.AudioInputReceived += _recoder_AudioInputReceived;
}
private void _recoder_AudioInputReceived(object sender, string e)
{
// do some stuff
}
private async void Button_Clicked(object sender, EventArgs e)
{
await RecodAudio();
}
private async Task RecodAudio()
{
try
{
if (!_recoder.IsRecording)
{
await _recoder.StartRecording();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
private async void StopButton_Clicked(object sender, EventArgs e)
{
if (_recoder.IsRecording)
{
await _recoder.StopRecording();
}
}
For uploading file, you could use the UploadFileToServer that mentioned in your case. And you will get the audio file path in the AudioInputReceived event args.
private void _recoder_AudioInputReceived(object sender, string e)
{
var path = e;
}
I have a question regarding event listener. We have a event listener which listen to delete node event and perform some activity say "send email".
While code review i found this, although this code is working fine i am not convinced with the session being handled here :
#Activate
protected void activate(ComponentContext context) {
try{
final String path="/content/dam/";
Session session = repository.loginAdministrative(repository.getDefaultWorkspace());
observationManager = session.getWorkspace().getObservationManager();
observationManager.addEventListener(this, Event.PROPERTY_REMOVED, path, true, null, null, true);
checkOutProperty = OsgiUtil.toString(context.getProperties()
.get(ASSET_LOCK_PROPNAME_UPDATE), ASSET_LOCK_PROPNAME_DEFAULT);
if (session != null && session.isLive()) {
session.save();
}
} catch (RepositoryException e) {
if(LOG.isErrorEnabled()){
LOG.error("Error Occured in activate method of Property Removed Listener class:" + e.getMessage());
}
}catch (Exception e) {
if(LOG.isErrorEnabled()){
LOG.error("Error Occured in activate method of Property Removed Listener class:"+e.getMessage());
}
}
}
#Deactivate
protected void deactivate(ComponentContext componentContext) {
try {
if (observationManager != null) {
observationManager.removeEventListener(this);
}
} catch (RepositoryException e) {
if(LOG.isErrorEnabled()){
LOG.error("Error Occured " + e);
}
} catch (Exception e) {
if(LOG.isErrorEnabled()){
LOG.error(e.getMessage());
}
}
}
Questions:
Best practice would be to create session object private to this class and should be logout in deactivate method?
Once an event is added in Observation Manager, do we really need session object? I was expecting if we should logout from session there.
EventListener are a bit cumbersome here. I fought many battles with JCR Sessions and Sling ResourceResolvers within them. The problem is, you need to keep the Session active as long as the Event Listener is active. So the only thing missing in your code is a logout on deactivate.
I created an AbstractEventListener which takes care of this and provides the following two methods and has two private members:
private Session session;
private ObservationManager observationManager;
protected void addEventListener(final EventListener eventListener,
final int eventTypes, final String path, final String[] nodeTypes) {
try {
session = getRepositorySession();
observationManager = session.getWorkspace().getObservationManager();
observationManager.addEventListener(eventListener, eventTypes,
path, true, null, nodeTypes, true);
} catch (RepositoryException e) {
LOGGER.error("Repository error while registering observation: ", e);
}
}
protected void removeEventListener(final EventListener eventListener) {
if (observationManager != null) {
try {
observationManager.removeEventListener(eventListener);
} catch (RepositoryException e) {
LOGGER.error(
"Repository error while unregistering observation: ", e);
} finally {
logoutSession(session);
}
}
}
And then in the actual EventListener I just call them:
protected void activate(ComponentContext context) {
addEventListener(this, Event.PROPERTY_ADDED| Event.PROPERTY_CHANGED, "/content/mysite", null);
}
}
protected void deactivate(ComponentContext componentContext) {
removeEventListener(this);
}
I'm getting "The GridView 'grdFiles' fired event PageIndexChanging which wasn't handled." even if I've added the event handler:
protected void grdFiles_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GetFiles();
grdFiles.PageIndex = e.NewPageIndex;
grdFiles.DataBind();
}
Any ideas?
Try this code. You need to declare a method on your code behind that handles the PageIndexChanging event.
protected void grdFiles_PageIndexChanging (object sender, GridViewPageEventArgs e)
{
grdFiles.PageIndex = e.NewPageIndex;
bindGridView()
}
the method bindGridView() is
private void bindGridView()
{
grdFiles.DataSource=.....;
grdFiles.DataBind();
}
I'm new in WP7, and I am trying to play sounds with a MediaElement when I press a button.
Its works, but unfortunately I get "Operation not permitted on IsolatedStorageFileStream" Exception when I press the button repeatedly, before the sound begins. How can I avoid that?
The Play method:
public void Play(string filename)
{
try
{
mediaElement.Stop();
mediaElement.ClearValue(MediaElement.SourceProperty);
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = isf.OpenFile(#"shared\transfers\" + filename, FileMode.Open))
{
mediaElement.SetSource(fileStream);
mediaElement.IsMuted = false;
mediaElement.Volume = 1.0;
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
Event handlers:
void me_MediaOpened(object sender, RoutedEventArgs e)
{
mediaElement.Play();
}
void me_MediaEnded(object sender, RoutedEventArgs e)
{
mediaElement.ClearValue(MediaElement.SourceProperty);
}
If you'd like for the user to be allowed to click the play button only once. One way would be.
public bool IsPlaying = false;
void me_MediaOpened(object sender, RoutedEventArgs e)
{
if(!IsPlaying){
mediaElement.Play();
IsPlaying = true;
}
}
void me_MediaEnded(object sender, RoutedEventArgs e)
{
if(IsPlaying){
mediaElement.ClearValue(MediaElement.SourceProperty);
IsPlaying = false;
}
}
Loading the filestream to a memorystream, before playing should make it more flexible, if you're dealing with low size streams.