示例#1
0
 private static StringsHelper GetLoader()
 {
     if (loader == null)
     {
         StringsHelper sr = new StringsHelper();
         Interlocked.CompareExchange(ref loader, sr, null);
     }
     return(loader);
 }
示例#2
0
        static internal OperationAbortedException Aborted(Exception inner)
        {
            OperationAbortedException e;

            if (inner == null)
            {
                e = new OperationAbortedException(StringsHelper.GetString(Strings.ADP_OperationAborted), null);
            }
            else
            {
                e = new OperationAbortedException(StringsHelper.GetString(Strings.ADP_OperationAbortedExceptionMessage), inner);
            }
            ADP.TraceExceptionAsReturnValue(e);
            return(e);
        }
        public static string GetResourceString(string res)
        {
            StringsHelper sys = GetLoader();

            if (sys is null)
            {
                return(null);
            }

            // If "res" is a resource id, temp will not be null, "res" will contain the retrieved resource string.
            // If "res" is not a resource id, temp will be null.
            string temp = sys._resources.GetString(res, StringsHelper.Culture);

            return(temp ?? res);
        }
示例#4
0
        const int const_ErrorMessageBufferSize          = 1024; // Buffer size for Local DB error message, according to Serverless team, 1K will be enough for all messages


        internal static string GetLocalDBMessage(int hrCode)
        {
            Debug.Assert(hrCode < 0, "HRCode does not indicate error");
            try
            {
                StringBuilder buffer = new StringBuilder((int)const_ErrorMessageBufferSize);
                UInt32        len    = (UInt32)buffer.Capacity;


                // First try for current culture
                int hResult = LocalDBFormatMessage(hrLocalDB: hrCode, dwFlags: const_LOCALDB_TRUNCATE_ERR_MESSAGE, dwLanguageId: (UInt32)CultureInfo.CurrentCulture.LCID,
                                                   buffer: buffer, buflen: ref len);
                if (hResult >= 0)
                {
                    return(buffer.ToString());
                }
                else
                {
                    // Message is not available for current culture, try default
                    buffer  = new StringBuilder((int)const_ErrorMessageBufferSize);
                    len     = (UInt32)buffer.Capacity;
                    hResult = LocalDBFormatMessage(hrLocalDB: hrCode, dwFlags: const_LOCALDB_TRUNCATE_ERR_MESSAGE, dwLanguageId: 0 /* thread locale with fallback to English */,
                                                   buffer: buffer, buflen: ref len);
                    if (hResult >= 0)
                    {
                        return(buffer.ToString());
                    }
                    else
                    {
                        return(string.Format(CultureInfo.CurrentCulture, "{0} (0x{1:X}).", StringsHelper.GetString("LocalDB_UnobtainableMessage"), hResult));
                    }
                }
            }
            catch (SqlException exc)
            {
                return(string.Format(CultureInfo.CurrentCulture, "{0} ({1}).", StringsHelper.GetString("LocalDB_UnobtainableMessage"), exc.Message));
            }
        }
示例#5
0
        internal static void CreateLocalDBInstance(string instance)
        {
            DemandLocalDBPermissions();
            if (s_configurableInstances == null)
            {
                // load list of instances from configuration, mark them as not created
                bool lockTaken = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    Monitor.Enter(s_configLock, ref lockTaken);
                    if (s_configurableInstances == null)
                    {
                        Dictionary <string, InstanceInfo> tempConfigurableInstances = new Dictionary <string, InstanceInfo>(StringComparer.OrdinalIgnoreCase);
                        object section = PrivilegedConfigurationManager.GetSection("system.data.localdb");
                        if (section != null) // if no section just skip creation
                        {
                            // validate section type
                            LocalDBConfigurationSection configSection = section as LocalDBConfigurationSection;
                            if (configSection == null)
                            {
                                throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_BadConfigSectionType"));
                            }
                            foreach (LocalDBInstanceElement confElement in configSection.LocalDbInstances)
                            {
                                Debug.Assert(confElement.Name != null && confElement.Version != null, "Both name and version should not be null");
                                tempConfigurableInstances.Add(confElement.Name.Trim(), new InstanceInfo(confElement.Version.Trim()));
                            }
                        }
                        else
                        {
                            SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> No system.data.localdb section found in configuration");
                        }
                        s_configurableInstances = tempConfigurableInstances;
                    }
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit(s_configLock);
                    }
                }
            }

            InstanceInfo instanceInfo = null;

            if (!s_configurableInstances.TryGetValue(instance, out instanceInfo))
            {
                return; // instance name was not in the config
            }
            if (instanceInfo.created)
            {
                return; // instance has already been created
            }
            Debug.Assert(!instance.Contains("\0"), "Instance name should contain embedded nulls");

            if (instanceInfo.version.Contains("\0"))
            {
                throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_InvalidVersion"), instance: instance);
            }

            // LocalDBCreateInstance is thread- and cross-process safe method, it is OK to call from two threads simultaneously
            int hr = LocalDBCreateInstance(instanceInfo.version, instance, flags: 0);

            SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> Starting creation of instance {0} version {1}", instance, instanceInfo.version);

            if (hr < 0)
            {
                throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_CreateFailed"), instance: instance, localDbError: hr);
            }

            SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> Finished creation of instance {0}", instance);
            instanceInfo.created = true; // mark instance as created
        } // CreateLocalDbInstance
示例#6
0
 public static Exception InvalidOffsetLength()
 {
     return(_Argument(StringsHelper.GetString(Strings.Data_InvalidOffsetLength)));
 }
 protected override string GetLocalizedString(string value)
 {
     return(StringsHelper.GetString(value));
 }