/*
* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* 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 Newtonsoft.Json;
namespace XenAPI
{
///
/// A placeholder for a binary blob
/// First published in XenServer 5.0.
///
public partial class Blob : XenObject
{
#region Constructors
public Blob()
{
}
public Blob(string uuid,
string name_label,
string name_description,
long size,
bool pubblic,
DateTime last_updated,
string mime_type)
{
this.uuid = uuid;
this.name_label = name_label;
this.name_description = name_description;
this.size = size;
this.pubblic = pubblic;
this.last_updated = last_updated;
this.mime_type = mime_type;
}
///
/// Creates a new Blob from a Hashtable.
/// Note that the fields not contained in the Hashtable
/// will be created with their default values.
///
///
public Blob(Hashtable table)
: this()
{
UpdateFrom(table);
}
///
/// Creates a new Blob from a Proxy_Blob.
///
///
public Blob(Proxy_Blob proxy)
{
UpdateFrom(proxy);
}
#endregion
///
/// Updates each field of this instance with the value of
/// the corresponding field of a given Blob.
///
public override void UpdateFrom(Blob update)
{
uuid = update.uuid;
name_label = update.name_label;
name_description = update.name_description;
size = update.size;
pubblic = update.pubblic;
last_updated = update.last_updated;
mime_type = update.mime_type;
}
internal void UpdateFrom(Proxy_Blob proxy)
{
uuid = proxy.uuid == null ? null : proxy.uuid;
name_label = proxy.name_label == null ? null : proxy.name_label;
name_description = proxy.name_description == null ? null : proxy.name_description;
size = proxy.size == null ? 0 : long.Parse(proxy.size);
pubblic = (bool)proxy.pubblic;
last_updated = proxy.last_updated;
mime_type = proxy.mime_type == null ? null : proxy.mime_type;
}
public Proxy_Blob ToProxy()
{
Proxy_Blob result_ = new Proxy_Blob();
result_.uuid = uuid ?? "";
result_.name_label = name_label ?? "";
result_.name_description = name_description ?? "";
result_.size = size.ToString();
result_.pubblic = pubblic;
result_.last_updated = last_updated;
result_.mime_type = mime_type ?? "";
return result_;
}
///
/// Given a Hashtable with field-value pairs, it updates the fields of this Blob
/// 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_label"))
name_label = Marshalling.ParseString(table, "name_label");
if (table.ContainsKey("name_description"))
name_description = Marshalling.ParseString(table, "name_description");
if (table.ContainsKey("size"))
size = Marshalling.ParseLong(table, "size");
if (table.ContainsKey("pubblic"))
pubblic = Marshalling.ParseBool(table, "pubblic");
if (table.ContainsKey("last_updated"))
last_updated = Marshalling.ParseDateTime(table, "last_updated");
if (table.ContainsKey("mime_type"))
mime_type = Marshalling.ParseString(table, "mime_type");
}
public bool DeepEquals(Blob other)
{
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return Helper.AreEqual2(this._uuid, other._uuid) &&
Helper.AreEqual2(this._name_label, other._name_label) &&
Helper.AreEqual2(this._name_description, other._name_description) &&
Helper.AreEqual2(this._size, other._size) &&
Helper.AreEqual2(this._pubblic, other._pubblic) &&
Helper.AreEqual2(this._last_updated, other._last_updated) &&
Helper.AreEqual2(this._mime_type, other._mime_type);
}
internal static List ProxyArrayToObjectList(Proxy_Blob[] input)
{
var result = new List();
foreach (var item in input)
result.Add(new Blob(item));
return result;
}
public override string SaveChanges(Session session, string opaqueRef, Blob server)
{
if (opaqueRef == null)
{
System.Diagnostics.Debug.Assert(false, "Cannot create instances of this type on the server");
return "";
}
else
{
if (!Helper.AreEqual2(_name_label, server._name_label))
{
Blob.set_name_label(session, opaqueRef, _name_label);
}
if (!Helper.AreEqual2(_name_description, server._name_description))
{
Blob.set_name_description(session, opaqueRef, _name_description);
}
return null;
}
}
///
/// Get a record containing the current state of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static Blob get_record(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_record(session.opaque_ref, _blob);
else
return new Blob(session.proxy.blob_get_record(session.opaque_ref, _blob ?? "").parse());
}
///
/// Get a reference to the blob instance with the specified UUID.
/// First published in XenServer 5.0.
///
/// The session
/// UUID of object to return
public static XenRef get_by_uuid(Session session, string _uuid)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_by_uuid(session.opaque_ref, _uuid);
else
return XenRef.Create(session.proxy.blob_get_by_uuid(session.opaque_ref, _uuid ?? "").parse());
}
///
/// Get all the blob instances with the given label.
/// First published in XenServer 5.0.
///
/// The session
/// label of object to return
public static List> get_by_name_label(Session session, string _label)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_by_name_label(session.opaque_ref, _label);
else
return XenRef.Create(session.proxy.blob_get_by_name_label(session.opaque_ref, _label ?? "").parse());
}
///
/// Get the uuid field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static string get_uuid(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_uuid(session.opaque_ref, _blob);
else
return session.proxy.blob_get_uuid(session.opaque_ref, _blob ?? "").parse();
}
///
/// Get the name/label field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static string get_name_label(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_name_label(session.opaque_ref, _blob);
else
return session.proxy.blob_get_name_label(session.opaque_ref, _blob ?? "").parse();
}
///
/// Get the name/description field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static string get_name_description(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_name_description(session.opaque_ref, _blob);
else
return session.proxy.blob_get_name_description(session.opaque_ref, _blob ?? "").parse();
}
///
/// Get the size field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static long get_size(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_size(session.opaque_ref, _blob);
else
return long.Parse(session.proxy.blob_get_size(session.opaque_ref, _blob ?? "").parse());
}
///
/// Get the public field of the given blob.
/// First published in XenServer 6.1.
///
/// The session
/// The opaque_ref of the given blob
public static bool get_public(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_public(session.opaque_ref, _blob);
else
return (bool)session.proxy.blob_get_public(session.opaque_ref, _blob ?? "").parse();
}
///
/// Get the last_updated field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static DateTime get_last_updated(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_last_updated(session.opaque_ref, _blob);
else
return session.proxy.blob_get_last_updated(session.opaque_ref, _blob ?? "").parse();
}
///
/// Get the mime_type field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static string get_mime_type(Session session, string _blob)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_mime_type(session.opaque_ref, _blob);
else
return session.proxy.blob_get_mime_type(session.opaque_ref, _blob ?? "").parse();
}
///
/// Set the name/label field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
/// New value to set
public static void set_name_label(Session session, string _blob, string _label)
{
if (session.JsonRpcClient != null)
session.JsonRpcClient.blob_set_name_label(session.opaque_ref, _blob, _label);
else
session.proxy.blob_set_name_label(session.opaque_ref, _blob ?? "", _label ?? "").parse();
}
///
/// Set the name/description field of the given blob.
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
/// New value to set
public static void set_name_description(Session session, string _blob, string _description)
{
if (session.JsonRpcClient != null)
session.JsonRpcClient.blob_set_name_description(session.opaque_ref, _blob, _description);
else
session.proxy.blob_set_name_description(session.opaque_ref, _blob ?? "", _description ?? "").parse();
}
///
/// Set the public field of the given blob.
/// First published in XenServer 6.1.
///
/// The session
/// The opaque_ref of the given blob
/// New value to set
public static void set_public(Session session, string _blob, bool _public)
{
if (session.JsonRpcClient != null)
session.JsonRpcClient.blob_set_public(session.opaque_ref, _blob, _public);
else
session.proxy.blob_set_public(session.opaque_ref, _blob ?? "", _public).parse();
}
///
/// Create a placeholder for a binary blob
/// First published in XenServer 5.0.
///
/// The session
/// The mime-type of the blob. Defaults to 'application/octet-stream' if the empty string is supplied
public static XenRef create(Session session, string _mime_type)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_create(session.opaque_ref, _mime_type);
else
return XenRef.Create(session.proxy.blob_create(session.opaque_ref, _mime_type ?? "").parse());
}
///
/// Create a placeholder for a binary blob
/// First published in XenServer 5.0.
///
/// The session
/// The mime-type of the blob. Defaults to 'application/octet-stream' if the empty string is supplied
/// True if the blob should be publicly available First published in XenServer 6.1.
public static XenRef create(Session session, string _mime_type, bool _public)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_create(session.opaque_ref, _mime_type, _public);
else
return XenRef.Create(session.proxy.blob_create(session.opaque_ref, _mime_type ?? "", _public).parse());
}
///
///
/// First published in XenServer 5.0.
///
/// The session
/// The opaque_ref of the given blob
public static void destroy(Session session, string _blob)
{
if (session.JsonRpcClient != null)
session.JsonRpcClient.blob_destroy(session.opaque_ref, _blob);
else
session.proxy.blob_destroy(session.opaque_ref, _blob ?? "").parse();
}
///
/// Return a list of all the blobs known to the system.
/// First published in XenServer 5.0.
///
/// The session
public static List> get_all(Session session)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_all(session.opaque_ref);
else
return XenRef.Create(session.proxy.blob_get_all(session.opaque_ref).parse());
}
///
/// Get all the blob Records at once, in a single XML RPC call
/// First published in XenServer 5.0.
///
/// The session
public static Dictionary, Blob> get_all_records(Session session)
{
if (session.JsonRpcClient != null)
return session.JsonRpcClient.blob_get_all_records(session.opaque_ref);
else
return XenRef.Create(session.proxy.blob_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;
Changed = true;
NotifyPropertyChanged("uuid");
}
}
}
private string _uuid = "";
///
/// a human-readable name
///
public virtual string name_label
{
get { return _name_label; }
set
{
if (!Helper.AreEqual(value, _name_label))
{
_name_label = value;
Changed = true;
NotifyPropertyChanged("name_label");
}
}
}
private string _name_label = "";
///
/// a notes field containing human-readable description
///
public virtual string name_description
{
get { return _name_description; }
set
{
if (!Helper.AreEqual(value, _name_description))
{
_name_description = value;
Changed = true;
NotifyPropertyChanged("name_description");
}
}
}
private string _name_description = "";
///
/// Size of the binary data, in bytes
///
public virtual long size
{
get { return _size; }
set
{
if (!Helper.AreEqual(value, _size))
{
_size = value;
Changed = true;
NotifyPropertyChanged("size");
}
}
}
private long _size;
///
/// True if the blob is publicly accessible
/// First published in XenServer 6.1.
///
public virtual bool pubblic
{
get { return _pubblic; }
set
{
if (!Helper.AreEqual(value, _pubblic))
{
_pubblic = value;
Changed = true;
NotifyPropertyChanged("pubblic");
}
}
}
private bool _pubblic = false;
///
/// Time at which the data in the blob was last updated
///
[JsonConverter(typeof(XenDateTimeConverter))]
public virtual DateTime last_updated
{
get { return _last_updated; }
set
{
if (!Helper.AreEqual(value, _last_updated))
{
_last_updated = value;
Changed = true;
NotifyPropertyChanged("last_updated");
}
}
}
private DateTime _last_updated;
///
/// The mime type associated with this object. Defaults to 'application/octet-stream' if the empty string is supplied
///
public virtual string mime_type
{
get { return _mime_type; }
set
{
if (!Helper.AreEqual(value, _mime_type))
{
_mime_type = value;
Changed = true;
NotifyPropertyChanged("mime_type");
}
}
}
private string _mime_type = "";
}
}