/* Copyright (c) Cloud Software Group, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1) Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2) Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; using Newtonsoft.Json; namespace XenAPI { /// /// An message for the attention of the administrator /// First published in XenServer 5.0. /// public partial class Message : XenObject { #region Constructors public Message() { } public Message(string uuid, string name, long priority, cls cls, string obj_uuid, DateTime timestamp, string body) { this.uuid = uuid; this.name = name; this.priority = priority; this.cls = cls; this.obj_uuid = obj_uuid; this.timestamp = timestamp; this.body = body; } /// /// Creates a new Message from a Hashtable. /// Note that the fields not contained in the Hashtable /// will be created with their default values. /// /// public Message(Hashtable table) : this() { UpdateFrom(table); } /// /// Creates a new Message from a Proxy_Message. /// /// public Message(Proxy_Message proxy) { UpdateFrom(proxy); } #endregion /// /// Updates each field of this instance with the value of /// the corresponding field of a given Message. /// public override void UpdateFrom(Message record) { uuid = record.uuid; name = record.name; priority = record.priority; cls = record.cls; obj_uuid = record.obj_uuid; timestamp = record.timestamp; body = record.body; } internal void UpdateFrom(Proxy_Message proxy) { uuid = proxy.uuid == null ? null : proxy.uuid; name = proxy.name == null ? null : proxy.name; priority = proxy.priority == null ? 0 : long.Parse(proxy.priority); cls = proxy.cls == null ? (cls) 0 : (cls)Helper.EnumParseDefault(typeof(cls), (string)proxy.cls); obj_uuid = proxy.obj_uuid == null ? null : proxy.obj_uuid; timestamp = proxy.timestamp; body = proxy.body == null ? null : proxy.body; } /// /// Given a Hashtable with field-value pairs, it updates the fields of this Message /// with the values listed in the Hashtable. Note that only the fields contained /// in the Hashtable will be updated and the rest will remain the same. /// /// public void UpdateFrom(Hashtable table) { if (table.ContainsKey("uuid")) uuid = Marshalling.ParseString(table, "uuid"); if (table.ContainsKey("name")) name = Marshalling.ParseString(table, "name"); if (table.ContainsKey("priority")) priority = Marshalling.ParseLong(table, "priority"); if (table.ContainsKey("cls")) cls = (cls)Helper.EnumParseDefault(typeof(cls), Marshalling.ParseString(table, "cls")); if (table.ContainsKey("obj_uuid")) obj_uuid = Marshalling.ParseString(table, "obj_uuid"); if (table.ContainsKey("timestamp")) timestamp = Marshalling.ParseDateTime(table, "timestamp"); if (table.ContainsKey("body")) body = Marshalling.ParseString(table, "body"); } public Proxy_Message ToProxy() { Proxy_Message result_ = new Proxy_Message(); result_.uuid = uuid ?? ""; result_.name = name ?? ""; result_.priority = priority.ToString(); result_.cls = cls_helper.ToString(cls); result_.obj_uuid = obj_uuid ?? ""; result_.timestamp = timestamp; result_.body = body ?? ""; return result_; } public bool DeepEquals(Message other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Helper.AreEqual2(this._uuid, other._uuid) && Helper.AreEqual2(this._name, other._name) && Helper.AreEqual2(this._priority, other._priority) && Helper.AreEqual2(this._cls, other._cls) && Helper.AreEqual2(this._obj_uuid, other._obj_uuid) && Helper.AreEqual2(this._timestamp, other._timestamp) && Helper.AreEqual2(this._body, other._body); } public override string SaveChanges(Session session, string opaqueRef, Message server) { if (opaqueRef == null) { System.Diagnostics.Debug.Assert(false, "Cannot create instances of this type on the server"); return ""; } else { throw new InvalidOperationException("This type has no read/write properties"); } } /// /// /// First published in XenServer 5.0. /// /// The session /// The name of the message /// The priority of the message /// The class of object this message is associated with /// The uuid of the object this message is associated with /// The body of the message public static XenRef create(Session session, string _name, long _priority, cls _cls, string _obj_uuid, string _body) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_create(session.opaque_ref, _name, _priority, _cls, _obj_uuid, _body); else return XenRef.Create(session.XmlRpcProxy.message_create(session.opaque_ref, _name ?? "", _priority.ToString(), cls_helper.ToString(_cls), _obj_uuid ?? "", _body ?? "").parse()); } /// /// /// First published in XenServer 5.0. /// /// The session /// The opaque_ref of the given message public static void destroy(Session session, string _message) { if (session.JsonRpcClient != null) session.JsonRpcClient.message_destroy(session.opaque_ref, _message); else session.XmlRpcProxy.message_destroy(session.opaque_ref, _message ?? "").parse(); } /// /// /// Experimental. First published in 22.19.0. /// /// The session /// Messages to destroy public static void destroy_many(Session session, List> _messages) { if (session.JsonRpcClient != null) session.JsonRpcClient.message_destroy_many(session.opaque_ref, _messages); else session.XmlRpcProxy.message_destroy_many(session.opaque_ref, _messages == null ? new string[] {} : Helper.RefListToStringArray(_messages)).parse(); } /// /// /// Experimental. First published in 22.19.0. /// /// The session /// Messages to destroy public static XenRef async_destroy_many(Session session, List> _messages) { if (session.JsonRpcClient != null) return session.JsonRpcClient.async_message_destroy_many(session.opaque_ref, _messages); else return XenRef.Create(session.XmlRpcProxy.async_message_destroy_many(session.opaque_ref, _messages == null ? new string[] {} : Helper.RefListToStringArray(_messages)).parse()); } /// /// /// First published in XenServer 5.0. /// /// The session /// The class of object /// The uuid of the object /// The cutoff time public static Dictionary, Message> get(Session session, cls _cls, string _obj_uuid, DateTime _since) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_get(session.opaque_ref, _cls, _obj_uuid, _since); else return XenRef.Create(session.XmlRpcProxy.message_get(session.opaque_ref, cls_helper.ToString(_cls), _obj_uuid ?? "", _since).parse()); } /// /// /// First published in XenServer 5.0. /// /// The session public static List> get_all(Session session) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_get_all(session.opaque_ref); else return XenRef.Create(session.XmlRpcProxy.message_get_all(session.opaque_ref).parse()); } /// /// /// First published in XenServer 5.0. /// /// The session /// The cutoff time public static Dictionary, Message> get_since(Session session, DateTime _since) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_get_since(session.opaque_ref, _since); else return XenRef.Create(session.XmlRpcProxy.message_get_since(session.opaque_ref, _since).parse()); } /// /// /// First published in XenServer 5.0. /// /// The session /// The opaque_ref of the given message public static Message get_record(Session session, string _message) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_get_record(session.opaque_ref, _message); else return new Message(session.XmlRpcProxy.message_get_record(session.opaque_ref, _message ?? "").parse()); } /// /// /// First published in XenServer 5.0. /// /// The session /// The uuid of the message public static XenRef get_by_uuid(Session session, string _uuid) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_get_by_uuid(session.opaque_ref, _uuid); else return XenRef.Create(session.XmlRpcProxy.message_get_by_uuid(session.opaque_ref, _uuid ?? "").parse()); } /// /// /// First published in XenServer 5.0. /// /// The session public static Dictionary, Message> get_all_records(Session session) { if (session.JsonRpcClient != null) return session.JsonRpcClient.message_get_all_records(session.opaque_ref); else return XenRef.Create(session.XmlRpcProxy.message_get_all_records(session.opaque_ref).parse()); } /// /// Unique identifier/object reference /// public virtual string uuid { get { return _uuid; } set { if (!Helper.AreEqual(value, _uuid)) { _uuid = value; NotifyPropertyChanged("uuid"); } } } private string _uuid = ""; /// /// The name of the message /// public virtual string name { get { return _name; } set { if (!Helper.AreEqual(value, _name)) { _name = value; NotifyPropertyChanged("name"); } } } private string _name = ""; /// /// The message priority, 0 being low priority /// public virtual long priority { get { return _priority; } set { if (!Helper.AreEqual(value, _priority)) { _priority = value; NotifyPropertyChanged("priority"); } } } private long _priority; /// /// The class of the object this message is associated with /// [JsonConverter(typeof(clsConverter))] public virtual cls cls { get { return _cls; } set { if (!Helper.AreEqual(value, _cls)) { _cls = value; NotifyPropertyChanged("cls"); } } } private cls _cls; /// /// The uuid of the object this message is associated with /// public virtual string obj_uuid { get { return _obj_uuid; } set { if (!Helper.AreEqual(value, _obj_uuid)) { _obj_uuid = value; NotifyPropertyChanged("obj_uuid"); } } } private string _obj_uuid = ""; /// /// The time at which the message was created /// [JsonConverter(typeof(XenDateTimeConverter))] public virtual DateTime timestamp { get { return _timestamp; } set { if (!Helper.AreEqual(value, _timestamp)) { _timestamp = value; NotifyPropertyChanged("timestamp"); } } } private DateTime _timestamp; /// /// The body of the message /// public virtual string body { get { return _body; } set { if (!Helper.AreEqual(value, _body)) { _body = value; NotifyPropertyChanged("body"); } } } private string _body = ""; } }