public ValidationMessageCollection ValidateEdit(EditRequest request)
        {
            _log.Add(request);
            var parameterSet       = _editParameterSetMapper.Map(request);
            var bus                = _busRepository.GetById(request.Id);
            var validationMessages = bus.ValidateEdit(parameterSet);

            return(validationMessages);
        }
Exemple #2
0
 /// <summary>
 /// 释放资源
 /// </summary>
 private void onDispose()
 {
     fileBuffer[bufferIndex++] = 0x3b;
     try
     {
         stream.Write(fileBuffer, 0, bufferIndex);
     }
     catch (Exception error)
     {
         log.Add(AutoCSer.Log.LogType.Error, error);
     }
 }
Exemple #3
0
 /// <summary>
 /// 新建文件处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void onCreatedHttpServerRegister(object sender, FileSystemEventArgs e)
 {
     try
     {
         if (AutoCSer.Diagnostics.ProcessCopyServer.FileWatcherFilter(e))
         {
             onCreated(e);
         }
     }
     catch (Exception error)
     {
         log.Add(AutoCSer.Log.LogType.Error, error);
     }
 }
        public void Add_ManualAdditionOfAircraft_ExpectedTrue()
        {
            FormattedData test1 = new FormattedData("test1", 1, 1, 1, DateTime.Today, "nord", 10);
            FormattedData test2 = new FormattedData("test2", 2, 2, 2, DateTime.Today, "syd", 20);

            _uut.Add(test1, test2);

            FormattedData test3 = new FormattedData("test3", 3, 3, 3, DateTime.Today, "øst", 30);
            FormattedData test4 = new FormattedData("test4", 4, 4, 4, DateTime.Today, "vest", 40);

            _uut.Add(test3, test4);

            Assert.That(_uut.GetConflictList().Count == 2);
        }
Exemple #5
0
        internal IBlock GetCmsBlock(HttpRequestMessage request, ILog log)
        {
            var wrapLog = log.Call <IBlock>(useTimer: true);

            var moduleInfo = request.FindModuleInfo();

            if (moduleInfo == null)
            {
                return(wrapLog("request ModuleInfo not found", null));
            }

            var context = _serviceProvider.Build <IContextOfBlock>().Init(moduleInfo, log);

            context.Page.Parameters = GetOverrideParams(request);
            IBlock block = _serviceProvider.Build <BlockFromModule>().Init(context, log);

            // check if we need an inner block
            if (request.Headers.Contains(WebApiConstants.HeaderContentBlockId))
            {
                var blockHeaderId = request.Headers.GetValues(WebApiConstants.HeaderContentBlockId).FirstOrDefault();
                int.TryParse(blockHeaderId, out var blockId);
                if (blockId < 0)   // negative id, so it's an inner block
                {
                    log.Add($"Inner Content: {blockId}");
                    block = _serviceProvider.Build <BlockFromEntity>().Init(block, blockId, log);
                }
            }

            return(wrapLog("ok", block));
        }
Exemple #6
0
        /// <summary>
        /// Update a setting for all language-versions of a module
        /// </summary>
        public static void UpdateInstanceSettingForAllLanguages(int instanceId, string key, string value, ILog log)
        {
            log?.Add($"UpdateInstanceSettingForAllLanguages(iid: {instanceId}, key: {key}, val: {value})");
            var moduleController = new ModuleController();

            // Find this module in other languages and update contentGroupGuid
            var originalModule = moduleController.GetModule(instanceId);
            var languages      = LocaleController.Instance.GetLocales(originalModule.PortalID);

            if (!originalModule.IsDefaultLanguage && originalModule.DefaultLanguageModule != null)
            {
                originalModule = originalModule.DefaultLanguageModule;
            }

            foreach (var language in languages)
            {
                // Find module for given Culture
                var moduleByCulture = moduleController.GetModuleByCulture(originalModule.ModuleID, originalModule.TabID, originalModule.PortalID, language.Value);

                // Break if no module found
                if (moduleByCulture == null)
                {
                    continue;
                }

                if (value == null)
                {
                    moduleController.DeleteModuleSetting(moduleByCulture.ModuleID, key);
                }
                else
                {
                    moduleController.UpdateModuleSetting(moduleByCulture.ModuleID, key, value);
                }
            }
        }
