날아라김지원
article thumbnail

위 그림의 설명

윈도우에서 만들어진 dll은 com+라는곳에 등록해서 사용할 수 있다.

FCMN200은 FCMN200.asp라는 이름으로 만들어진 어플리케이션의 한 부분, 페이지이고

그안에서 FORD100.dll이라는 DLL을 구성 요소 서비스로 불러온다.

 

현재 해야하는것

 

VBS로 만들어진 32bit DLL 하나를 C# 기반의 .net 으로만든 64bit DLL로 바꿔야한다.

 

현재는 FORD100이라는 dll의 FORD100X1하나만 다른것으로 갈아끼우기 위한 작업을 하고 있다.

 

그 작업중 DLL로만들어지면 바뀌는 외부프로그램의 ID, PASSWORD, 혹은 아이피 정보들을 변경하기

 

어렵기 때문에 외부파일(txt혹은 ini)로 저장된 파일을 가져와 변수로 사용할 수 있게 해주려고한다.

 

using System;
using System.IO;

namespace HelloWorld
{
    class Program
    {
        static void MyMethod()
        {

            string ApplicationServer = 192.168.0.1
            string SystemNumber = 02
            string Client = 200
            string Language = KO
            string codepage = 8500
            string User = test
            string Password = test123

        }
        static void Main(string[] args)
        {
            MyMethod();
        }
        
    }
}

 

이런식으로 작성 할 수도 있지만 추후에 유지보수하기 힘들다고 판단, 외부파일을 읽어올 필요가 있었다.

 

이와같이 만들어진 파일에서 정보를 불러온다면 추후에 변경사항만 dll편집없이, 코드편집없이 수정할 수 있다.

 

using System;
using System.IO;

namespace HelloWorld
{
    class Program
    {
        static void MyMethod()
        {
            // code to be executed
            string[] readTextvar = File.ReadAllLines("SAPINFO.ini");  // Read the contents of the file
            Console.WriteLine("==============================");
            Console.WriteLine("SAP정보");
            string ApplicationServer = readTextvar[1].Remove(0, 18);
            string SystemNumber = readTextvar[2].Remove(0, 13);
            string Client = readTextvar[3].Remove(0, 7);
            string Language = readTextvar[4].Remove(0, 9);
            string codepage = readTextvar[5].Remove(0, 9);
            string User = readTextvar[6].Remove(0, 5);
            string Password = readTextvar[7].Remove(0, 9);
            // Output the content
            Console.WriteLine(ApplicationServer);
            Console.WriteLine(SystemNumber);
            Console.WriteLine(Client);
            Console.WriteLine(Language);
            Console.WriteLine(codepage);
            Console.WriteLine(User);
            Console.WriteLine(Password);

            Console.WriteLine("==============================");
        }
        static void Main(string[] args)
        {
            MyMethod();
        }
        
    }
}

완성된 전문이다. 가장 중요한 부분은 2가지

 

1.상단에 using System.IO; 구문을 넣어주고

 

2.파일을 한줄씩 읽어주는 string[] readTextvar = File.ReadAllLines("SAPINFO.ini"); 부분이다.

 

3.그 다음 배열에 순차적으로 저장된 정보들을 Remove를 사용해 저장해주었다.

 

더 깔끔하게 하는 방법이 있겠지만 우선 당장 필요한 상태로 완성만 시켰다.

 

차차 더 완성도 있게 만들어보자

 

- 참고한링크 -

https://www.w3schools.com/cs/cs_files.php

 

C# Files

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

https://learn.microsoft.com/ko-kr/dotnet/api/system.io.file.writealltext?view=net-7.0 

https://way-code.tistory.com/14

https://homzzang.com/b/cs-37

https://learn.microsoft.com/ko-kr/dotnet/api/system.string.trim?view=net-7.0 

https://learn.microsoft.com/ko-kr/dotnet/standard/base-types/trimming

https://blockdmask.tistory.com/361

profile

날아라김지원

@flykimjiwon

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!