Skip to content

Commit

Permalink
Memory:: Garbage Collector
Browse files Browse the repository at this point in the history
  • Loading branch information
bachtiarpanjaitan committed Sep 30, 2024
1 parent a7adc41 commit 7df2ec7
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 50 deletions.
50 changes: 23 additions & 27 deletions Bepe/Controllers/PageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,44 @@
using IhandCashier.Bepe.Helpers;
using IhandCashier.Bepe.Interfaces;
using IhandCashier.Bepe.Types;
using IhandCashier.Pages.Views;

namespace IhandCashier.Bepe.Controllers
{
public class PageController : ContentView,IPageInterface
public class PageController : ContentView
{
private ContentView _contentView = new();
public Dictionary<string, MenuItemPage> SideMenus = new();
private ContentLayoutTwoColumn _layout = new();
private SideMenu sm = new();
public PageController()
{

}
public PageController() { }

public void DefineLayoutTwoColumn()
{
var sm = new SideMenu();
sm.SetMenuItems(SideMenus);
sm.ItemTapped += OnClickSideMenuItemAsync;
sm.ItemTapped += (sender, args) =>
{
Type type = Type.GetType(args.Page);
if(type != null)
{
try
{
if (_contentView != null) _contentView = null;
_layout.SetContent(null);
_contentView = (ContentView)Activator.CreateInstance(type);
_layout.SetContent(_contentView);

}
catch (TargetInvocationException ex)
{
Console.WriteLine("Cannot create layout " + ex.InnerException?.Message);
}
}
} ;
VerticalStackLayout sideMenu = sm.CreateSideMenu();
_layout.SetSideMenu(sideMenu);
Content = _layout.GenerateFrame();
}

public void OnClickSideMenuItemAsync(object obj, EventHandlerPageArgs e)
{
Type type = Type.GetType(e.Page);
if(type != null)
{
try
{
if (_contentView != null) _contentView = null;
_layout.SetContent(null);
_contentView = (ContentView)Activator.CreateInstance(type);
_layout.SetContent(_contentView);
}
catch (TargetInvocationException ex)
{
Console.WriteLine("Cannot create instance " + ex.InnerException?.Message);
}
}

}
}
}

2 changes: 2 additions & 0 deletions Bepe/Helpers/Pagination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public sealed class Pagination<T> : IDisposable
private bool _disposed = false;
private PopupManager manager = new ();

public Pagination(){}

/// <summary>
/// Mengelola Pagination data di datagrid.
/// </summary>
Expand Down
19 changes: 16 additions & 3 deletions IhandCashier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>basapadi.snk</AssemblyOriginatorKeyFile>
<Configurations>Debug;Release;Release Core</Configurations>
<Platforms>AnyCPU</Platforms>
<Platforms>AnyCPU;maccatalyst-x64</Platforms>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-maccatalyst|AnyCPU'">
Expand All @@ -61,9 +61,22 @@
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<MtouchLink>SdkOnly</MtouchLink>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|maccatalyst-x64' ">
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
<CodesignKey>Apple Development: [email protected] (53TNH3S72W)</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<Optimize>true</Optimize>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<PlatformTarget>maccatalyst-x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|maccatalyst-x64' ">
<MtouchEnableSGenConc>true</MtouchEnableSGenConc>
<CodesignKey>Apple Development: [email protected] (53TNH3S72W)</CodesignKey>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<MauiImage Remove="Resources\Images\document.png" />
Expand Down
6 changes: 2 additions & 4 deletions IhandCashier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.Build.0 = Release|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.Deploy.0 = Release|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release Core|Any CPU.ActiveCfg = Debug|Any CPU
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.ActiveCfg = Release|maccatalyst-x64
{4F2570B0-6B36-4040-8272-C9E0FBC401C5}.Release|Any CPU.Build.0 = Release|maccatalyst-x64
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release|Any CPU.Build.0 = Release|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Debug|Any CPU.ActiveCfg = Release Core|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release Core|Any CPU.ActiveCfg = Release Core|Any CPU
{D930DFC6-C684-4182-BF52-8D4614304F6D}.Release Core|Any CPU.Build.0 = Release Core|Any CPU
Expand Down
24 changes: 20 additions & 4 deletions Layouts/MainLayout.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
Expand All @@ -25,33 +26,48 @@
Padding="5,0,0,0"
Grid.Row="0"
BorderColor="#592f02"
BackgroundColor="Transparent"
Grid.Column="0">
<Label x:Name="LJamAplikasi" FontAttributes="Bold" FontSize="12" Text="0000-00-00 00:00:00" VerticalOptions="Center"/>
</Frame>

<Frame
Padding="5,0"
Margin="5,0"
Margin="5,0,0,0"
Grid.Row="0"
BorderColor="#592f02"
BackgroundColor="Transparent"
Grid.Column="1">
<Label x:Name="LogLabel" FontFamily="Consolas" FontAttributes="Bold" TextColor="DarkOrange" FontSize="12" HorizontalOptions="Start" VerticalOptions="Center"/>
<Label x:Name="LMemory" FontAttributes="Bold" FontSize="12" Text="0000-00-00 00:00:00" VerticalOptions="Center"/>
</Frame>

