protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                // load...
                SimpleXmlPropertyBag input = SimpleXmlPropertyBag.Load(this.Request.InputStream, typeof(SimpleXmlPropertyBag));
                if (input == null)
                    throw new InvalidOperationException("'bag' is null.");

                // op...
                string opName = input.GetStringValue("operation", null, Cultures.System, OnNotFound.ThrowException);
                OperationBase operation = null;
                if (string.Compare(opName, "startpanicking", true, Cultures.System) == 0)
                    operation = new StartPanicOperation();
                else if (string.Compare(opName, "stoppanicking", true, Cultures.System) == 0)
                    operation = new StopPanicOperation();
                else
                    throw new NotSupportedException(string.Format("Cannot handle '{0}'.", opName));

                // run...
                SimpleXmlPropertyBag output = new SimpleXmlPropertyBag();
                operation.Run(input, output);

                // send...
                SendSuccess(output);
            }
            catch (Exception ex)
            {
                SendError(ex);
            }
        }
Пример #2
0
        private void LoadSettings(XmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            // load...
            _settings = SimpleXmlPropertyBag.Load(element, typeof(SimpleXmlPropertyBag));
            if (_settings == null)
            {
                throw new InvalidOperationException("_settings is null.");
            }
        }
		/// <summary>
		/// Private constructor.
		/// </summary>
		private SixBookmarksRuntime()
		{
            // settings...
            this.Settings = SimpleXmlPropertyBag.Load("Settings.xml", false);

            // register the entity type...
            EntityType bookmark = new EntityType(typeof(Bookmark), "Bookmark");
            bookmark.AddField(Bookmark.BookmarkIdKey, Bookmark.BookmarkIdKey, DataType.Int32, -1).IsKey = true;
            bookmark.AddField(Bookmark.NameKey, Bookmark.NameKey, DataType.String, 128);
            bookmark.AddField(Bookmark.UrlKey, Bookmark.UrlKey, DataType.String, 128);
            bookmark.AddField(Bookmark.OrdinalKey, Bookmark.OrdinalKey, DataType.Int32, -1);
            bookmark.AddField(Bookmark.IsLocalModifiedKey, Bookmark.IsLocalModifiedKey, DataType.Boolean, -1);
            bookmark.AddField(Bookmark.IsLocalDeletedKey, Bookmark.IsLocalDeletedKey, DataType.Boolean, -1);
            EntityType.RegisterEntityType(bookmark);
		}
        private void SendSuccess(SimpleXmlPropertyBag output)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("RestResponse");
            doc.AppendChild(root);

            // set...
            foreach (string key in output.Keys)
            {
                XmlElement element = doc.CreateElement(key);
                root.AppendChild(element);
                XmlHelper.SetElementValue(element, output[key]);
            }

            // send...
            WebRuntime.Current.TransmitDocument(doc, MimeTypes.Xml, null, this.Response, TransmitDocumentFlags.Normal);
        }
        protected void HandlePanic(SimpleXmlPropertyBag input, SimpleXmlPropertyBag output, bool start)
        {
            // get the resource...
            string resourceId = input.GetStringValue("resourceid", null, Cultures.System, OnNotFound.ThrowException);

            // find it...
            ResourceCollection resources = Resource.GetByExternalId(resourceId);
            if (resources.Count == 0)
                throw new InvalidOperationException(string.Format("A resource with ID '{0}' was not found.", resourceId));

            // we've got the one that we want...
            Resource resource = resources[0];

            // find the custom field...
            TableCatalogItem table = TableCatalogItem.GetByName("Resource");
            if (table == null)
                throw new InvalidOperationException("'table' is null.");
            CustomField field = CustomField.GetByNameAndTableCatalogId("Panic", table.TableCatalogId);
            if (field == null)
                throw new InvalidOperationException("'field' is null.");

            // get the data item...
            CustomData item = CustomData.GetByCustomFieldIdAndObjectId(field.CustomFieldId, resource.ResourceId);
            if (item == null)
            {
                item = new CustomData();
                item.CustomField = field;
                item.ObjectId = resource.ResourceId;
            }

            // set...
            if (start)
                item.Value = string.Format("Entered alert state at '{0}'", DateTime.Now);
            else
                item.Value = string.Empty;

            // save...
            item.SaveChanges();

            // set...
            output["NowPanicking"] = start;
        }
