AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 26.08.2011, 01:13   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
sumitsaxfactor: Browsing Folders for Files on 64-bit Server Side Implementation (Batch Run)
Источник: http://sumitsaxfactor.wordpress.com/...ion-batch-run/
==============

I am sure all of us have had a requirement where we were supposed to process a folder for specific file pattern / all file pattern and process these files.

This scenario is very prominent during integration of different applications with AX.

I scenarios where this process is run manually or on client side, we use the standard methods provided by Microsoft in WinApi class (FindFirstFile, FindNextFile, FindClose).

These methods in turn use the FindFirstFile, FindNextFile and FindClose methods defined in Kernel32 dll.

Now these methods are not provided on Server Side implementation of WinApi namely WinApiServer. But you can copy  these methods from WinApi to WinApiServer and use them as required.

These methods work fine on any 32-bit OS on both client side and server side.

But the real issue comes when you are using these methods on 64-bit systems and that too on server side.

The reason being we need some redirection that needs to be done. I will speak about this re-direction in a separate blog post as I am still working on making this work inside Ax.

But other method that I found was to use System.IO class.

Here is a sample code with proper comments to make you understand.

 

server public static void getFiles()

{

    System.IO.DirectoryInfo directoryInfo;

    System.IO.FileInfo[]    fileList;

    System.IO.FileInfo      file;

    System.Exception        e;

    System.String           moveName, fromName;

 

    int i;

    int fileCount;

    str axMoveName, axFromName;

 

    InterOpPermission   perm;

    FileIOPermission    filePerm;

    FilePath            searchFilePath;

    FileName            moveFileName;

    ;

 

    //Check if the folder exists

    filePerm = new FileIOPermission(@"\AX_InBound\", ‘r’);

    filePerm.assert();

    if (!WinApiServer::fileExists(@"\AX_InBound\", true))

    {

        throw error("Path not found");

    }

    CodeAccessPermission::revertAssert();

 

    //Check if the archive folder exists

    filePerm = new FileIOPermission(@"\AX_Archive\", ‘r’);

    filePerm.assert();

    if (!WinApiServer::fileExists(@"\AX_Archive\", true))

    {

        throw error("Archive Path not found");

    }

    CodeAccessPermission::revertAssert();

 

    //Check the permission for CLR InterOp

    perm = new InterOpPermission(InteropKind::ClrInterop);

    perm.assert();

 

    try

    {

        //Traverse to the inbound folder and search file

        searchFilePath = @"\AX_InBound\";

        directoryInfo = new System.IO.DirectoryInfo(searchFilePath);

       

        //Get list of only text files

        fileList = directoryInfo.GetFiles("*.txt");

       

        //Get the file count

        fileCount = fileList.get_Length();

       

        //One by one get each file

        for (i = 0; i < fileCount; i++)

        {

            file = fileList.GetValue(i);

 

            //.Net method returns System.String need to marshal it to AX str data type

            fromName = file.get_FullName();

            axFromName = fromName;

           

            //Display the name of the fetched file

            info(fromName);

 

            //.Net method returns System.String need to marshal it to AX str data type

            moveName = file.get_Name();

            axMoveName = moveName;

 

            //Move to archive folder

            moveFileName = @"\AX_Archive\" + axMoveName;

            file.MoveTo(moveFileName);

           

            info("File moved to " + moveFileName);

        }

    }

    catch(Exception::CLRError)

    {

        e = ClrInterOp::getLastException();

        while (e)

        {

            error(e.get_Message());

            e = e.get_InnerException();

        }

    }

    catch

    {

        error("An unknown exception has occurred");

    }

    CodeAccessPermission::revertAssert();

}





Источник: http://sumitsaxfactor.wordpress.com/...ion-batch-run/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
CRM DE LA CREME! CRM 4.0 Disaster Recovery Blog bot Dynamics CRM: Blogs 2 26.02.2016 08:23
Dynamics AX Sustained Engineering: Unable to Browse List Pages in EP when running SharePoint 2010 with Windows Server 2008 R2 (64 Bit) Blog bot DAX Blogs 0 29.12.2010 02:16
paruvella: Issues with EP tools, on 64-bit Windows server 2008. Blog bot DAX Blogs 0 03.12.2010 19:11
Microsoft Dynamics CRM Team Blog: Building a Self-Contained Virtual CRM Development Server Blog bot Dynamics CRM: Blogs 0 05.05.2009 10:05
Microsoft Dynamics CRM Team Blog: 32-bit vs. 64-bit CRM SDK Assemblies Blog bot Dynamics CRM: Blogs 0 11.09.2008 20:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 15:21.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.