<Frame
Padding="5,0"
Margin="5,0,0,0"
Grid.Row="0"
BorderColor="#592f02"
BackgroundColor="Transparent"
Grid.Column="2">
<Label x:Name="LUser" Text="Unknown" FontAttributes="Bold" FontSize="12" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label x:Name="LogLabel" FontFamily="Consolas" FontAttributes="Bold" TextColor="DarkOrange" FontSize="12" HorizontalOptions="Start" VerticalOptions="Center"/>
</Frame>

<Frame
Padding="5,0"
Margin="5,0,0,0"
Grid.Row="0"
BorderColor="#592f02"
BackgroundColor="Transparent"
Grid.Column="3">
<Label x:Name="LUser" Text="Unknown" FontAttributes="Bold" FontSize="12" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>

<Frame
Padding="5,0"
Margin="5,0,0,0"
Grid.Row="0"
BorderColor="#592f02"
BackgroundColor="Transparent"
Grid.Column="4">
<Label x:Name="Copyright" FontSize="12" HorizontalOptions="Center" VerticalOptions="Center" />
</Frame>
</Grid>
Expand Down
13 changes: 12 additions & 1 deletion Layouts/MainLayout.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Globalization;
using System.Diagnostics;
using System.Globalization;
using System.Runtime;
using IhandCashier.Bepe.Components;
using IhandCashier.Bepe.Configs;
using IhandCashier.Bepe.Helpers;
Expand All @@ -22,6 +24,7 @@ public partial class MainLayout : ContentPage
public MainLayout()
{
InitializeComponent();

SetupClock();
MenuBarItems.Clear();
ListMenu = new MenuCreator().CreateMenu(MenuBarItems);
Expand Down Expand Up @@ -99,6 +102,14 @@ private void OnTimerElapsed(object sender, EventArgs e)
var date = DateTime.Now.ToString("dd MMMM yyyy", _cultureInfo);
var time = DateTime.Now.ToString("HH:mm:ss", _cultureInfo);
LJamAplikasi.Text = $"{dayOfWeek}, {date}, {time}";
long memoryUsage = GC.GetTotalMemory(false);
var memoryGc = Math.Round(memoryUsage / 1024.0 / 1024.0,2);

Process currentProcess = Process.GetCurrentProcess();
long privateMemorySize = currentProcess.PrivateMemorySize64;
var memoryCp = Math.Round(privateMemorySize / 1024.0 / 1024.0, 2);

LMemory.Text = $"GC: {memoryGc} MB, CP: {memoryCp} MB";
});
}

Expand Down
9 changes: 8 additions & 1 deletion Pages/Views/BaseView.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using IhandCashier.Bepe.Helpers;
using IhandCashier.Bepe.Types;
using IhandCashier.Core.Maui.Providers;

Expand All @@ -8,6 +9,7 @@ public class BaseView : ContentView
private static EventHandler _RefreshlickedHandlerRef;
private static EventHandler _EditClickedHandlerRef;
private static EventHandler _DeleteClickedHandlerRef;
public event EventHandler ViewDisappeared;

public static MenuFlyoutItem RefreshMenu = new() { Text = "Refresh Data"};
public static MenuFlyoutItem EditMenu = new() { Text = "Ubah Data"};
Expand Down Expand Up @@ -48,4 +50,9 @@ public class ContextMenuHandlers
public EventHandler? RefreshHandler { get; set; }
public EventHandler? EditHandler { get; set; }
public EventHandler? DeleteHandler { get; set; }
}
}

public static class PaginationCatcher<T> where T : class
{
public static Pagination<T> CurrentPagination { get; set; }
}
6 changes: 5 additions & 1 deletion Pages/Views/GridDataBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class GridDataBarang
private const string ModuleName = "Data Barang";
ProductService _service = ServiceLocator.ServiceProvider.GetService<ProductService>();
ProductDto _selectedProduct;
Pagination<ProductDto> _pagination;

public GridDataBarang()
{
Expand All @@ -36,7 +37,7 @@ public GridDataBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<ProductDto>(_service, typeof(FilterOne), typeof(FormBarang));
_pagination = new Pagination<ProductDto>(_service, typeof(FilterOne), typeof(FormBarang));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
Expand All @@ -46,9 +47,11 @@ public GridDataBarang()

DatagridProvider.AddDatagridCellHandler(OnClick,OnEditClicked);
DatagridProvider.HideLoader();
PaginationCatcher<ProductDto>.CurrentPagination = _pagination;
});
}


