示例#1
0
        //추가
        public void InsertServiceInfo(string url, string DBName)
        {
            //서비스 정보가 들어갈 객체
            IList <ServiceInfo> OriginalData = null;

            try
            {
                //유효성 검사
                if (url == null || url == string.Empty || url == "http://")
                {
                    throw new Exception("접속할 URL을 입력하십시오");
                }
                else if (DBName == null || DBName == string.Empty)
                {
                    throw new Exception("사용할 DB의 이름 입력하십시오");
                }
                //파일이 있으면 기존 정보외의 충돌 검사
                if (File.Exists(this.infoFilePath))
                {
                    if (ServiceList == null)
                    {
                        SelectServiceInfo();
                    }
                    foreach (ServiceInfo si in this.ServiceList)
                    {
                        if (si.ServiceURL == url)
                        {
                            throw new Exception("기존의 URL과 중복됩니다.");
                        }
                        else if (si.DBName == DBName)
                        {
                            throw new Exception("입력된 데이터베이스는 이미 서비스 되고 있습니다.");
                        }
                    }
                    //기존의 입력된 내용을 바탕으로 VO객체를 다시 생성해서 거기에 데이터 입력처리
                    string originalJson = File.ReadAllText(infoFilePath, Encoding.UTF8);
                    OriginalData = JsonConvert.DeserializeObject <IList <ServiceInfo> >(originalJson);
                }
                else
                {
                    //파일이 없으면 새로 객체 만들어서 처리
                    OriginalData = new List <ServiceInfo>();
                }
                //내용 삽입
                OriginalData.Add(new ServiceInfo(url, DBName));
                //객체를 문자열(Json)으로 변환
                String jsonData = JsonConvert.SerializeObject(OriginalData);
                //파일 삭제
                File.Delete(infoFilePath);
                //파일작성
                File.AppendAllText(infoFilePath, jsonData);

                this.ServiceList = OriginalData;
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
 internal void InternalPrepareForUpdate()
 {
     OriginalData.Clear();
     foreach (var line in Data)
     {
         OriginalData.Add(line.Key, line.Value);
     }
     PrepareForUpdate();
 }
        public bool load(string file)
        {
            try
            {
                StreamReader sr = new StreamReader(file);

                string tmp = "";
                do
                {
                    tmp = sr.ReadLine();
                    OriginalData.Add(tmp);
                }while (tmp != null);

                sr.Close();
                return(true);
            }

            catch
            {
                Console.WriteLine("\nLoading error. See LoadData.cs, load().");
                return(false);
            }
        }
        public override void Load(Stream stream)
        {
            // Let the base class do the heavy lifting.
            base.Load(stream);

            foreach (var kvp in Data)
            {
                OriginalData.Add(kvp.Key, kvp.Value);
            }

            // Do decryption here, you can tap into the Data property like so:
            Data = Data?.ToDictionary(k => k.Key.ToUpperInvariant(), v => v.Value) as IDictionary <string, string>;

            if (Data == null)
            {
                return;
            }

            var toUpdate = new Dictionary <string, string>();

            foreach (var kvp in Data)
            {
                var keyAr = kvp.Key?.Split(':');
                if (keyAr == null)
                {
                    continue;
                }
                if (keyAr.Length == 0)
                {
                    continue;
                }

                var valueKey = string.Empty;
                if (keyAr.Length > 2)
                {
                    const string customSetting = "JOBSCUSTOMSETTINGS";
                    if (keyAr[0] == customSetting)
                    {
                        valueKey = $"{keyAr[1]}:{keyAr[2]}:VALUE";
                    }
                }
                if (kvp.Key == valueKey)
                {
                    continue;
                }

                var isEncrypted = Data.FirstOrDefault(kp => kp.Key.ToUpper().EndsWith("ISENCRYPTED") & kp.Value?.ToUpper() == "TRUE").Key != null;

                //var isEncrypted = keyAr.Any(v => v == "ISENCRYPTED");
                if (isEncrypted & Data.ContainsKey(valueKey))
                {
                    var encVal = Data[valueKey];
                    var decVal = Cryptography.DecryptText(encVal);
                    toUpdate.Add(valueKey, decVal);
                }
            }

            //updates
            foreach (var kvp in toUpdate)
            {
                Data[kvp.Key] = kvp.Value;
            }



            //Data["abc:password"] = MyEncryptionLibrary.Decrypt(Data["abc:password"]);

            // But you have to make your own MyEncryptionLibrary, not included here
        }