Beispiel #1
0
        public static DataConnectorsDTO ConvertTableToDTO(tblConnector objDbtbl)
        {
            DataConnectorsDTO objDataConnectorDTO = new DataConnectorsDTO();

            objDataConnectorDTO.ConnectorCredential.ServerUserName = StringEncryDecry.Decrypt(objDbtbl.User_Name, objDbtbl.SessionID);
            objDataConnectorDTO.ConnectorCredential.ServerPassword = StringEncryDecry.Decrypt(objDbtbl.Password, objDbtbl.SessionID);
            objDataConnectorDTO.ConnectorCredential.ServerOrIP     = StringEncryDecry.Decrypt(objDbtbl.Server_Name, objDbtbl.SessionID);
            objDataConnectorDTO.ConnectorCredential.PortNumber     = objDbtbl.Port_Number;
            objDataConnectorDTO.NameofConnection = DescriptionConvert.DescriptionConvertDTOToTbl(objDbtbl.tblDescription);
            objDataConnectorDTO.ID = objDbtbl.ID;

            if (Enum.IsDefined(typeof(DataSouceConnectionType), objDbtbl.Data_Connector_Connection_Type))
            {
                objDataConnectorDTO.DataConnectorConnectionType = (DataSouceConnectionType)Enum.Parse(typeof(DataSouceConnectionType), objDbtbl.Data_Connector_Connection_Type);
                switch ((DataSouceConnectionType)Enum.Parse(typeof(DataSouceConnectionType), objDbtbl.Data_Connector_Connection_Type))
                {
                case DataSouceConnectionType.Database:
                    objDataConnectorDTO.objConnectionDatabaseDTO = new ConnectionDataBaseDTO();
                    objDataConnectorDTO.objConnectionDatabaseDTO.strDatabaseName = objDbtbl.Database_Name;
                    break;

                case DataSouceConnectionType.API:
                    objDataConnectorDTO.objConnectionAPIDTO = new ConnectionAPIDTO();
                    throw new NotImplementedException();

                case DataSouceConnectionType.FTP:
                    objDataConnectorDTO.objConnectionFTPDTO = new ConnectionFTPDTO();
                    objDataConnectorDTO.objConnectionFTPDTO.DefaultFolder = objDbtbl.Default_Path;

                    FTPMode enumFTPMode;
                    if (Enum.TryParse(objDbtbl.FTP_Mode, out enumFTPMode))
                    {
                        objDataConnectorDTO.objConnectionFTPDTO.Mode = enumFTPMode;
                    }
                    else
                    {
                        throw new Exception(string.Format(Resources.FTPModeTypeInvalid + "- {0}" + objDbtbl.tblDescription.tblLanguageDescriptions.FirstOrDefault().Short_Desription));
                    }
                    break;

                default:
                    throw new Exception(string.Format(Resources.DataSouceConnectionTypeInvalid + "- {0}" + objDbtbl.tblDescription.tblLanguageDescriptions.FirstOrDefault().Short_Desription));
                }
            }
            else
            {
                throw new DataConnectorExcetion(Resources.DataSouceConnectionTypeInvalid);
                // Handle values not in enum here if needed
            }
            return(objDataConnectorDTO);
        }
Beispiel #2
0
        public static void ConvertDTOtoTable(DataConnectorsDTO objConnectorDTO, ref tblConnector objConnector)
        {
            if (objConnector == null)
            {
                objConnector = new tblConnector();
            }

            objConnector.Data_Connector_Connection_Type = objConnectorDTO.DataConnectorConnectionType.ToString();


            if (objConnectorDTO.DataConnectorConnectionType == DataSouceConnectionType.Database)
            {
                objConnector.Database_Name = objConnectorDTO.objConnectionDatabaseDTO.strDatabaseName;
            }
            else if (objConnectorDTO.DataConnectorConnectionType == DataSouceConnectionType.API)
            {
                throw new NotImplementedException();
            }
            else if (objConnectorDTO.DataConnectorConnectionType == DataSouceConnectionType.FTP)
            {
                objConnector.Default_Path = objConnectorDTO.objConnectionFTPDTO.DefaultFolder;
                objConnector.FTP_Mode     = objConnectorDTO.objConnectionFTPDTO.Mode.ToString();
            }
            else
            {
                throw new DataConnectorExcetion(Resources.DataSouceConnectionTypeInvalid);
            }



            objConnector.ID          = objConnectorDTO.ID;
            objConnector.User_Name   = StringEncryDecry.Encrypt(objConnectorDTO.ConnectorCredential.ServerUserName, objConnectorDTO.SessionId);
            objConnector.Password    = StringEncryDecry.Encrypt(objConnectorDTO.ConnectorCredential.ServerPassword, objConnectorDTO.SessionId);
            objConnector.Server_Name = StringEncryDecry.Encrypt(objConnectorDTO.ConnectorCredential.ServerOrIP, objConnectorDTO.SessionId);
            objConnector.Port_Number = objConnectorDTO.ConnectorCredential.PortNumber;
            objConnector.SessionID   = objConnectorDTO.SessionId;

            //if (objConnector.tblDescription == null)
            //    objConnector.tblDescription = new tblDescription();

            tblDescription objtblDescription = objConnector.tblDescription;

            DescriptionConvert.DescriptionConvertDTOToTbl(objConnectorDTO.NameofConnection, ref objtblDescription);
            objConnector.tblDescription = objtblDescription;
        }