using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.Dynamics.AX.Framework.FileManagement;
using System;
using System.Collections;
using System.Collections.Generic;
Using OfficeOpenXml;
Using OfficeOpenXml.ExcelPackage;
Using OfficeOpenXml.ExcelRange;
class DXImportServiceClass extends SysOperationServiceBase
{
public void processOperation()
{
CloudBlobClient cloudBlobClient;
CloudBlobContainer cloudBlobContainer;
CloudStorageAccount cloudStorageAccount;
str vend,dim,cur,nameoffile,Name;
CloudBlobDirectory cloudBlobDirectory;
container con;
int j;
Boolean errorFlag;
Name fileNameLog;
System.Exception ex;
try
{
cloudStorageAccount = CloudStorageAccount::Parse("AccountName=dev01;AccountKey=ZecZy9WsnsqUQGJ1VrTgu+CF9MMDGsAQxim+ASt3gQwMw==;EndpointSuffix=core.windows.net;DefaultEndpointsProtocol=https;");
cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
cloudBlobContainer = cloudBlobClient.GetContainerReference("crp");
cloudBlobDirectory = cloudBlobContainer.GetDirectoryReference("Outbound/Error/");
System.Collections.IEnumerable lstEnumarable = cloudBlobDirectory.ListBlobs(false, 0, null, null);
System.Collections.IEnumerator lstEnumarator = lstEnumarable.GetEnumerator();
List filenames = new List(Types::String);
while(lstEnumarator.MoveNext())
{
IListBlobItem item = lstEnumarator.Current;
if(item is CloudBlockBlob)
{
CloudBlockBlob blob = item;
blob.FetchAttributes(null, null, null);
con = str2con(blob.name, "/");
nameoffile = conPeek(con,conlen(con));
fileNameLog = nameoffile;
System.IO.Stream memory = blob.OpenRead(null,null,null);
using(ExcelPackage package= new ExcelPackage(memory))
{
int rowCount, iterator;
package.Load(memory);
ExcelWorksheet worksheet = package.get_workbook().get_worksheets().get_Item(1);
OfficeOpenXml.ExcelRange range = worksheet.Cells;
rowCount = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row + 1;
for (iterator=2; iterator<=rowCount; iterator++)
{
Global::Info(strFmt('%1-%2',range.get_Item(iterator,1).Value, range.get_Item(iterator,2).Value));
}
}
}
if (errorFlag == true)
{
//CloudBlobDirectory sourceCloudBlobDirectory = cloudBlobContainer.GetDirectoryReference(invoiceParameters.InvoiceFilePath);
//CloudBlobDirectory destinationCloudBlobDirectory = cloudBlobContainer.GetDirectoryReference(invoiceParameters.InvoiceErrorFilePath);
//CloudBlockBlob SourceBlob = sourceCloudBlobDirectory.GetBlockBlobReference(nameoffile);
//CloudBlockBlob destinationBlob = destinationCloudBlobDirectory.GetBlockBlobReference(nameoffile);
//destinationBlob.UploadFromStream(sourceBlob.OpenRead(null,null,null),null,null,null);
//SourceBlob.Delete(0,null,null,null);
}
else if (errorFlag == false)
{
//CloudBlobDirectory sourceCloudBlobDirectory = cloudBlobContainer.GetDirectoryReference(invoiceParameters.InvoiceFilePath);
//CloudBlobDirectory destinationCloudBlobDirectory = cloudBlobContainer.GetDirectoryReference(invoiceParameters.InvoiceSuccessFilePath);
//CloudBlockBlob SourceBlob = sourceCloudBlobDirectory.GetBlockBlobReference(nameoffile);
//CloudBlockBlob destinationBlob = destinationCloudBlobDirectory.GetBlockBlobReference(nameoffile);
//destinationBlob.UploadFromStream(sourceBlob.OpenRead(null,null,null),null,null,null);
//SourceBlob.Delete(0,null,null,null);
}
}
Global::info("OperationCompleted");
}
catch
{
ex = CLRInterop::getLastException();
Global::info(strFmt("Exception message %1",ex.ToString()));
//CloudBlobDirectory sourceCloudBlobDirectory = cloudBlobContainer.GetDirectoryReference(invoiceParameters.InvoiceFilePath);
//CloudBlobDirectory destinationCloudBlobDirectory = cloudBlobContainer.GetDirectoryReference(invoiceParameters.InvoiceErrorFilePath);
//CloudBlockBlob SourceBlob = sourceCloudBlobDirectory.GetBlockBlobReference(nameoffile);
//CloudBlockBlob destinationBlob = destinationCloudBlobDirectory.GetBlockBlobReference(nameoffile);
//destinationBlob.UploadFromStream(sourceBlob.OpenRead(null,null,null),null,null,null);
//SourceBlob.Delete(0,null,null,null);
}
}
}
No comments:
Post a Comment