private void OnClick(object sender, DataGridCellTappedEventArgs dataGridCellTappedEventArgs)
{
_selectedProduct = dataGridCellTappedEventArgs.RowData as ProductDto;
Expand All @@ -64,6 +67,7 @@ private async void OnDeleteClicked(object sender, EventArgs e)
{
await _service.DeleteAsync(_selectedProduct.ToEntity());
Application.Current.MainPage.DisplayAlert("Berhasil", "Barang berhasil dihapus", "OK");
_pagination.RefreshData();
}
catch (Exception ex)
{
Expand Down
5 changes: 3 additions & 2 deletions Pages/Views/GridDataHargaBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class GridDataHargaBarang
private const string ModuleName = "Data Harga Barang";
ProductPriceService _service = ServiceLocator.ServiceProvider.GetService<ProductPriceService>();
ProductPriceDto _selectedProduct;

Pagination<ProductPriceDto> _pagination;
public GridDataHargaBarang()
{
InitializeComponent();
Expand All @@ -44,7 +44,7 @@ public GridDataHargaBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<ProductPriceDto>(_service, typeof(FilterOne));
_pagination = new Pagination<ProductPriceDto>(_service, typeof(FilterOne));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
Expand All @@ -53,6 +53,7 @@ public GridDataHargaBarang()
});
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
PaginationCatcher<ProductPriceDto>.CurrentPagination = _pagination;
});
}

Expand Down
4 changes: 3 additions & 1 deletion Pages/Views/GridDataKasir.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class GridDataKasir
private const string ModuleName = "Data Kasir";
UserService _service = ServiceLocator.ServiceProvider.GetService<UserService>();
UserDto _selectedProduct;
Pagination<UserDto> _pagination;
public GridDataKasir()
{
InitializeComponent();
Expand All @@ -36,9 +37,10 @@ public GridDataKasir()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<UserDto>(_service, typeof(FilterOne));
_pagination = new Pagination<UserDto>(_service, typeof(FilterOne));
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
PaginationCatcher<UserDto>.CurrentPagination = _pagination;
});
}

Expand Down
3 changes: 2 additions & 1 deletion Pages/Views/GridDataPelanggan.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class GridDataPelanggan
private const string ModuleName = "Data Pelanggan";
CustomerService _service = ServiceLocator.ServiceProvider.GetService<CustomerService>();
Customer _selectedProduct;
Pagination<Customer> _pagination;
public GridDataPelanggan()
{
InitializeComponent();
Expand All @@ -35,7 +36,7 @@ public GridDataPelanggan()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<Customer>(_service, typeof(FilterOne));
_pagination = new Pagination<Customer>(_service, typeof(FilterOne));
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
});
Expand Down
3 changes: 2 additions & 1 deletion Pages/Views/GridDataPemasok.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class GridDataPemasok
private const string ModuleName = "Data Pemasok";
SupplierService _service = ServiceLocator.ServiceProvider.GetService<SupplierService>();
Supplier _selectedProduct;
Pagination<Supplier> _pagination;
public GridDataPemasok()
{
InitializeComponent();
Expand All @@ -35,7 +36,7 @@ public GridDataPemasok()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<Supplier>(_service, typeof(FilterOne));
_pagination = new Pagination<Supplier>(_service, typeof(FilterOne));
DatagridProvider.AddDatagridCellHandler(OnClick);
DatagridProvider.HideLoader();
});
Expand Down
2 changes: 1 addition & 1 deletion Pages/Views/GridDataSatuanBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GridDataSatuanBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<UnitDto>(_service, typeof(FilterOne), typeof(FormSatuanBarang));
_pagination = new Pagination<UnitDto>(_service, typeof(FilterOne), typeof(FormSatuanBarang));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
Expand Down
4 changes: 3 additions & 1 deletion Pages/Views/GridDataSatuanDasarBarang.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed partial class GridDataSatuanDasarBarang
private const string ModuleName = "Data Satuan Dasar Barang";
BasicUnitService _service = ServiceLocator.ServiceProvider.GetService<BasicUnitService>();
BasicUnitDto _selected;
Pagination<BasicUnitDto> _pagination;
public GridDataSatuanDasarBarang()
{
InitializeComponent();
Expand All @@ -35,7 +36,7 @@ public GridDataSatuanDasarBarang()
DatagridProvider.ShowLoader();
Device.BeginInvokeOnMainThread(() =>
{
using var _pagination = new Pagination<BasicUnitDto>(_service, typeof(FilterOne), typeof(FormSatuanDasarBarang));
_pagination = new Pagination<BasicUnitDto>(_service, typeof(FilterOne), typeof(FormSatuanDasarBarang));
SetContextMenuHandler(ContextMenu,new ContextMenuHandlers
{
DeleteHandler = OnDeleteClicked,
Expand All @@ -56,6 +57,7 @@ private async void OnDeleteClicked(object sender, EventArgs e)
{
await _service.DeleteAsync(_selected.ToEntity());
Application.Current.MainPage.DisplayAlert("Berhasil", "Satuan dasar berhasil dihapus", "OK");
_pagination.RefreshData();
}
catch (Exception ex)
{
Expand Down
Loading

0 comments on commit 7df2ec7

Please sign in to comment.