Пример #6
0
        public FilterMangler(string manglerId, SimpleXmlPropertyBag settings, ISqlFilterMangler filter)
        {
            if (manglerId == null)
            {
                throw new ArgumentNullException("manglerId");
            }
            if (manglerId.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'manglerId' is zero-length.");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            // set...
            _manglerId     = manglerId;
            _settings      = settings;
            _filterMangler = filter;
        }
 internal abstract void Run(SimpleXmlPropertyBag input, SimpleXmlPropertyBag output);
Пример #8
0
        private static FilterMangler LoadMangler(SqlSearchSettings settings, XmlElement element)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            // get the type...
            string manglerId = XmlHelper.GetAttributeString(element, "manglerId", OnNotFound.ThrowException);

            if (manglerId == null)
            {
                throw new InvalidOperationException("'manglerId' is null.");
            }
            if (manglerId.Length == 0)
            {
                throw new InvalidOperationException("'manglerId' is zero-length.");
            }

            // get the type...
            Type type = XmlHelper.GetAttributeType(element, "type", OnNotFound.ThrowException);

            if (type == null)
            {
                throw new InvalidOperationException("type is null.");
            }

            // create...
            ISqlFilterMangler filter = (ISqlFilterMangler)CreateInstance(type);

            if (filter == null)
            {
                throw new InvalidOperationException("filter is null.");
            }

            // get the settings element...
            XmlElement settingsElement = (XmlElement)element.SelectSingleNode("Settings");

            if (settingsElement == null)
            {
                throw new InvalidOperationException("settingsElement is null.");
            }

            // load...
            SimpleXmlPropertyBag bag = SimpleXmlPropertyBag.Load(settingsElement, typeof(SimpleXmlPropertyBag));

            if (bag == null)
            {
                throw new InvalidOperationException("bag is null.");
            }

            // Lets deserialize the bag into the control
            filter.DeserializeSqlSearchSettings(bag);
            FilterMangler mangler = new FilterMangler(manglerId, bag, filter);

            // patch...
            //mangler.DeserializeSqlSearchSettings(bag);

            // return...
            return(mangler);
        }
Пример #9
0
        private void SerializeSettings(XmlElement parentElement, XmlNamespaceManagerEx manager, SimpleXmlPropertyBag bag)
        {
            if (parentElement == null)
            {
                throw new ArgumentNullException("parentElement");
            }
            if (bag == null)
            {
                throw new ArgumentNullException("bag");
            }

            // add...
            XmlElement element = parentElement.OwnerDocument.CreateElement("Settings");

            parentElement.AppendChild(element);

            // save...
            bag.Save(element, manager, SimpleXmlSaveMode.ReplaceExisting);
        }
Пример #10
0
        /// <summary>
        /// Gets the XML for these settings.
        /// </summary>
        /// <returns></returns>
        public XmlDocument ToXmlDocument()
        {
            this.OnBeforeXmlSerialization();

            if (EntityType == null)
            {
                throw new InvalidOperationException("EntityType is null.");
            }

            // create...
            XmlDocument doc = new XmlDocument();

            // mbr - 22-09-2006 - manager...
            XmlNamespaceManagerEx manager = XmlHelper.GetNamespaceManagerEx(doc);

            if (manager == null)
            {
                throw new InvalidOperationException("manager is null.");
            }

            // root...
            XmlElement rootElement = doc.CreateElement(RootElementName);

            doc.AppendChild(rootElement);

            // type...
            this.AddTypeAttribute(rootElement, this.GetType());

            // entity type...
            XmlElement etElement = doc.CreateElement("EntityType");

            rootElement.AppendChild(etElement);
            etElement.InnerText = string.Format("{0}, {1}", this.EntityType.Type.FullName, this.EntityType.Type.Assembly.GetName().Name);

            // sources?
            XmlElement manglersElement = doc.CreateElement("Manglers");

            rootElement.AppendChild(manglersElement);

            // sources...
            foreach (FilterMangler mangler in this.Manglers)
            {
                if (mangler.ManglerId == null)
                {
                    throw new InvalidOperationException("'mangler.ManglerId' is null.");
                }
                if (mangler.ManglerId.Length == 0)
                {
                    throw new InvalidOperationException("'mangler.ManglerId' is zero-length.");
                }

                // owner...
                XmlElement manglerElement = doc.CreateElement("Mangler");
                manglersElement.AppendChild(manglerElement);

                // type...
                XmlAttribute manglerIdAttr = doc.CreateAttribute("manglerId");
                manglerIdAttr.Value = mangler.ManglerId;
                manglerElement.Attributes.Append(manglerIdAttr);

                if (mangler.Filter != null)
                {
                    this.AddTypeAttribute(manglerElement, mangler.Filter.GetType());
                }

                // settings...
                SimpleXmlPropertyBag bag = new SimpleXmlPropertyBag();
                mangler.Filter.SerializeSqlSearchSettings(bag);

                // add...
                this.SerializeSettings(manglerElement, manager, bag);
            }

            // settings...
            if (this.Settings.Count > 0)
            {
                this.SerializeSettings(rootElement, manager, this.SettingsAsSimpleXmlPropertyBag);
            }

            // return...
            return(doc);
        }
 internal override void Run(SimpleXmlPropertyBag input, SimpleXmlPropertyBag output)
 {
     this.HandlePanic(input, output, true);
 }