コード例 #1
0
        private static string GetNextRequestId()
        {
            ulong ret = 37059;             //starting number "aaaa"

            //lock to reduce the chance of file contention
            lock (_hnd) {
                if (_RequestIdPath == null)
                {
                    if (HttpContext.Current != null)
                    {
                        _RequestIdPath = HttpContext.Current.Server.MapPath("~/App_Data/request_id_counter.bin");
                    }
                    else
                    {
                        _RequestIdPath = "./request_id_counter.bin";
                    }
                }
                var b = new byte[0];
                if (File.Exists(_RequestIdPath))
                {
                    b = File.ReadAllBytes(_RequestIdPath);
                }
                if (b.Length >= 8)
                {
                    ret = BitConverter.ToUInt64(b, 0);
                    ret++;
                }
                File.WriteAllBytes(_RequestIdPath, BitConverter.GetBytes(ret));
                return(ret.AsBase33Safe());
            }
        }