Beispiel #1
0
    private bool IsDone  = false; //更新完毕
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnInit(procedureOwner);

        ClientApp.Event.Subscribe(ResourceCheckCompleteEventArgs.EventId, OnCheckComplete);         //检查资源列表完成
        ClientApp.Event.Subscribe(VersionListUpdateSuccessEventArgs.EventId, OnListUpdateSuccess);  //更新list成功
        ClientApp.Event.Subscribe(ResourceUpdateChangedEventArgs.EventId, OnResourceUpdateChanged); //更新单个资源进度
        ClientApp.Event.Subscribe(ResourceUpdateSuccessEventArgs.EventId, OnResourceUpdateSuccess); //更新单个资源成功
        ClientApp.Event.Subscribe(ResourceUpdateFailureEventArgs.EventId, OnResourceUpdateFailure); //更新单个资源失败
        ClientApp.Event.Subscribe(ResourceUpdateAllCompleteEventArgs.EventId, OnAllComplete);       //全部更新完成

        string ver = Application.version.Replace('.', '_');
        string url = "http://eltsres.gulugames.cn/test/" + "GameResourceVersion_" + ver + ".xml";

        WebRequestEvent _event = new WebRequestEvent
        {
            OnSuccess = delegate(int SerialId, byte[] bytes)
            {
                System.Text.UTF8Encoding code = new System.Text.UTF8Encoding(false);
                bytes = CleanUTF8Bom(bytes);
                string str = code.GetString(bytes);
                Debug.Log(str);
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(str);
                XmlNode      node = xml.SelectSingleNode("ResourceVersionInfo");
                XmlAttribute LatestInternalResourceVersionNode = node.Attributes["LatestInternalResourceVersion"];
                int          LatestInternalResourceVersion     = int.Parse(LatestInternalResourceVersionNode.Value); //内部版本号

                node = node.SelectSingleNode("StandaloneWindows");
                XmlAttribute ZipHashCodeNode = node.Attributes["ZipHashCode"];
                int          ZipHashCode     = int.Parse(ZipHashCodeNode.Value);

                XmlAttribute ZipLengthNode = node.Attributes["ZipLength"];
                int          ZipLength     = int.Parse(ZipLengthNode.Value);

                XmlAttribute HashCodeNode = node.Attributes["HashCode"];
                int          HashCode     = int.Parse(HashCodeNode.Value);

                XmlAttribute LengthNode = node.Attributes["Length"];
                int          Length     = int.Parse(LengthNode.Value);

                if (ClientApp.Resource.CheckVersionList(LatestInternalResourceVersion) == GameFramework.Resource.CheckVersionListResult.NeedUpdate)
                {
                    ClientApp.Resource.UpdateVersionList(Length, HashCode, ZipLength, ZipHashCode);
                }
                else
                {
                    ClientApp.Resource.CheckResources();
                }
            }
        };

        ClientApp.Resource.UpdatePrefixUri = "http://eltsres.gulugames.cn/test/windows/";
        ClientApp.WebRequest.AddWebRequest(url, _event);
    }
