Skip to content

Commit

Permalink
-Removido algumas variaveis estaticas do OutlookAPI
Browse files Browse the repository at this point in the history
-Tratamento de lixo de memória em CarregaContatos, Tela_Contatos e MainPage.
-OptionBoxes com 90% de visibilidade
  • Loading branch information
lucas-zimerman committed Jul 11, 2017
1 parent 8e59ecc commit ab878fc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 54 deletions.
43 changes: 13 additions & 30 deletions 9Contatos/API/Outlook/OutlookAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ internal class ODataResponse<T>
class OutlookAPI
{
// The Client ID is used by the application to uniquely identify itself to the v2.0 authentication endpoint.
public static string[] Scopes = { "https://graph.microsoft.com/Contacts.ReadWrite" };
public static string TokenForUser = null;
public static DateTimeOffset Expiration;
public static ApplicationDataContainer _settings = ApplicationData.Current.RoamingSettings;
static string clientId = App.Current.Resources["ida:ClientID"].ToString();
public static PublicClientApplication IdentityClientApp = new PublicClientApplication(clientId);
// public static ApplicationDataContainer _settings = ApplicationData.Current.RoamingSettings;



/// <summary>
Expand All @@ -51,35 +49,20 @@ public static async Task<string> GetTokenForUserAsync()
/*
* Se já temos o Token então não precisamos checa-lo.
*/
// return TokenForUser;
// return TokenForUser;
}
else
{
AuthenticationResult authResult;
try
{
authResult = await IdentityClientApp.AcquireTokenSilentAsync(Scopes);
TokenForUser = authResult.Token;
}

catch (Exception)
{
if (TokenForUser == null || Expiration <= DateTimeOffset.UtcNow.AddMinutes(5))
{
try
{
authResult = await IdentityClientApp.AcquireTokenAsync(Scopes);
TokenForUser = authResult.Token;
Expiration = authResult.ExpiresOn;

}
catch (Microsoft.Identity.Client.MsalException)
{
TokenForUser = null;
}
}
}
// return TokenForUser;
//Adquire o Token
string[] Scopes = { "https://graph.microsoft.com/Contacts.ReadWrite" };
string clientId = App.Current.Resources["ida:ClientID"].ToString();
PublicClientApplication IdentityClientApp = new PublicClientApplication(clientId);
AuthenticationResult authResult = await IdentityClientApp.AcquireTokenAsync(Scopes);
TokenForUser = authResult.Token;
Expiration = authResult.ExpiresOn;
authResult = null;
IdentityClientApp = null;
clientId = null;
}
return TokenForUser;
}
Expand Down
4 changes: 2 additions & 2 deletions 9Contatos/Contato/CarregaContatos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ private static async Task<bool> Carrega_OutlookAPI()
{
Saida = false;
}


//não precisamos mais dos contatos do outlook
Globais.Outlook_contatos.Clear();
return Saida;
}

Expand Down
1 change: 0 additions & 1 deletion 9Contatos/Interface/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ private async void bt_arrumar(object sender, TappedRoutedEventArgs e)
pergunta.ShowAsync();
}
break;

}
}

Expand Down
2 changes: 1 addition & 1 deletion 9Contatos/Interface/OptionBox_Filtra_Contato.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d"
Title="O que deseja visualizar?"
PrimaryButtonText="Filtrar"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick_1" VerticalAlignment="Top" MaxHeight="456">
PrimaryButtonClick="ContentDialog_PrimaryButtonClick_1" VerticalAlignment="Top" MaxHeight="456" Opacity="0.9">

<Grid Height="302">
<Grid.ColumnDefinitions>
Expand Down
2 changes: 1 addition & 1 deletion 9Contatos/Interface/OptionBox_FormatacaoContato.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mc:Ignorable="d"
Title="Formatação dos Contatos"
PrimaryButtonText="Formatar"
PrimaryButtonClick="Botao_Formatar_Click" Height="644" MinWidth="320" MinHeight="200" MaxWidth="316" VerticalAlignment="Top" Width="444" MaxHeight="500" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch" SecondaryButtonText="" Closing="ContentDialog_Closing">
PrimaryButtonClick="Botao_Formatar_Click" Height="644" MinWidth="320" MinHeight="200" MaxWidth="316" VerticalAlignment="Top" Width="444" MaxHeight="500" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch" SecondaryButtonText="" Closing="ContentDialog_Closing" Opacity="0.9">

<Grid Width="270" Height="267" HorizontalAlignment="Center" VerticalAlignment="Top" Opacity="0.9">
<Grid.RowDefinitions>
Expand Down
36 changes: 17 additions & 19 deletions 9Contatos/Interface/Tela_Contatos.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,36 +299,21 @@ private void AtualizaLista()

private async void Bt_Salvar_Click(object sender, RoutedEventArgs e)
{
FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
switch (Globais.api_usada)
{
case QualAPI.PeopleAPI:
Salvar_TextoFlyout.Text = "Salvando contatos temporários, favor não apagar" + Environment.NewLine + "seus contatos da agenda.";
break;
case QualAPI.PeopleAPI_COM_Alteracao:
break;
case QualAPI.OutlookAPI:
Salvar_TextoFlyout.Text = "Aguarde um momento pois esse método de " + Environment.NewLine + "atualização de contatos demora um pouco.";
break;
}
bool Output = await SalvaContatos.Salvar();
if (Output == true)
{
/*GC*/
LimpaContatos();
Frame.GoBack();
}

}

private void Bt_Cancelar_Click(object sender, RoutedEventArgs e)
{
/*GC*/
LimpaContatos();
// Botar popup confirmando
ListadeContatos.Clear();
if (ListaContatosView != null)
{
ListaContatosView.ItemsSource = null;
}
ListaContatosView = null;

Globais.contatos.Clear();
Frame.GoBack();
e = null;
Expand Down Expand Up @@ -357,5 +342,18 @@ private async void Bt_Ajuda_Click(object sender, RoutedEventArgs e)
await dialog.ShowAsync();
e = null;
}

private void LimpaContatos()
{
Globais.contatos.Clear();
ListadeContatos.Clear();
if (ListaContatosView != null)
{
ListaContatosView.ItemsSource = null;
}
ListaContatosView = null;


}
}
}

0 comments on commit ab878fc

Please sign in to comment.