public bool keepalive_ttl_internal(string ClientID, string SessionID)
        {
            if (ClientID == null || SessionID == null)
            {
                return(false);
            }

            try
            {
                var res = new APIController().callSoapQuery <TTLITradeWSDEV.isClientLoginResponseIsLoginResp>(
                    new TTLAPIRequest(
                        "isClientLogin",
                        new Dictionary <string, object>
                {
                    ["ClientID"]  = ClientID,
                    ["SessionID"] = SessionID,
                })
                    );

                //TTLITradeWSDEV.ItradeWebServicesClient soap = new TTLITradeWSDEV.ItradeWebServicesClient();
                var resp = (TTLITradeWSDEV.isClientLoginResponseIsLoginResp)res;

                if (resp.errorCode != null || resp.errorMessage != null)
                {
                    AuditLogDbContext.getInstance().createAuditLog(new AuditLog
                    {
                        is_private = true,
                        action     = "TTL INTERNAL",
                        remarks    = "FAIL KEEP ALIVE (" + ClientID + ")",
                    });
                    return(false);
                }

                AuditLogDbContext.getInstance().createAuditLog(new AuditLog
                {
                    is_private = true,
                    action     = "TTL INTERNAL",
                    remarks    = "SUCCESS KEEP ALIVE (" + ClientID + ")",
                });
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public static bool SendEmail(List <string> emailTo, string mailbody, string subject)
        {
            var useDefaultCredentials = false;
            var enableSsl             = true;
            var method = SmtpDeliveryMethod.Network;

            var smtp_skip_email = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_skip_email");

            if (smtp_skip_email != null && smtp_skip_email.Value == "1")
            {
                AuditLogDbContext.getInstance().createAuditLog(new AuditLog
                {
                    action     = "[EMAIL SKIPPED]",
                    remarks    = subject + " " + mailbody,
                    is_private = false,
                });
                return(true);
            }

            var c_from           = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_from");
            var c_userName       = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_username");
            var c_password       = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_password");
            var c_port           = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_port");
            var c_host           = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_host");
            var c_domain         = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_domain");
            var c_smtpClientHost = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_smtpClientHost");
            var c_smtpClientPort = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_smtpClientPort");
            var c_smtpSSL        = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SMTP_ssl");

            /*
             * var from = new MailAddress("*****@*****.**", "Geminis");
             * var userName = "******";
             * var password = "******";
             * var port = 587;
             * var host = "mail.geminisgroup.com";
             * var domain = "fbgemini";
             */

            var    from           = new MailAddress("*****@*****.**", "Geminis");
            var    userName       = "******";
            var    password       = "******";
            var    port           = 587;
            var    host           = "smtp.gmail.com";
            string domain         = null;
            string smtpClientHost = null;
            var    smtpClientPort = 465;
            var    smtpSSL        = 0;


            if (c_from != null && c_from.Value != null && c_from.Value != "")
            {
                from = new MailAddress(c_from.Value, "Geminis");
            }
            if (c_userName != null && c_userName.Value != null && c_userName.Value != "")
            {
                userName = c_userName.Value;
            }
            if (c_password != null && c_password.Value != null && c_password.Value != "")
            {
                password = c_password.Value;
            }
            if (c_port != null && c_port.Value != null && c_port.Value != "")
            {
                port = int.Parse(c_port.Value);
            }
            if (c_host != null && c_host.Value != null && c_host.Value != "")
            {
                host = c_host.Value;
            }
            if (c_domain != null && c_domain.Value != null && c_domain.Value != "")
            {
                domain = c_domain.Value;
            }
            if (c_smtpClientHost != null && c_smtpClientHost.Value != null && c_smtpClientHost.Value != "")
            {
                smtpClientHost = c_smtpClientHost.Value;
            }
            if (c_smtpClientPort != null && c_smtpClientPort.Value != null && c_smtpClientPort.Value != "")
            {
                smtpClientPort = int.Parse(c_smtpClientPort.Value);
            }
            if (c_smtpSSL != null && c_smtpSSL.Value != null && c_smtpSSL.Value != "")
            {
                smtpSSL = int.Parse(c_smtpSSL.Value);
            }

            if (smtpSSL == 0)
            {
                enableSsl = false;
            }
            else
            {
                enableSsl = true;
            }

            using (var mail = new MailMessage())
            {
                mail.From = from;

                foreach (string to in emailTo)
                {
                    mail.To.Add(to);
                }

                mail.Subject    = subject;
                mail.Body       = mailbody;
                mail.IsBodyHtml = true;

                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Delay |
                                                   DeliveryNotificationOptions.OnFailure |
                                                   DeliveryNotificationOptions.OnSuccess;

                SmtpClient _client = null;
                if (smtpClientHost == null)
                {
                    _client = new SmtpClient();
                }
                else
                {
                    _client = new SmtpClient(smtpClientHost, smtpClientPort);
                }

                using (var client = _client)
                {
                    client.Host                  = host;
                    client.EnableSsl             = enableSsl;
                    client.Port                  = port;
                    client.UseDefaultCredentials = useDefaultCredentials;

                    if (domain != null)
                    {
                        client.Credentials = new NetworkCredential(userName, password, domain);
                    }
                    else
                    {
                        client.Credentials = new NetworkCredential(userName, password);
                    }

                    client.DeliveryMethod = method;
                    try
                    {
                        client.Send(mail);
                    }
                    catch (Exception e)
                    {
                        AuditLogDbContext.getInstance().createAuditLog(new WebApplication2.Models.AuditLog
                        {
                            action     = "[EMAIL API TEST]",
                            remarks    = "Response Exception: " + e.Message + " " + userName + " " + port + " " + host,
                            is_private = false,
                        });
                    }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public static List <LuceneSearchData> GetAll()
        {
            List <LuceneSearchData> searchData = new List <LuceneSearchData>();
            List <ArticlePublished> items      = ArticlePublishedDbContext.getInstance().findPublishedArticlesGroupByBaseVersion("en", "trading");

            List <string> innerHTMLLinks = new List <string>();

            for (int i = 0; i < items.Count; i++)
            {
                try
                {
                    ArticlePublished article = items[i];
                    LuceneSearchData data    = new LuceneSearchData();

                    data.is_page = 0;
                    data.is_pdf  = 0;
                    data.is_doc  = 0;
                    data.is_docx = 0;

                    data.is_visitor = 0;
                    data.is_member  = 0;
                    data.is_trading = 0;

                    if (article != null &&
                        article.categoryID != null &&
                        article.categoryID.HasValue)
                    {
                        data.Id            = i;
                        data.ArticleId     = article.ArticleID;
                        data.BaseArticleId = article.BaseArticleID;
                        data.CategoryId    = article.categoryID.Value;
                        data.Url           = article.category.url;
                        data.Type          = "page";
                        data.Name          = article.Name;
                        data.Description   = article.Desc;

                        if (data.Name == null)
                        {
                            continue;
                        }

                        if (data.Description == null)
                        {
                            data.Description = "";
                        }

                        data.name_en = article.Name;
                        data.desc_en = article.Desc;

                        ArticlePublished a_zh = ArticlePublishedDbContext.getInstance().getArticlePublishedByBaseArticleID(article.BaseArticleID, "zh");
                        if (a_zh != null)
                        {
                            data.name_zh = a_zh.Name;
                            data.desc_zh = a_zh.Desc;
                        }

                        ArticlePublished a_cn = ArticlePublishedDbContext.getInstance().getArticlePublishedByBaseArticleID(article.BaseArticleID, "cn");
                        if (a_cn != null)
                        {
                            data.name_cn = a_cn.Name;
                            data.desc_cn = a_cn.Desc;
                        }

                        if (data.name_en == null)
                        {
                            data.name_en = "";
                        }

                        if (data.name_zh == null)
                        {
                            data.name_zh = "";
                        }

                        if (data.name_cn == null)
                        {
                            data.name_cn = "";
                        }

                        if (data.desc_en == null)
                        {
                            data.desc_en = "";
                        }

                        if (data.desc_zh == null)
                        {
                            data.desc_zh = "";
                        }

                        if (data.desc_cn == null)
                        {
                            data.desc_cn = "";
                        }

                        data.Description = MyRazorExtensions.Render(null, data.Description, null, true);
                        data.desc_en     = MyRazorExtensions.Render(null, data.desc_en, null, true);
                        data.desc_zh     = MyRazorExtensions.Render(null, data.desc_zh, null, true);
                        data.desc_cn     = MyRazorExtensions.Render(null, data.desc_cn, null, true);


                        data.Description = HtmlToPlainText(data.Description);
                        data.desc_en     = HtmlToPlainText(data.desc_en);
                        data.desc_zh     = HtmlToPlainText(data.desc_zh);
                        data.desc_cn     = HtmlToPlainText(data.desc_cn);


                        data.is_page = 1;

                        data.is_trading = article.category.isVisibleToTradingOnly ? 1 : 0;
                        data.is_member  = article.category.isVisibleToMembersOnly ? 1 : 0;
                        data.is_visitor = article.category.isVisibleToVisitorOnly ? 1 : 0;

                        searchData.Add(data);

                        List <string> innerLinks_en = LinkScanner.getInnerUrlsFromHTML(data.desc_en);
                        List <string> innerLinks_zh = LinkScanner.getInnerUrlsFromHTML(data.desc_zh);
                        List <string> innerLinks_cn = LinkScanner.getInnerUrlsFromHTML(data.desc_cn);

                        innerLinks_en.AddRange(innerLinks_zh.Except(innerLinks_en));
                        innerLinks_zh.AddRange(innerLinks_cn.Except(innerLinks_zh));

                        for (var m = innerLinks_en.Count - 1; m >= 0; m--)
                        {
                            string link = innerLinks_en[m];
                            if (innerHTMLLinks.Contains(link))
                            {
                                innerLinks_en.RemoveAt(m);
                            }
                        }

                        for (var m = innerLinks_en.Count - 1; m >= 0; m--)
                        {
                            string link = innerLinks_en[m];
                            string name = LinkScannerParser.getFilenameFromInnerUrl(link);
                            string ext  = LinkScannerParser.getFiletypeFromInnerUrl(link);

                            LuceneSearchData _data = new LuceneSearchData();

                            _data.ArticleId     = 0;
                            _data.BaseArticleId = 0;
                            _data.CategoryId    = 0;

                            _data.is_page = 0;
                            _data.is_pdf  = 0;
                            _data.is_doc  = 0;
                            _data.is_docx = 0;

                            if (ext == ".pdf")
                            {
                                _data.is_pdf = 1;
                            }
                            else if (ext == ".doc")
                            {
                                _data.is_doc = 1;
                            }
                            else if (ext == ".docx")
                            {
                                _data.is_docx = 1;
                            }
                            else
                            {
                                continue;
                            }

                            string desc = LinkScannerParser.getDocumentFromInnerUrl(link);

                            _data.is_visitor = data.is_visitor;
                            _data.is_member  = data.is_member;
                            _data.is_trading = data.is_trading;
                            _data.Name       = name;

                            if (name == "")
                            {
                                continue;
                            }

                            _data.name_en = "";
                            _data.name_zh = "";
                            _data.name_cn = "";

                            _data.Url         = "/ckfinder/userfiles/files/" + _data.Name;
                            _data.Type        = ext.ToUpper();
                            _data.Description = desc;

                            _data.desc_en = "";
                            _data.desc_zh = "";
                            _data.desc_cn = "";

                            searchData.Add(_data);
                        }
                    }
                }
                catch (Exception e)
                {
                    AuditLogDbContext.getInstance().createAuditLog(new AuditLog
                    {
                        action  = "Search Indexing",
                        remarks = "Exception GetAll: " + e.Message,
                    });
                }
            }

            return(searchData);
        }
        public ActionResult login(string username, string password)
        {
            try
            {
                var res = new APIController().callSoapQuery <TTLITradeWSDEV.clientLoginResponseLoginResp>(
                    new TTLAPIRequest(
                        "clientLogin",
                        new Dictionary <string, object>
                {
                    ["ChannelID"]     = "INT",
                    ["ClientID"]      = username,
                    ["Password"]      = password,
                    ["TradingAccSeq"] = "-1",
                    ["Encrypt"]       = "Y",
                })
                    );

                //TTLITradeWSDEV.ItradeWebServicesClient soap = new TTLITradeWSDEV.ItradeWebServicesClient();
                var resp = (TTLITradeWSDEV.clientLoginResponseLoginResp)res;

                if (resp.errorCode != null || resp.errorMessage != null)
                {
                    return(this.Json(BaseResponse.MakeResponse("F001", resp.errorCode, null, resp.errorMessage)));
                }



                setSession(resp);


                BaseControllerSession session = getSession();


                if (session != null)
                {
                    try
                    {
                        var isNonTradingAccField = "1";
                        if (session.hasTradingAcc)
                        {
                            isNonTradingAccField = "-1";
                        }

                        var res2 = new APIController().callSoapQuery <TTLITradeWSDEV.queryAccountDetailsResponseQueryAccountDetailsResp>(
                            new TTLAPIRequest(
                                "queryAccountDetails",
                                new Dictionary <string, object>
                        {
                            ["ClientID"]             = session.clientID,
                            ["SessionID"]            = session.sessionID,
                            ["isNonTradingAccField"] = isNonTradingAccField,
                            ["version"]   = "1",
                            ["deviceID"]  = "",
                            ["osVersion"] = "1",
                        })
                            );

                        if (res2 != null)
                        {
                            setAccSession(res2);
                        }
                    }
                    catch (Exception e)
                    {
                        AuditLogDbContext.getInstance().createAuditLog(new AuditLog
                        {
                            action  = "queryAccountDetails",
                            remarks = "failed",
                        });
                    }
                }


                /*
                 * var jsession = loginQPI(username, password, resp);
                 *
                 * if (jsession.Result != null)
                 * {
                 *  setJSession(jsession.Result);
                 * }
                 */

                var is_sso_enabled = false;
                var sso_enabled    = ConstantDbContext.getInstance().findActiveByKeyNoTracking("SSO_enabled");
                if (sso_enabled != null &&
                    sso_enabled.Value != null)
                {
                    is_sso_enabled = sso_enabled.Value == "1";
                }

                SSO_UpsertUser(is_sso_enabled);

                return(this.Json(BaseResponse.MakeResponse(resp)));
            }
            catch (Exception e)
            {
                return(this.Json(BaseResponse.MakeResponse("F001", e)));
            }
        }
Exemplo n.º 5
0
        public T callSoapQuery <T>(TTLAPIRequest form)
        {
            TTLITradeWSDEV.ItradeWebServicesClient soap = new TTLITradeWSDEV.ItradeWebServicesClient();

            TTLITradeWSDEV.requestHeaderType  reqHeader  = new TTLITradeWSDEV.requestHeaderType();
            TTLITradeWSDEV.responseHeaderType respHeader = new TTLITradeWSDEV.responseHeaderType();

            TTLITradeWSDEV.BaseRequest_CType  query    = null;
            TTLITradeWSDEV.BaseResponse_CType response = null;


            if (form.name != null)
            {
                MethodInfo      mth = soap.GetType().GetMethod(form.name);
                ParameterInfo[] pms = mth.GetParameters();

                int i = 0;
                foreach (ParameterInfo _param in pms)
                {
                    var fullName = _param.ParameterType.FullName;
                    fullName = fullName.Replace("&", "");

                    Type type = AppDomain.CurrentDomain.GetAssemblies()
                                .SelectMany(a => a.GetTypes())
                                .FirstOrDefault(t => t.FullName == fullName);

                    var obj = Activator.CreateInstance(type);

                    if (typeof(requestHeaderType).IsAssignableFrom(obj.GetType()))
                    {
                        reqHeader = (requestHeaderType)obj;
                    }
                    if (typeof(BaseRequest_CType).IsAssignableFrom(obj.GetType()))
                    {
                        query = (BaseRequest_CType)obj;
                    }
                    if (typeof(BaseResponse_CType).IsAssignableFrom(obj.GetType()))
                    {
                        response = (BaseResponse_CType)obj;
                    }
                    i++;
                }
            }

            soap.ClientCredentials.UserName.UserName = form.credentials.username;
            soap.ClientCredentials.UserName.Password = form.credentials.password;

            reqHeader.version = form.header.version;
            reqHeader.traceNo = form.header.traceNo;


            if (form.body != null)
            {
                string json = JsonConvert.SerializeObject(form.body, Formatting.None, new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                });
                query = (BaseRequest_CType)JsonConvert.DeserializeObject(json, query.GetType());
                AuditLogDbContext.getInstance().createAuditLog(new WebApplication2.Models.AuditLog
                {
                    action  = "[TTL API TEST]",
                    remarks = "1. " + form.name,
                });

                /*
                 * var keys = form.body.Keys;
                 * foreach (string key in keys)
                 * {
                 *  var val = form.body[key];
                 *  if (val != null)
                 *  {
                 *
                 *      var property = query.GetType().GetProperty(key);
                 *      if (property == null)
                 *      {
                 *          continue;
                 *      }
                 *
                 *      if (property.PropertyType == typeof(string)
                 || property.PropertyType == typeof(int)
                 || property.PropertyType == typeof(bool)
                 || property.PropertyType == typeof(decimal)
                 || property.PropertyType == typeof(float)
                 || property.PropertyType == typeof(double))
                 ||     {
                 ||         property.SetValue(query, Convert.ChangeType(val, property.PropertyType), null);
                 ||     }
                 ||     else
                 ||     {
                 ||         object ob = Newtonsoft.Json.JsonConvert.DeserializeObject<property.PropertyType>(Json Object);
                 ||         property.SetValue(query, )
                 ||     }
                 || }
                 ||}
                 */
            }

            try
            {
                MethodInfo    mth        = soap.GetType().GetMethod(form.name);
                List <object> parameters = new List <object>
                {
                    reqHeader,
                    query,
                    null
                };

                var p = parameters.ToArray();
                try
                {
                    object resp = mth.Invoke(soap, p);

                    AuditLogDbContext.getInstance().createAuditLog(new WebApplication2.Models.AuditLog
                    {
                        action     = "[TTL API TEST]",
                        remarks    = "Response: " + resp.ToString(),
                        is_private = true,
                    });

                    if (respHeader.GetType().IsAssignableFrom(resp.GetType()))
                    {
                        respHeader = (responseHeaderType)resp;
                    }

                    T res = (T)p[2];
                    return(res);
                }
                catch (Exception e)
                {
                    AuditLogDbContext.getInstance().createAuditLog(new WebApplication2.Models.AuditLog
                    {
                        action     = "[TTL API TEST]",
                        remarks    = "Response Format Parsing Error: " + e.Message + " " + form.name,
                        is_private = true,
                    });
                    throw e;
                }
            }
            catch (Exception e)
            {
                AuditLogDbContext.getInstance().createAuditLog(new WebApplication2.Models.AuditLog
                {
                    action     = "[TTL API TEST]",
                    remarks    = "Generic Error: " + e.Message + " " + form.name,
                    is_private = true,
                });
                throw e;
            }
        }