示例#1
0
        internal void HydrateNonPersistentRegistrations()
        {
            string conditionalRegistrationsDirectory = ConditionalRegistrationLog.GetConditionalRegistrationsDirectory();

            if (!string.IsNullOrEmpty(conditionalRegistrationsDirectory))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(conditionalRegistrationsDirectory);
                FileInfo[]    files         = directoryInfo.GetFiles("*.xml");
                foreach (FileInfo fileInfo in files)
                {
                    try
                    {
                        ConditionalRegistration conditionalRegistration;
                        using (StreamReader streamReader = fileInfo.OpenText())
                        {
                            conditionalRegistration = ConditionalRegistration.DeserializeFromStreamReader(streamReader);
                        }
                        if (conditionalRegistration != null)
                        {
                            ConditionalRegistrationCache.Singleton.Register(conditionalRegistration);
                        }
                        else
                        {
                            File.Delete(fileInfo.FullName);
                        }
                    }
                    catch (Exception exception)
                    {
                        ConditionalRegistrationLog.LogFailedHydration(new XElement(string.Format("Failed to hydrate registration with cookie:{0}", fileInfo.Name)), exception);
                    }
                }
            }
        }
示例#2
0
        public static string Save(ConditionalRegistration registration)
        {
            string text = Path.Combine(ConditionalRegistrationLog.GetConditionalRegistrationsDirectory(), string.Format("{0}.{1}", registration.Cookie, "xml"));

            ExTraceGlobals.DiagnosticHandlersTracer.TraceDebug <string, string>(0L, "[ConditionalRegistrationLog.Save] Logging registration for '{0}' of user '{1}'", registration.Cookie, registration.User);
            using (XmlWriter xmlWriter = XmlWriter.Create(text, ConditionalRegistrationLog.writerSettings))
            {
                XElement xelement = new XElement("ConditionalRegistration");
                XElement content  = new XElement("Description")
                {
                    Value = registration.Description
                };
                xelement.Add(content);
                XElement content2 = new XElement("CreatedTime")
                {
                    Value = registration.Created.ToString()
                };
                xelement.Add(content2);
                XElement content3 = new XElement("User")
                {
                    Value = registration.User
                };
                xelement.Add(content3);
                XElement content4 = new XElement("Cookie")
                {
                    Value = registration.Cookie
                };
                xelement.Add(content4);
                XElement content5 = new XElement("PropertiesToFetch")
                {
                    Value = registration.OriginalPropertiesToFetch
                };
                xelement.Add(content5);
                XElement content6 = new XElement("Filter")
                {
                    Value = registration.OriginalFilter
                };
                xelement.Add(content6);
                XElement content7 = new XElement("TimeToLive")
                {
                    Value = registration.TimeToLive.ToString()
                };
                xelement.Add(content7);
                XElement content8 = new XElement("MaxHits")
                {
                    Value = registration.MaxHits.ToString()
                };
                xelement.Add(content8);
                xelement.WriteTo(xmlWriter);
                xmlWriter.Flush();
            }
            return(text);
        }
示例#3
0
        public static void DeleteRegistration(string cookie)
        {
            string path = Path.Combine(ConditionalRegistrationLog.GetConditionalRegistrationsDirectory(), string.Format("{0}.{1}", cookie, "xml"));

            ExTraceGlobals.DiagnosticHandlersTracer.TraceDebug <string>(0L, "[ConditionalRegistrationLog.DeleteRegistration] Deleting registration for '{0}'", cookie);
            if (File.Exists(path))
            {
                try
                {
                    File.Delete(path);
                }
                catch (Exception ex)
                {
                    ExTraceGlobals.DiagnosticHandlersTracer.TraceDebug <string, string>(0L, "[ConditionalRegistrationLog.DeleteRegistration] failure deleting registration for '{0}'. Exception: {1}", cookie, ex.ToString());
                }
            }
        }