Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Van Hoesen jvanhoesen

View GitHub Profile
@jvanhoesen
jvanhoesen / Project.xml
Created Apr 13, 2021
Customization Project XML
View Project.xml
<Sql TableName="Table1" TableSchemaXml="#CDATA">
<CDATA name="TableSchemaXml"><![CDATA[<table name="Table1">
<col name="Field1" type="Int" default="Zero" />
<col name="Field2" type="NVarChar(10)" />
<index name="PK_Table1" clustered="true" primary="true" unique="true">
<col name="Field1" />
<col name="Field2" />
</index>
</table>]]></CDATA>
</Sql>
@jvanhoesen
jvanhoesen / SelectRecords.cs
Created Jun 2, 2021
Selects DACs from the database including Extension fields
View SelectRecords.cs
public static IEnumerable<TNode> SelectRecords(params PXDataField[] restricts)
{
//Retrieves table structure for specified TNode
TableHeader tableStructure = PXDatabase.GetTableStructure(typeof(TNode).Name);
//Should be null if there's no Table, IE if you're using a Synthetic DAC
if (tableStructure != null)
{
List<PXDataField> parameters = new List<PXDataField>();
IEnumerable<PXDataRecord> selectDel = null;
@jvanhoesen
jvanhoesen / GetExtensions.cs
Created Jun 2, 2021
Retrieves slot of type PXCacheExtensionCollection
View GetExtensions.cs
public static PXCacheExtension[] GetExtensions(TNode row)
{
object pxCacheExtensionCollection = AAReflectionHelper.InvokeMethod(PXCacheExtensionCollectionType, null, "GetSlot", PXCacheExtensionCollectionType, new Type[0], new object[] { true });
object syncRoot = ((ICollection)pxCacheExtensionCollection).SyncRoot;
PXCacheExtension[] extensions;
IDictionary<IBqlTable, PXCacheExtension[]> dict = pxCacheExtensionCollection as IDictionary<IBqlTable, PXCacheExtension[]>;
lock (syncRoot)
{
@jvanhoesen
jvanhoesen / AAInventoryItemCache.cs
Created Jun 2, 2021
Updated IPrefetchable implementation utilizing AACache
View AAInventoryItemCache.cs
internal sealed class AAInventoryItemCache : IPrefetchable
{
private Dictionary<int, InventoryItem> _InventoryItems = new Dictionary<int, InventoryItem>();
public void Prefetch()
{
_InventoryItems.Clear();
foreach (InventoryItem item in AACache<InventoryItem>.SelectRecords())
{
@jvanhoesen
jvanhoesen / Properties.cs
Last active Jun 2, 2021
Property declaration of AACache
View Properties.cs
private static CacheStaticInfo _staticInfo;
private static Type _pXCacheExtensionCollectionType;
protected static CacheStaticInfo StaticInfo
{
get
{
if (_staticInfo == null)
{
@jvanhoesen
jvanhoesen / Prefetch.cs
Created Jun 2, 2021
Prefetch default implementation vs advanced implementation
View Prefetch.cs
//Default implementation
public void Prefetch()
{
_InventoryItems.Clear();
foreach (InventoryItem item in PXDatabase.SelectRecords<InventoryItem>())
{
_InventoryItems[item.InventoryID.Value] = item;
}
}
View ZipArchiveCreate.cs
using (MemoryStream zipStream = new MemoryStream())
{
zipStream.Seek(0, SeekOrigin.Begin);
//2nd Parameter determines if .Zip is read only
using (ZipArchive zip = ZipArchive.CreateFrom(zipStream, false))
{
//Read or write data
}
}
@jvanhoesen
jvanhoesen / FileAddition.cs
Created Feb 2, 2022
Addition of file to created .Zip archive
View FileAddition.cs
using (ZipArchive zip = ZipArchive.CreateFrom(zipStream, false))
{
using (MemoryStream fileStream = new MemoryStream())
{
fileStream.Seek(0, SeekOrigin.Begin);
file.Write(fileStream);
fileStream.Seek(0, SeekOrigin.Begin);
@jvanhoesen
jvanhoesen / ZipArchiveOpen.cs
Created Mar 28, 2022
Open existing .Zip file
View ZipArchiveOpen.cs
//Retrieving .ZIP file attached to Acumatica document
PX.SM.FileInfo fileInfo = uploadFileMaint.GetFile(zipFile);
if(fileInfo != null)
{
//Create a new memory stream from .ZIP file data
using (MemoryStream stream = new MemoryStream(fileInfo.BinData))
{
//Create new instance of ZipArchive to interact with .ZIP file
using (ZipArchive zip = ZipArchive.CreateFrom(stream, true))
{
@jvanhoesen
jvanhoesen / ZipArchiveIterate.cs
Created Mar 28, 2022
Iterate through file names in Archive
View ZipArchiveIterate.cs
//Iterate through all files and retrieve each files ItemInfo containing it's name
foreach (ZipArchive.ItemInfo info in zip.GetFiles())
{
//Use file name to retrieve file from .Zip Archive
}