Beispiel #2
0
        /// <summary>
        /// Processes the event passed to the provider.
        /// </summary>
        /// <param name="raisedEvent"></param>
        public override void ProcessEvent(WebBaseEvent raisedEvent)
        {
            //make SURE we're really running in the web server so we don't mess up aspnet_compiler.
            if (m_NotInAspNet)
            {
                return;
            }

            try
            {
                //lets see if this is an event we're going to ignore to keep the log clean.
                if (raisedEvent.EventCode == WebEventCodes.AuditUrlAuthorizationSuccess)
                {
                    return; //this is an ignorable audit success, who cares.
                }
                if (raisedEvent.EventCode == WebEventCodes.AuditFileAuthorizationSuccess)
                {
                    return; //this is an ignorable audit success, who cares.
                }
                if (raisedEvent.EventCode == WebEventCodes.ApplicationHeartbeat)
                {
                    return; //the user has other ways of knowing we're alive, we don't want to record this.
                }
                if (raisedEvent.EventCode == WebEventCodes.ApplicationShutdown)
                {
                    //call end session and tell it our sucess information
                    Log.EndSession(SessionStatus.Normal, raisedEvent.Message);
                    return;
                }

                string categoryName = "System.Events." + GetEventCodeCategoryName(raisedEvent.EventCode);

                string caption     = raisedEvent.Message;
                string description = null;

                Exception          exception = null;
                LogMessageSeverity severity;

                Uri requestUri = null;
                WebProcessInformation processInformation = null;
                WebRequestInformation requestInformation = null;
                WebThreadInformation  threadInformation  = null;

                //process types we explicitly understand first

                if (raisedEvent is WebSuccessAuditEvent)
                {
                    //it's an otherwise unknown inheritor of the success event, treat it as such.
                    WebSuccessAuditEvent specificEvent = raisedEvent as WebSuccessAuditEvent;

                    severity           = LogMessageSeverity.Verbose;
                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebViewStateFailureAuditEvent)
                {
                    //it's an otherwise unknown inheritor of the failure audit event, treat it as such.
                    WebViewStateFailureAuditEvent specificEvent = raisedEvent as WebViewStateFailureAuditEvent;

                    severity  = LogMessageSeverity.Error;
                    exception = specificEvent.ViewStateException;
                    GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier.

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebFailureAuditEvent)
                {
                    //it's an otherwise unknown inheritor of the failure event, treat it as such.
                    WebFailureAuditEvent specificEvent = raisedEvent as WebFailureAuditEvent;

                    severity = LogMessageSeverity.Warning;

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebRequestEvent)
                {
                    //it's an otherwise unknown inheritor of the request event, treat it as such.
                    WebRequestEvent specificEvent = raisedEvent as WebRequestEvent;

                    severity = LogMessageSeverity.Information;

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebRequestErrorEvent)
                {
                    //it's an otherwise unknown inheritor of the request error event, treat it as such.
                    WebRequestErrorEvent specificEvent = raisedEvent as WebRequestErrorEvent;

                    severity  = LogMessageSeverity.Error;
                    exception = specificEvent.ErrorException;
                    GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier.

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                    threadInformation  = specificEvent.ThreadInformation;
                }
                else if (raisedEvent is WebErrorEvent)
                {
                    //it's an otherwise unknown inheritor of the error event, treat it as such.
                    WebErrorEvent specificEvent = raisedEvent as WebErrorEvent;

                    severity  = LogMessageSeverity.Error;
                    exception = specificEvent.ErrorException;
                    GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier.

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                    threadInformation  = specificEvent.ThreadInformation;
                }
                else if (raisedEvent is WebBaseErrorEvent)
                {
                    //it's an otherwise unknown inheritor of the base error event, treat it as such.
                    WebBaseErrorEvent specificEvent = raisedEvent as WebBaseErrorEvent;

                    exception = specificEvent.ErrorException;
                    severity  = LogMessageSeverity.Error;

                    processInformation = specificEvent.ProcessInformation;
                }
                else if (raisedEvent is WebApplicationLifetimeEvent)
                {
                    WebApplicationLifetimeEvent specificEvent = raisedEvent as WebApplicationLifetimeEvent;

                    //we use different severities for two scenarios:  Compilation and startup/shutdown
                    if ((raisedEvent.EventCode == WebEventCodes.ApplicationCompilationStart) ||
                        (raisedEvent.EventCode == WebEventCodes.ApplicationCompilationEnd))
                    {
                        severity = LogMessageSeverity.Verbose;
                    }
                    else
                    {
                        severity = LogMessageSeverity.Information;
                    }

                    processInformation = specificEvent.ProcessInformation;
                }
                else if (raisedEvent is WebManagementEvent)
                {
                    //it's an otherwise unknown inheritor of the management event, treat it as such.
                    WebManagementEvent specificEvent = raisedEvent as WebManagementEvent;

                    severity = LogMessageSeverity.Information;

                    processInformation = specificEvent.ProcessInformation;
                }
                else
                {
                    //overly simple initial implementation
                    severity = LogMessageSeverity.Information;
                }

                //see if we can populate more fields based on ASP-NET objects
                string userName = null;
                if (processInformation != null)
                {
                    userName = processInformation.AccountName;
                }

                if (threadInformation != null)
                {
                    //thread user name better than process user name
                    userName = threadInformation.ThreadAccountName;
                }

                string detailsXml = null;
                if (requestInformation != null)
                {
                    //if there is a current principal, that's our favorite answer.
                    IPrincipal currentPrincipal = requestInformation.Principal;
                    IIdentity  currentIdentity  = null;
                    if (currentPrincipal != null)
                    {
                        currentIdentity = currentPrincipal.Identity;
                    }

                    userName = currentIdentity != null ? currentIdentity.Name : requestInformation.ThreadAccountName;

                    detailsXml = GetRequestXml(requestInformation);

                    if (string.IsNullOrEmpty(requestInformation.RequestUrl) == false)
                    {
                        try
                        {
                            requestUri = new Uri(requestInformation.RequestUrl);
                        }
                        catch (Exception ex)
                        {
                            GC.KeepAlive(ex);
#if DEBUG
                            Log.RecordException(ex, "System", true);
#endif
                        }
                    }
                }

                //three ways we create our message source provider: Exception (best), Thread info (gotta parse, but accurate), and Request INfo (fake location)
                IMessageSourceProvider requestSource = null;
                if (exception != null)
                {
                    requestSource = new ExceptionSourceProvider(exception);
                }
                else if (requestInformation != null)
                {
                    requestSource = new WebRequestSourceProvider(requestInformation, requestUri);
                }
                else if (raisedEvent.EventSource != null)
                {
                    requestSource = new WebRequestSourceProvider(raisedEvent.EventSource);
                }

                //if we haven't figured out a class name by now, BS it using our event source.
                if ((requestSource as WebRequestSourceProvider != null) &&
                    (string.IsNullOrEmpty(requestSource.ClassName) && (raisedEvent.EventSource != null)))
                {
                    (requestSource as WebRequestSourceProvider).SetSource(raisedEvent.EventSource);
                }

                Log.Write(severity, LogSystem, requestSource, userName, exception, LogWriteMode.Queued, detailsXml, categoryName, caption, description);
            }
            catch (Exception ex)
            {
                GC.KeepAlive(ex);

#if DEBUG
                Log.RecordException(ex, "System", true);
#endif
            }
        }