Exemple #1
0
        public string DBConnect(String CompanyId, string DataBaseType)
        {
            String      UId;
            String      provider;
            String      pass;
            String      dsource;
            String      incat;
            String      mystring;
            string      mycon = string.Empty;
            XmlDocument xmDataAccess;

            xmDataAccess = new XmlDocument();
            DataAccess_Net.DataAccess objda = new DataAccess_Net.DataAccess();

            if (!string.IsNullOrEmpty(DataBaseType))
            {
                mystring = "/ConfigParams/Company/" + CompanyId + "/" + DataBaseType;
            }
            else
            {
                mystring = "/ConfigParams/AdminDB,/ConfigParams/subagent,/ConfigParams/Log";
            }

            mystring = objda.fnDataAccess(mystring, ",");
            mystring = mystring.Replace("'", "\"");
            xmDataAccess.LoadXml(mystring);

            try
            {
                if (xmDataAccess.DocumentElement.Name != "Error")
                {
                    if (xmDataAccess.DocumentElement.HasChildNodes)
                    {
                        if (!string.IsNullOrEmpty(DataBaseType))
                        {
                            provider = xmDataAccess.DocumentElement.SelectSingleNode(DataBaseType).Attributes.GetNamedItem("Provider").InnerText;
                            UId      = xmDataAccess.DocumentElement.SelectSingleNode(DataBaseType).Attributes.GetNamedItem("UserID").InnerText;
                            pass     = xmDataAccess.DocumentElement.SelectSingleNode(DataBaseType).Attributes.GetNamedItem("Password").InnerText;
                            dsource  = xmDataAccess.DocumentElement.SelectSingleNode(DataBaseType).Attributes.GetNamedItem("DataSource").InnerText;
                            incat    = xmDataAccess.DocumentElement.SelectSingleNode(DataBaseType).Attributes.GetNamedItem("DBName").InnerText;
                        }
                        else
                        {
                            provider = xmDataAccess.DocumentElement.SelectSingleNode("AdminDB").Attributes.GetNamedItem("Provider").InnerText;
                            UId      = xmDataAccess.DocumentElement.SelectSingleNode("AdminDB").Attributes.GetNamedItem("UserID").InnerText;
                            pass     = xmDataAccess.DocumentElement.SelectSingleNode("AdminDB").Attributes.GetNamedItem("Password").InnerText;
                            dsource  = xmDataAccess.DocumentElement.SelectSingleNode("AdminDB").Attributes.GetNamedItem("DataSource").InnerText;
                            incat    = xmDataAccess.DocumentElement.SelectSingleNode("AdminDB").Attributes.GetNamedItem("DBName").InnerText;
                        }
                        mycon = "user id='" + UId + "';password='******';data source='" + dsource + "'; initial catalog='" + incat + "'";
                    }
                }
            }
            catch (Exception ex)
            {
                // log.Log("Initializeskyvantage()", Environment.NewLine + "Exception occured in DBConnect function :" + ex.StackTrace + Environment.NewLine + ex.InnerException + Environment.NewLine + ex.Message + Environment.NewLine, "Caching");
            }
            return(mycon);
        }
Exemple #2
0
        internal string Log(string MethodName_, string errorMsg_, string Searchtype)
        {
            string logpath = string.Empty;

            try
            {
                if (_WriteLogs)
                {
                    object lockIndex = new object();

                    string      filepath         = string.Empty;
                    XmlDocument xmlConfigDetails = new XmlDocument();


                    DataAccess_Net.DataAccess objfbDataAcess = new DataAccess_Net.DataAccess();
                    logpath = objfbDataAcess.fnDataAccess("ConfigParams/Log", ",");
                    xmlConfigDetails.LoadXml(logpath);

                    logpath = xmlConfigDetails.DocumentElement.SelectSingleNode("Log").Attributes["Path"].Value;

                    if (Searchtype.ToUpper() == "FATOSERVICE")
                    {
                        logpath += "BookingEngine\\" + scompid + "\\" + Searchtype + "\\";
                    }



                    FileInfo objFileInfo;
                    lock (lockIndex)
                    {
                        if (!Directory.Exists(logpath))
                        {
                            Directory.CreateDirectory(logpath);
                        }
                        filepath = logpath + "Fato_Service" + DateTime.Today.ToString("dd-MMM-yyyy") + ".log";

                        objFileInfo = new FileInfo(filepath);

                        FileStream fs;
                        if (objFileInfo.Exists)
                        {
                            if (objFileInfo.Length > 5048576)
                            {
                                filepath = logpath + strSessionID + DateTime.Today.ToString("dd-MMM-yyyy") + DateTime.Now.ToString("H-m-s") + ".log";
                                fs       = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite);
                            }
                            else
                            {
                                fs = new FileStream(filepath, FileMode.Append, FileAccess.Write);
                            }
                        }
                        else
                        {
                            fs = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite);
                        }

                        TextWriter m_streamWriter = new StreamWriter(fs);

                        if (!string.IsNullOrEmpty(errorMsg_))
                        {
                            m_streamWriter.WriteLine("      ============================================================================================================================================");
                            //m_streamWriter.WriteLine("Time           :: " + System.DateTime.Now );
                            m_streamWriter.WriteLine("      Method Name    :: " + MethodName_);
                            m_streamWriter.WriteLine(Environment.NewLine + "      " + errorMsg_);
                            //m_streamWriter.WriteLine("============================================================================================================================================");
                        }
                        else
                        {
                            m_streamWriter.WriteLine("*************************************************************************************************************************************************************************************");
                        }
                        m_streamWriter.Close();
                        m_streamWriter.Dispose();
                    }
                }
            }
            catch (Exception _ex) //if error comes in log writing
            {
                return("Error: Failed to Write Log" + _ex.Message);
                //throw new System.ApplicationException(_ex.ToString());
            }
            return(logpath);
        }