Exemple #7
0
 public static void Write <T>(this ILog input, Result result, ResultLevel level = ResultLevel.Normal, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
 {
     if (input.Enabled)
     {
         var logEntry = new LogEntry(level, typeof(T).Name, result, member, line);
         input.Add(logEntry);
     }
 }
Exemple #8
0
 public int Add(BasLog model)
 {
     if (model == null)
     {
         return(0);
     }
     return(dal.Add(model));
 }
        /// <summary>
        /// 写文件
        /// </summary>
        internal void WriteFile()
        {
            bool isErrorWait = isError;

            do
            {
                Monitor.Enter(bufferLock);
                if (buffers.Length == 0)
                {
                    if (buffer.IsBuffer)
                    {
                        currentBuffers.Array[0] = buffer;
                        buffer.Clear();
                        ++currentBuffers.Length;
                    }
                    else
                    {
                        isWritting = false;
                        Monitor.Exit(bufferLock);
                        if (isErrorWait)
                        {
                            Monitor.Enter(waitLock);
                            Monitor.PulseAll(waitLock);
                            Monitor.Exit(waitLock);
                        }
                        return;
                    }
                }
                else
                {
                    currentBuffers.Exchange(ref buffers);
                }
                Monitor.Exit(bufferLock);
                WaitBuffer[] bufferArray = currentBuffers.Array;
                int          count = currentBuffers.Length, index = 0;
                if (!isError)
                {
                    try
                    {
                        do
                        {
                            bufferArray[index].WriteFile(this);
                        }while (++index != count);
                    }
                    catch (Exception error)
                    {
                        isError = true;
                        log.Add(Log.LogType.Error, error);
                        AutoCSer.Threading.ThreadPool.Tiny.FastStart(this, AutoCSer.Threading.Thread.CallType.FileStreamWriterDispose);
                    }
                }
                while (index != count)
                {
                    isErrorWait |= bufferArray[index++].Error(this);
                }
                currentBuffers.Length = 0;
            }while (true);
        }
Exemple #10
0
        public void Add_ManualAdditionOfAircraft_ExpectedTrue()
        {
            FormattedData test1 = new FormattedData("test1", 1, 1, 1, DateTime.Today, "nord", 10);
            FormattedData test2 = new FormattedData("test2", 2, 2, 2, DateTime.Today, "syd", 20);

            _uut.Add(test1, test2);

            Assert.That(_uut.GetConflictList().Count == 1);
            Assert.That(writer.WasWriterCalled == true);
        }
Exemple #11
0
        /// <summary>
        /// 释放文件
        /// </summary>
        public void Dispose()
        {
            FileStream fileStream = this.fileStream;

            if (fileStream != null)
            {
                this.fileStream = null;
                using (fileStream)
                {
                    fileBuffer[bufferIndex++] = 0x3b;
                    try
                    {
                        fileStream.Write(fileBuffer, 0, bufferIndex);
                    }
                    catch (Exception error)
                    {
                        log.Add(AutoCSer.Log.LogType.Error, error);
                    }
                }
            }
        }
Exemple #12
0
 /// <summary>
 /// 新建客户端命令池
 /// </summary>
 /// <param name="currentIndex">当前空闲命令位置</param>
 /// <returns></returns>
 private int create(int currentIndex)
 {
     if (bitSize == maxArrayBitSize)
     {
         if (arrayCount == arrays.Length)
         {
             if (arrayCount == 1 << (Server.CommandIndexBits - maxArrayBitSize))
             {
                 freeIndex = currentIndex;
                 if (isErrorLog == 0)
                 {
                     isErrorLog = 1;
                     log.Add(LogType.Error, "TCP 客户端活动会话数量过多");
                 }
                 return(0);
             }
             arrays = arrays.copyNew(arrayCount << 1);
         }
         int           index = 1 << maxArrayBitSize;
         CommandLink[] array = new CommandLink[index];
         do
         {
             array[index - 1].Next = commandCount + index;
         }while (--index != 0);
         arrays[arrayCount++] = array;
         while (System.Threading.Interlocked.CompareExchange(ref freeEndIndexLock, 1, 0) != 0)
         {
             AutoCSer.Threading.ThreadYield.YieldOnly();
         }
         arrays[freeEndIndex >> bitSize][freeEndIndex & arraySizeAnd].Next = commandCount;
         freeEndIndex = (commandCount += 1 << maxArrayBitSize) - 1;
         System.Threading.Interlocked.Exchange(ref freeEndIndexLock, 0);
     }
     else
     {
         CommandLink[] array = new CommandLink[1 << ++bitSize];
         for (int index = commandCount, endIndex = commandCount << 1; index != endIndex; ++index)
         {
             array[index].Next = index + 1;
         }
         while (System.Threading.Interlocked.CompareExchange(ref freeEndIndexLock, 1, 0) != 0)
         {
             AutoCSer.Threading.ThreadYield.YieldOnly();
         }
         Array.CopyTo(array, 0);
         arrays[0] = Array = array;
         array[freeEndIndex].Next = commandCount;
         freeEndIndex             = arraySizeAnd = (commandCount <<= 1) - 1;
         System.Threading.Interlocked.Exchange(ref freeEndIndexLock, 0);
     }
     freeIndex = (currentIndex < (1 << maxArrayBitSize) ? Array : pushArray)[currentIndex & arraySizeAnd].Next;
     return(currentIndex);
 }
Exemple #13
0
        internal static IBlock GetCmsBlock(HttpRequestMessage request, bool allowNoContextFound, ILog log)
        {
            var wrapLog = log.Call <IBlock>(parameters: $"request:..., {nameof(allowNoContextFound)}: {allowNoContextFound}");

            //const string headerId = "ContentBlockId";
            var moduleInfo = request.FindModuleInfo();

            if (allowNoContextFound & moduleInfo == null)
            {
                return(wrapLog("request ModuleInfo not found, allowed", null));
            }

            if (moduleInfo == null)
            {
                log.Add("context/module not found");
            }

            var container = new DnnContainer().Init(moduleInfo, log);

            var tenant = moduleInfo == null
                ? new DnnTenant(null)
                : new DnnTenant().Init(moduleInfo.OwnerPortalID);

            var    context = new DnnContext(tenant, container, new DnnUser(), GetOverrideParams(request));
            IBlock block   = new BlockFromModule().Init(context, log);

            // check if we need an inner block
            if (request.Headers.Contains(WebApiConstants.HeaderContentBlockId))
            {
                var blockHeaderId = request.Headers.GetValues(WebApiConstants.HeaderContentBlockId).FirstOrDefault();
                int.TryParse(blockHeaderId, out var blockId);
                if (blockId < 0)   // negative id, so it's an inner block
                {
                    log.Add($"Inner Content: {blockId}");
                    block = new BlockFromEntity().Init(block, blockId, log);
                }
            }

            return(wrapLog("ok", block));
        }
Exemple #14
0
        public override Status Process()
        {
            if (Log.RootCaller == null)
            {
                Log.RootCaller = this;
            }

            var result = Node.Process();

            Log.Add(this, result);

            //var parent = Parent as Logger;

            if (Log.RootCaller == this)
            {
                Log.RootCaller = null;
                Log.OnRootExit(this);
            }


            return(result);
        }
Exemple #15
0
        internal static IBlockBuilder GetCmsBlock(HttpRequestMessage request, bool allowNoContextFound, ILog log)
        {
            var wrapLog = log.Call <IBlockBuilder>(parameters: $"request:..., {nameof(allowNoContextFound)}: {allowNoContextFound}");

            const string headerId   = "ContentBlockId";
            var          moduleInfo = request.FindModuleInfo();

            if (allowNoContextFound & moduleInfo == null)
            {
                return(wrapLog("request ModuleInfo not found, allowed", null));
            }

            if (moduleInfo == null)
            {
                log.Add("context/module not found");
            }

            var urlParams = PrepareUrlParamsForInternalUse(request);

            var tenant = moduleInfo == null
                ? new DnnTenant(null)
                : new DnnTenant(new PortalSettings(moduleInfo.OwnerPortalID));

            IBlock contentBlock = new BlockFromModule(new DnnContainer(moduleInfo), log, tenant, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(headerId))
            {
                var blockHeaderId = request.Headers.GetValues(headerId).FirstOrDefault();
                int.TryParse(blockHeaderId, out var blockId);
                if (blockId < 0)   // negative id, so it's an inner block
                {
                    log.Add($"Inner Content: {blockId}");
                    contentBlock = new BlockFromEntity(contentBlock, blockId, log);
                }
            }

            return(wrapLog("ok", contentBlock.BlockBuilder));
        }
Exemple #16
0
        /// <summary>
        /// Update a setting for all language-versions of a module
        /// </summary>
        public void UpdateInstanceSetting(int instanceId, string key, string value, ILog log)
        {
            log?.Add($"UpdateInstanceSetting(iid: {instanceId}, key: {key}, val: {value})");

            if (value == null)
            {
                _settingsHelper.DeleteSetting(EntityNames.Module, instanceId, key);
            }
            else
            {
                _settingsHelper.UpdateSetting(EntityNames.Module, instanceId, key, value);
            }
        }
Exemple #17
0
        internal static string GetAppFolder <T>(HttpRequestMessage request, ILog log, Func <string, T, T> wrapLog)
        {
            const string errPrefix = "Api Controller Finder Error: ";
            const string errSuffix = "Check event-log, code and inner exception. ";

            var routeData = request.GetRouteData();

            // Figure out the Path, or show error for that.
            string appFolder = null;

            try
            {
                appFolder = Route.AppPathOrNull(routeData);

                // only check for app folder if we don't have a context
                if (appFolder == null)
                {
                    log.Add("no folder found in url, will auto-detect");
                    var block = Eav.Factory.StaticBuild <DnnGetBlock>().GetCmsBlock(request, log);
                    appFolder = block?.App?.Folder;
                }

                log.Add($"App Folder: {appFolder}");
            }
            catch (Exception getBlockException)
            {
                const string msg = errPrefix + "Trying to find app name, unexpected error - possibly bad/invalid headers. " + errSuffix;
                throw ReportToLogAndThrow <T>(request, HttpStatusCode.BadRequest, getBlockException, msg, wrapLog);
            }

            if (string.IsNullOrWhiteSpace(appFolder))
            {
                const string msg = errPrefix + "App name is unknown - tried to check name in url (.../app/[app-name]/...) " +
                                   "and tried app-detection using url-params/headers pageid/moduleid. " + errSuffix;
                throw ReportToLogAndThrow <T>(request, HttpStatusCode.BadRequest, new Exception(msg), msg, wrapLog);
            }

            return(appFolder);
        }
        public ValidationMessageCollection ValidateCustomerMake(CustomerMakeBookingRequest request)
        {
            _log.Add(request);
            var parameterSet       = _customerMakePendingParameterSetMapper.Map(request);
            var validationMessages = Booking.ValidateCustomerMake(parameterSet);

            return(validationMessages);
        }
Exemple #19
0
        /// <summary>
        /// Get a Root CMS Block if you know the TabId and the ModId
        /// </summary>
        /// <param name="pageId">The DNN tab id (page id)</param>
        /// <param name="modId">The DNN Module id</param>
        /// <param name="parentLog">The parent log, optional</param>
        /// <returns>An initialized CMS Block, ready to use/render</returns>
        public static IBlockBuilder CmsBlock(int pageId, int modId, ILog parentLog)
        {
            var wrapLog    = parentLog?.Call($"{pageId}, {modId}");
            var moduleInfo = new ModuleController().GetModule(modId, pageId, false);

            if (moduleInfo == null)
            {
                var msg = $"Can't find module {modId} on page {pageId}. Maybe you reversed the ID-order?";
                parentLog?.Add(msg);
                throw new Exception(msg);
            }
            var container = Eav.Factory.StaticBuild <DnnModule>().Init(moduleInfo, parentLog);

            wrapLog?.Invoke("ok");
            return(CmsBlock(container, parentLog));
        }
Exemple #20
0
        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="context"></param>
        public void OnException(ExceptionContext context)
        {
            string msg = context.Exception.Message;

            //错误信息记录数据库
            _mslog.Add(new Model.Message.Log
            {
                IpAddress  = context.HttpContext.Connection.LocalIpAddress.ToString(),
                Title      = context.Exception.Message,
                Type       = 1,
                Url        = context.HttpContext.Request.GetAbsoluteUri(),
                UserId     = context.HttpContext.User.Identity.GetUserId().ToString(),
                Detail     = context.Exception.ToString(),
                UserName   = "",
                CreateDate = DateTime.Now
            });
        }
Exemple #21
0
        public bool IsThereConflict(FormattedData currentData)
        {
            bool result = false;

            foreach (FormattedData aircraft in GetAircraftList())
            {
                if (currentData.Tag != aircraft.Tag && AreAircraftsInConflict(currentData, aircraft) == true)
                {
                    result             = true;
                    aircraftInConflict = aircraft;
                    _log.Add(aircraft, currentData);
                }
                else
                {
                    _log.Remove(currentData);
                }
            }

            return(result);
        }
Exemple #22
0
        /// <summary>
        /// 记录日志到文件
        /// </summary>
        /// <param name="logTitle">日志标题</param>
        /// <param name="logMsg">日志内容</param>
        /// <param name="userName">用户名</param>
        /// <param name="logCategory">日志类别</param>
        /// <param name="logPriority">日志等级</param>
        /// <param name="logSource">异常信息</param>
        public static void SaveFileLog(string logTitle, string logMsg, string userName = "", LogCategory logCategory = LogCategory.SystemAction, LogPriority logPriority = LogPriority.Normal, string logSource = "")
        {
            LogInfo info = new LogInfo();

            info.UserIP    = IPHelper.GetClientIP();
            info.Timestamp = DateTime.Now;
            info.Category  = logCategory;
            info.Priority  = logPriority;
            info.UserName  = userName;
            if (MyHttpContext.Current != null)
            {
                if (MyHttpContext.Current.Request.Path.HasValue)
                {
                    info.ScriptName = MyHttpContext.Current.Request.Path.Value;
                }
            }
            string strHeaders = "Request Headers信息:";

            foreach (string strFormKey in MyHttpContext.Current.Request.Headers.Keys)
            {
                strHeaders += "\"" + strFormKey + "\":\"" + MyHttpContext.Current.Request.Headers[strFormKey] + "\",";
            }
            strHeaders = strHeaders.TrimEnd(',');
            string strForm = "Request Form信息:";

            if (MyHttpContext.Current.Request.Method == "POST" && MyHttpContext.Current.Request.HasFormContentType)
            {
                foreach (string strFormKey in MyHttpContext.Current.Request.Form.Keys)
                {
                    strForm += "\"" + strFormKey + "\":\"" + DataConverter.ToString(MyHttpContext.Current.Request.Form[strFormKey]) + "\",";
                }
                strForm = strForm.TrimEnd(',');
            }
            info.PostString = strHeaders + Environment.NewLine + strForm;
            info.Source     = logSource;
            info.Message    = logMsg;
            info.Title      = logTitle;
            ILog log = CreateLog(LogType.Files);

            log.Add(info);
        }
Exemple #23
0
 /// <summary>
 /// 获取 TCP 注册服务客户端
 /// </summary>
 /// <param name="serviceName">服务名称</param>
 /// <param name="Log">日志处理</param>
 /// <returns>TCP注册服务客户端,失败返回null</returns>
 internal static Client Get(string serviceName, ILog Log)
 {
     if (!string.IsNullOrEmpty(serviceName))
     {
         int        count   = int.MinValue;
         Client     client  = null;
         HashString nameKey = serviceName;
         Monitor.Enter(clientsLock);
         try
         {
             if (!clients.TryGetValue(nameKey, out client))
             {
                 try
                 {
                     client = new Client(serviceName);
                 }
                 catch (Exception error)
                 {
                     Log.Add(AutoCSer.Log.LogType.Error, error);
                 }
                 if (client != null)
                 {
                     count = clients.Count;
                     clients.Add(nameKey, client);
                 }
             }
         }
         finally { Monitor.Exit(clientsLock); }
         if (count == 0)
         {
             AutoCSer.DomainUnload.Unloader.Add(null, AutoCSer.DomainUnload.Type.TcpRegisterClientClose);
         }
         if (client != null)
         {
             client.createWait.Wait();
             return(client);
         }
     }
     return(null);
 }
Exemple #24
0
 /// <summary>
 /// 获取 TCP 注册服务客户端
 /// </summary>
 /// <param name="serviceName">服务名称</param>
 /// <param name="Log">日志处理</param>
 /// <returns>TCP注册服务客户端,失败返回null</returns>
 internal static Client Get(string serviceName, ILog Log)
 {
     if (!string.IsNullOrEmpty(serviceName))
     {
         Client     client;
         HashString nameKey = serviceName;
         if (clients.TryGetValueEnter(ref nameKey, out client))
         {
             return(client);
         }
         try
         {
             clients.SetOnly(ref nameKey, client = new Client(serviceName));
         }
         catch (Exception error)
         {
             Log.Add(AutoCSer.Log.LogType.Error, error);
         }
         finally { clients.Exit(); }
         return(client);
     }
     return(null);
 }
 /// <summary>
 /// 进程退出事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void guard(object sender, EventArgs e)
 {
     try
     {
         Dispose();
         if (System.IO.File.Exists(Process))
         {
             start();
         }
         else
         {
             log.Add(AutoCSer.Log.LogType.Error, "没有找到文件 " + Process);
         }
     }
     catch (Exception error)
     {
         log.Add(AutoCSer.Log.LogType.Error, error, "进程启动失败 " + Process);
     }
 }
Exemple #26
0
 /// <summary>
 /// 守护启动进程
 /// </summary>
 internal void Start()
 {
     try
     {
         ProcessCopyServer server = Server;
         if (server != null)
         {
             Server = null;
             server.Remove(this);
         }
         if (System.IO.File.Exists(Process))
         {
             start();
         }
         else
         {
             log.Add(AutoCSer.Log.LogType.Error, "没有找到文件 " + Process);
         }
     }
     catch (Exception error)
     {
         log.Add(AutoCSer.Log.LogType.Error, error, "进程启动失败 " + Process);
     }
 }
        /// <summary>
        /// 根据物理地址获取模板内容
        /// </summary>
        /// <param name="path"></param>
        /// <param name="physicalApplicationPath"></param>
        /// <returns></returns>
        public static string GetTemplateContent(string path, string physicalApplicationPath)
        {
            string str;

            if (string.IsNullOrEmpty(path))
            {
                return(string.Empty);
            }
            if ((HttpContext.Current != null) && string.IsNullOrEmpty(physicalApplicationPath))
            {
                str = HttpContext.Current.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir + path;
            }
            else
            {
                str = physicalApplicationPath + SiteConfig.SiteOption.TemplateDir + path;
            }
            str = str.Replace("/", @"\");
            try
            {
                return(FileSystemObject.ReadFile(str));
            }
            catch (FileNotFoundException exception)
            {
                ILog    log  = LogFactory.CreateLog();
                LogInfo info = new LogInfo();
                info.Category = LogCategory.Exception;
                info.Priority = LogPriority.High;
                info.Message  = exception.Message;
                if (HttpContext.Current != null)
                {
                    info.ScriptName = HttpContext.Current.Request.RawUrl;
                }
                else
                {
                    info.ScriptName = "系统线程访问!";
                }
                info.Source    = exception.Source;
                info.Timestamp = DateTime.Now;
                info.Title     = "模板文件“" + path + "”未找到";
                if (HttpContext.Current != null)
                {
                    info.UserIP = PEContext.Current.UserHostAddress;
                }
                else
                {
                    info.UserIP = "";
                }
                info.UserName = "******";
                log.Add(info);
                return("模板文件未找到");
            }
            catch (UnauthorizedAccessException exception2)
            {
                ILog    log2  = LogFactory.CreateLog();
                LogInfo info2 = new LogInfo();
                info2.Category = LogCategory.Exception;
                info2.Priority = LogPriority.High;
                info2.Message  = exception2.Message;
                if (HttpContext.Current != null)
                {
                    info2.ScriptName = HttpContext.Current.Request.RawUrl;
                }
                else
                {
                    info2.ScriptName = "系统线程访问!";
                }
                info2.Source    = exception2.Source;
                info2.Timestamp = DateTime.Now;
                info2.Title     = "没有模板文件“" + path + "”的访问权限";
                if (HttpContext.Current != null)
                {
                    info2.UserIP = PEContext.Current.UserHostAddress;
                }
                else
                {
                    info2.UserIP = "";
                }
                info2.UserName = "******";
                log2.Add(info2);
                return("没有模板文件访问权限");
            }
            catch (Exception exception3)
            {
                ILog    log3  = LogFactory.CreateLog();
                LogInfo info3 = new LogInfo();
                info3.Category = LogCategory.Exception;
                info3.Priority = LogPriority.High;
                info3.Message  = exception3.Message;
                if (HttpContext.Current != null)
                {
                    info3.ScriptName = HttpContext.Current.Request.RawUrl;
                }
                else
                {
                    info3.ScriptName = "系统线程访问!";
                }
                info3.Source    = exception3.Source;
                info3.Timestamp = DateTime.Now;
                info3.Title     = "读取模板文件“" + path + "”出错";
                if (HttpContext.Current != null)
                {
                    info3.UserIP = PEContext.Current.UserHostAddress;
                }
                else
                {
                    info3.UserIP = "";
                }
                info3.UserName = "******";
                log3.Add(info3);
                return("读取模板文件出错");
            }
        }
        protected void IbtnEnter_Click(object sender, EventArgs e)
        {
            string str  = (string)this.Session["LoginName"];
            string str2 = (string)this.Session["password"];

            if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str2))
            {
                AdminPage.WriteErrMsg("<li>操作超时</li>", "Login.aspx");
            }
            string            str4 = base.Request.Form[str];
            string            str5 = base.Request.Form[str2];
            AdministratorInfo info = Administrators.AuthenticateAdmin(str4.Trim(), str5.Trim());

            if (info.IsLock)
            {
                AdminPage.WriteErrMsg("<li>此管理员已经被锁定,请联系网站管理员!</li>", "Login.aspx");
            }
            LogInfo info2 = new LogInfo();

            info2.UserName   = info.AdminName;
            info2.UserIP     = PEContext.Current.UserHostAddress;
            info2.ScriptName = base.Request.RawUrl;
            info2.Timestamp  = DateTime.Now;
            info2.Source     = "";
            ILog log = LogFactory.CreateLog();

            if (!info.IsNull && (string.Compare(info.AdminName, str4.Trim(), StringComparison.OrdinalIgnoreCase) == 0))
            {
                AdminPrincipal principal = new AdminPrincipal();
                principal.UserName    = info.UserName;
                principal.AdminName   = info.AdminName;
                principal.RndPassword = info.RndPassword;
                string userData = principal.SerializeToString();
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, info.AdminName, DateTime.Now, DateTime.Now.AddMinutes((double)SiteConfig.SiteOption.TicketTime), false, userData);
                string     str8   = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName + "AdminCookie", str8);
                cookie.HttpOnly = true;
                cookie.Path     = FormsAuthentication.FormsCookiePath;
                cookie.Secure   = FormsAuthentication.RequireSSL;
                base.Response.Cookies.Add(cookie);
                if (base.Request.Cookies[FormsAuthentication.FormsCookieName] == null)
                {
                    UserInfo usersByUserName = Users.GetUsersByUserName(principal.UserName);
                    if (!usersByUserName.IsNull && (usersByUserName.Status == UserStatus.None))
                    {
                        string str9 = DataSecurity.MakeRandomString(10);
                        usersByUserName.LogOnTimes++;
                        usersByUserName.LastLogOnTime = new DateTime?(DateTime.Now);
                        usersByUserName.LastLogOnIP   = PEContext.Current.UserHostAddress;
                        usersByUserName.LastPassword  = str9;
                        Users.Update(usersByUserName);
                        UserPrincipal principal2 = new UserPrincipal();
                        principal2.UserName     = principal.UserName;
                        principal2.LastPassword = str9;
                        FormsAuthenticationTicket ticket2 = new FormsAuthenticationTicket(1, principal.UserName, DateTime.Now, DateTime.Now.AddDays(1.0), false, principal2.SerializeToString());
                        string     str10   = FormsAuthentication.Encrypt(ticket2);
                        HttpCookie cookie2 = new HttpCookie(FormsAuthentication.FormsCookieName, str10);
                        cookie2.HttpOnly         = true;
                        cookie2.Path             = FormsAuthentication.FormsCookiePath;
                        cookie2.Secure           = FormsAuthentication.RequireSSL;
                        this.Session["UserName"] = principal2.UserName;
                        base.Response.Cookies.Add(cookie2);
                    }
                }
                info2.PostString = "";
                info2.Category   = LogCategory.LogOnOk;
                info2.Message    = "登录成功";
                info2.Title      = info.AdminName + " 登录成功";
                info2.Priority   = LogPriority.Normal;
                log.Add(info2);
                BasePage.ResponseRedirect("Index.aspx", true);
            }
            else
            {
                info2.PostString = "\r\nFORM: " + HttpContext.Current.Request.Form.ToString() + "\r\nQUERYSTRING: " + HttpContext.Current.Request.QueryString.ToString();
                info2.Category   = LogCategory.LogOnFailure;
                info2.Message    = "登录失败";
                info2.Title      = str4.Trim() + " 登录失败";
                info2.Priority   = LogPriority.Highest;
                log.Add(info2);
                AdminPage.WriteErrMsg("<li>用户登录名称或用户密码不对!</li>");
            }
        }
 public void AddLog(Exception error)
 {
     Log.Add(AutoCSer.Log.LogType.Error, error);
 }
Exemple #30
0
 private static void add(RoadFlow.Data.Model.Log model)
 {
     dataLog1.Add(model);
 }