示例#1
0
        /// ------------------------------------------------------------------------------------
        private static FwQueries Load(string filename)
        {
            // Find the file that contains the queries.
            var queryFile = FileLocator.GetFileDistributedWithApplication(App.ConfigFolderName, filename);
            var fwqueries = XmlSerializationHelper.DeserializeFromFile <FwQueries>(queryFile);

            if (fwqueries != null)
            {
                fwqueries.QueryFile = queryFile;
            }
            else if (ShowMsgOnFileLoadFailure)
            {
                string filePath = Utils.PrepFilePathForMsgBox(queryFile);

                var msg = LocalizationManager.GetString("Miscellaneous.Messages.DataSourceReading.LoadingSQLQueriesErrorMsg",
                                                        "The file that contains FieldWorks queries '{0}' is either missing or corrupt. " +
                                                        "Until this problem is corrected, FieldWorks data sources cannot be accessed or " +
                                                        "added as data sources.");

                App.NotifyUserOfProblem(msg, filePath);
                fwqueries = new FwQueries(true);
            }

            return(fwqueries);
        }
 /// ------------------------------------------------------------------------------------
 private void GetQueries()
 {
     if (DataSourceType == DataSourceType.FW && m_queries == null &&
         Name != null && Server != null)
     {
         m_queries = FwQueries.GetQueriesForDB(Name, Server);
         m_lastModified = DateLastModified;
     }
 }
示例#3
0
        /// ------------------------------------------------------------------------------------
        internal static FwQueries GetQueriesForDB(string dbName, string machineName)
        {
            string longNameCheckSQL = FwDBAccessInfo.LongNameCheckSQL;

            if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(longNameCheckSQL))
            {
                return(null);
            }

            FwQueries fwqueries = null;

            using (SqlConnection connection = FwDBUtils.FwConnection(dbName, machineName))
            {
                if (connection != null)
                {
                    try
                    {
                        SqlCommand command = new SqlCommand(longNameCheckSQL, connection);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            reader.Close();

                            if (s_fwLongNameQueries == null)
                            {
                                s_fwLongNameQueries = Load("FwSQLQueries.xml");
                            }

                            fwqueries = s_fwLongNameQueries;
                        }
                    }
                    catch
                    {
                        if (s_fwShortNameQueries == null)
                        {
                            s_fwShortNameQueries =
                                CheckForShortNameFile(dbName, machineName, "FwSQLQueriesShortNames.xml") ?
                                Load("FwSQLQueriesShortNames.xml") : new FwQueries(true);
                        }

                        fwqueries = s_fwShortNameQueries;
                    }

                    connection.Close();
                }
            }

            return(fwqueries);
        }