/// <summary> /// Maps the subscription. /// </summary> /// <param name="subscription">The subscription.</param> /// <param name="drop">The drop.</param> /// <param name="node">The node.</param> protected void MapSubscription(Drop drop, Subscription subscription, XmlNode node) { subscription.Id = this.ExtractInt(node, "id"); //subscription.Message = this.ExtractInnerText(node, "message"); subscription.Type = this.ExtractInnerText(node, "type"); //subscription.Username = this.ExtractInnerText(node, "username"); subscription.Url = this.ExtractInnerText(node, "url"); subscription.Drop = drop; }
public Asset AddFile(Drop drop, HttpPostedFile file, string description, string conversion, string pingbackUrl, string outputLocations ) { return this.ServiceAdapter.AddFileInit (drop, file, description, conversion, pingbackUrl, outputLocations ); }
/// <summary>Moves the asset to the given drop.</summary> /// <param name="targetDrop">The target drop.</param> /// <returns>A <see cref="bool"/> indicating the success of the move</returns> public bool MoveTo(Drop targetDrop) { return ServiceProxy.Instance.MoveAsset (this, targetDrop); }
/// <summary> /// Finds the subscriptions. /// </summary> /// <param name="drop"> /// The drop. /// </param> /// <param name="page"> /// The page. /// </param> /// <returns> /// /// </returns> public List<Subscription> FindSubscriptions(Drop drop, int page) { return this.ServiceAdapter.FindSubscriptions(drop,page); }
/// <summary> /// Moves the asset to the given drop. /// </summary> /// <param name="asset">The asset.</param> /// <param name="targetDrop">The target drop.</param> /// <returns></returns> public bool MoveAsset(Asset asset, Drop targetDrop) { return this.ServiceAdapter.CopyAsset(asset, targetDrop, false); }
/// <summary> /// Deletes the drop. /// </summary> /// <param name="drop">The drop.</param> /// <returns></returns> public bool DestroyDrop(Drop drop) { return this.ServiceAdapter.DestroyDrop(drop); }
/// <summary> /// Finds the asset. /// </summary> /// <param name="drop">The drop.</param> /// <param name="assetId">The asset id.</param> /// <returns></returns> public Asset FindAsset(Drop drop, string assetId) { return this.ServiceAdapter.FindAsset(drop, assetId); }
/// <summary> /// Empties a drop of all assets /// </summary> /// <param name="drop">The <see cref="Drop"/> to be emptied</param> /// <returns></returns> public bool EmptyDrop(Drop drop) { // can't do much if we don't have a drop to act on... if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); // bool to return bool emptied = false; // do request and change "emptied" to true if request succeeds HttpWebRequest request = this.CreatePutRequest(this.CreateEmptyDropUrl(drop.Name), new Hashtable() ); CompleteRequest(request, (HttpWebResponse response) => { emptied = true; }); if( emptied == true ) drop.AssetCount = 0; return emptied; }
/// <summary> /// Finds an asset. /// </summary> /// <param name="drop"></param> /// <param name="name">The asset name.</param> /// <returns></returns> public Asset FindAsset(Drop drop, string assetId) { // we can't do much without a drop or asset ID... if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); if (assetId == null) throw new ArgumentNullException("assetId", "The given asset ID can't be null"); // asset object to return Asset a = null; // do the request HttpWebRequest request = this.CreateUrlEncodedRequest("GET", this.CreateAssetUrl(drop.Name, assetId, string.Empty)); CompleteRequest(request, delegate(HttpWebResponse response) { ReadResponse(response, delegate(XmlDocument doc) { // read the XML response into the Asset object XmlNode node = doc.SelectSingleNode( "/asset"); a = this.CreateAndMapAsset(drop, node); }); }); return a; }
/// <summary> /// Creates a pingback subscription. When the events happen, the url will be sent a POST request with the pertinent data. /// </summary> /// <param name="drop">The drop.</param> /// <param name="url">The url.</param> /// <param name="events"> The events. </param> /// <returns></returns> public Subscription CreatePingbackSubscription(Drop drop, string url, AssetEvents events) { if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); Subscription s = null; Hashtable parameters = new Hashtable(); parameters.Add("type", "pingback"); parameters.Add("url", url); parameters.Add("asset_created", ((events & AssetEvents.AssetCreated) == AssetEvents.AssetCreated).ToString().ToLower()); parameters.Add("asset_udpated", ((events & AssetEvents.AssetUpdated) == AssetEvents.AssetUpdated).ToString().ToLower()); parameters.Add("asset_deleted", ((events & AssetEvents.AssetDeleted) == AssetEvents.AssetDeleted).ToString().ToLower()); parameters.Add("job_started", ((events & AssetEvents.JobStarted) == AssetEvents.JobStarted).ToString().ToLower()); parameters.Add("job_complete", ((events & AssetEvents.JobComplete) == AssetEvents.JobComplete).ToString().ToLower()); parameters.Add("job_progress", ((events & AssetEvents.JobProgress) == AssetEvents.JobProgress).ToString().ToLower()); HttpWebRequest request = this.CreatePostRequest(this.CreateSubscriptionsUrl(drop.Name), parameters); CompleteRequest(request, delegate(HttpWebResponse response) { ReadResponse(response, delegate(XmlDocument doc) { XmlNode node = doc.SelectSingleNode("/subscription"); s = this.CreateAndMapSubscription(drop, node); }); }); return s; }
/// <summary> /// Deletes the drop. /// </summary> /// <param name="drop">The drop.</param> /// <returns></returns> public bool DestroyDrop(Drop drop) { // can't do much if we don't have a drop to act on... if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); // bool to return bool destroyed = false; // do request and change "destroyed" to true if request succeeds HttpWebRequest request = this.CreateUrlEncodedRequest("DELETE",this.CreateDropUrl(drop.Name), new Hashtable() ); CompleteRequest(request, (HttpWebResponse response) => { destroyed = true; }); if( destroyed == true ) { // empty the drop *object* so that actions cannot be performed on it (since the drop it represents no // longer exists). Just setting it to null doesn't work (it doesn't overwrite the object being passed // in, so once we return we are back to the object that we orginially passed in. drop.AssetCount = 0; drop.ChatPassword = string.Empty; drop.CurrentBytes = 0; drop.Description = string.Empty; drop.Email = string.Empty; drop.MaxBytes = 0; drop.Name = string.Empty; } return destroyed; }
/// <summary> /// /// </summary> /// <param name="asset"> /// A <see cref="Asset"/> /// </param> /// <param name="dropName"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> public bool CopyAsset(Asset asset, Drop drop, bool keepOriginal) { if (asset == null) throw new ArgumentNullException("asset", "The given asset can't be null"); if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); bool copied = false; Hashtable parameters = new Hashtable(); parameters.Add("drop_name", drop.Name); HttpWebRequest request = this.CreatePostRequest(this.CreateAssetUrl(asset.Drop.Name, asset.Id, keepOriginal == true ? COPY : MOVE ), parameters); CompleteRequest(request, (HttpWebResponse response) => { copied = true; }); if( copied == true ) { // increase asset count by 1 if the asset was copied sucessfully Console.WriteLine( "yo..."); drop.AssetCount++; } if( keepOriginal == false ) { // we moved (not copied) so decrease assets count on drop that asset was moved from asset.Drop.AssetCount--; } return copied; }
public Asset AddFileInit(Drop drop, HttpPostedFile file, string description, string conversion, string pingbackUrl, string outputLocations ) { // get the name of the file string fileName = file.FileName; // length of file in bytes long fileLength = (long)file.ContentLength; // create Stream object for file access Stream fs = file.InputStream; return this.AddFile (drop, fileName, description, fileLength, fs, conversion, pingbackUrl, outputLocations); }
public Asset AddFileInit(Drop drop, string file, string description, string conversion, string pingbackUrl, string outputLocations ) { // get the name of the file string fileName = Path.GetFileName (file); // length of file in bytes long fileLength = new FileInfo (file).Length; // create Stream object for file access Stream fs = new FileStream (file, FileMode.Open, FileAccess.Read); return this.AddFile (drop, fileName, description, fileLength, fs, conversion, pingbackUrl, outputLocations); }
/// <summary> /// Copies the asset to the given drop and returns the new asset. /// </summary> /// <param name="asset">The asset.</param> /// <param name="targetDrop">The target drop.</param> /// <returns></returns> public bool CopyAsset(Asset asset, Drop targetDrop) { return this.ServiceAdapter.CopyAsset(asset, targetDrop, true); }
/// <summary> /// Finds the assets for a given drop. /// </summary> /// <param name="drop">The drop.</param> /// <param name="page">The page.</param> /// <param name="order">The order.</param> /// <returns></returns> public List<Asset> FindAssets(Drop drop, int page, Order order) { // can't do much without a drop to act on if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); // the Asset list to return List<Asset> assets = new List<Asset>(); // create a new hashtable and add the passed in parameters Hashtable parameters = new Hashtable(); parameters.Add( "page", page.ToString() ); parameters.Add( "order", (order == Order.Newest ) ? "latest" : "oldest" ); // do the request HttpWebRequest request = this.CreateUrlEncodedRequest("GET", this.CreateAssetUrl(drop.Name, string.Empty, string.Empty), parameters); CompleteRequest(request, delegate(HttpWebResponse response) { ReadResponse(response, delegate(XmlDocument doc) { // get all the asset XML nodes, load each one into an Asset object and load into the Asset list XmlNodeList nodes = doc.SelectNodes("//assets/asset"); foreach (XmlNode node in nodes) { Asset a = this.CreateAndMapAsset(drop, node); assets.Add(a); } }); }); return assets; }
/// <summary> /// Creates a pingback subscription. When the events happen, the url will be sent a POST request with the pertinent data. /// </summary> /// <param name="drop">The drop.</param> /// <param name="url">The url.</param> /// <param name="events"> The events. </param> /// <returns></returns> public Subscription CreatePingbackSubscription(Drop drop, string url, AssetEvents events) { return this.ServiceAdapter.CreatePingbackSubscription(drop, url, events); }
/// <summary> /// Finds the subscriptions. /// </summary> /// <param name="drop">The drop.</param> /// <param name="page">The page.</param> /// <returns></returns> public List<Subscription> FindSubscriptions(Drop drop, int page) { if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); List<Subscription> subscriptions = new List<Subscription>(); Hashtable parameters = new Hashtable(); parameters.Add( "page", page.ToString() ); HttpWebRequest request = this.CreateUrlEncodedRequest("GET", this.CreateSubscriptionsUrl(drop.Name), parameters ); CompleteRequest(request, delegate(HttpWebResponse response) { ReadResponse(response, delegate(XmlDocument doc) { XmlNodeList nodes = doc.SelectNodes("/subscriptions/subscription"); foreach (XmlNode node in nodes) { Subscription s = this.CreateAndMapSubscription(drop, node); subscriptions.Add(s); } }); }); return subscriptions; }
/// <summary> /// Empty the drop of all assets /// </summary> /// <param name="drop"> /// A <see cref="Drop"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> public bool EmptyDrop(Drop drop) { return this.ServiceAdapter.EmptyDrop(drop); }
public string GetUploadifyForm(Drop drop, Hashtable uploadifyOptions) { Hashtable parameters = new Hashtable (); AddCommonParameters (ref parameters); parameters.Add ("drop_name", drop.Name); StringBuilder sb = new StringBuilder (); sb.AppendLine ("<script type=\"text/javascript\" src=\"uploadify/jquery-1.3.2.min.js\"></script>"); sb.AppendLine ("<script type=\"text/javascript\" src=\"uploadify/swfobject.js\"></script>"); sb.AppendLine ("<script type=\"text/javascript\" src=\"uploadify/jquery.uploadify.v2.1.0.min.js\"></script>"); sb.AppendLine ("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen, projection\" href=\"uploadify/uploadify.css\" />"); sb.AppendLine ("<script type=\"text/javascript\">// <![CDATA["); sb.AppendLine ("$(document).ready(function() {"); sb.AppendLine ("$('#file').uploadify({"); // UPLOADER if ((uploadifyOptions != null) && uploadifyOptions.Contains ("uploader")) { sb.AppendLine ("'uploader':" + uploadifyOptions["uploader"] + ","); uploadifyOptions.Remove ("uploader"); } else sb.AppendLine ("'uploader':'uploadify/uploadify.swf',"); // SCRIPT if ((uploadifyOptions != null) && uploadifyOptions.Contains ("script")) { sb.AppendLine ("'script':" + uploadifyOptions["script"] + ","); uploadifyOptions.Remove ("script"); } else sb.AppendLine ("'script':'" + this.UploadUrl + "',"); // MULTI if ((uploadifyOptions != null) && uploadifyOptions.Contains ("multi")) { sb.AppendLine ("'multi':" + uploadifyOptions["multi"] + ","); uploadifyOptions.Remove ("multi"); } else sb.AppendLine ("'multi':true,"); // SCRIPTDATA if ((uploadifyOptions != null) && uploadifyOptions.Contains ("scriptData")) { // scriptData should be a Hashtable if( uploadifyOptions["scriptData"].GetType() == typeof(Hashtable) ) { Hashtable scriptData = (Hashtable)uploadifyOptions["scriptData"]; foreach( string data in scriptData.Keys) { parameters.Add( data, scriptData[data]); } } sb.Append( "'scriptData': ").AppendLine( ToJson(parameters) + "," ); uploadifyOptions.Remove ("scriptData"); } else sb.Append ("'scriptData': ").AppendLine (ToJson (parameters) + ","); // CANCELIMG if ((uploadifyOptions != null) && uploadifyOptions.Contains ("cancelImg")) { sb.AppendLine ("'cancelImg':" + uploadifyOptions["cancelImg"] + ","); uploadifyOptions.Remove ("cancelImg"); } else sb.AppendLine ("'cancelImg':'uploadify/cancel.png',"); // AUTO if ((uploadifyOptions != null) && uploadifyOptions.Contains ("auto")) { sb.AppendLine ("'auto':" + uploadifyOptions["auto"] + ","); uploadifyOptions.Remove ("auto"); } else sb.AppendLine ("'auto':true,"); // add any other options that don't have default options if (uploadifyOptions != null) { foreach (object obj in uploadifyOptions.Keys) { sb.AppendLine ("'" + obj + "':" + uploadifyOptions[obj] + ","); } } // ONCOMPLETE //sb.AppendLine ("'onComplete' : function(event, queueID, fileObj, response, data){ alert('all done'); }"); sb.AppendLine ("});"); sb.AppendLine ("});"); sb.AppendLine ("// ]]></script>"); return sb.ToString (); }
/// <summary> /// Finds the assets. /// </summary> /// <param name="drop">The drop.</param> /// <param name="page">The page.</param> /// <param name="order">The order.</param> /// <returns></returns> public List<Asset> FindAssets(Drop drop, int page, Order order) { return this.ServiceAdapter.FindAssets(drop, page, order); }
/// <summary> /// Updates the drop. /// </summary> /// <param name="drop">The drop.</param> /// <param name="name"></param> /// <param name="chatPassword"></param> /// <returns></returns> //public bool UpdateDrop (Drop drop, string newName, string newDescription, string newChatPassword, int newMaxSize) public bool UpdateDrop(Drop drop, string newName ) { // can't do much if we don't have a drop to act on... if (drop == null) throw new ArgumentNullException("drop", "The given drop can't be null"); Hashtable parameters = new Hashtable(); if ( !string.IsNullOrEmpty( newName )) { // we are updating just the name parameters.Add( "name", newName ); } else { // we are updating anything but name parameters.Add( "description", drop.Description ); parameters.Add( "chat_password", drop.ChatPassword ); parameters.Add( "max_size", drop.MaxBytes.ToString() ); } // bool to return bool updated = false; // do the request and change updated to "true" if request succeeded HttpWebRequest request = this.CreatePutRequest(this.CreateDropUrl(drop.Name), parameters); CompleteRequest(request, delegate(HttpWebResponse response) { // the response includes the updated drop information, load it into the drop object we passed ReadResponse(response, (XmlDocument doc) => this.MapDrop(drop, doc.SelectSingleNode("drop"))); updated = true; }); return updated; }
/// <summary> /// Gets an uploadify form /// </summary> /// <param name="drop"> /// A <see cref="Drop"/> /// </param> /// <param name="uploadifyOptions"> /// A <see cref="Hashtable"/> /// </param> /// <returns> /// A <see cref="System.String"/> /// </returns> public string GetUploadifyForm(Drop drop, Hashtable uploadifyOptions) { return this.ServiceAdapter.GetUploadifyForm (drop, uploadifyOptions); }
/// <summary> /// Creates the and map asset. /// </summary> /// <param name="d">The d.</param> /// <param name="node">The node.</param> /// <returns></returns> protected Asset CreateAndMapAsset(Drop d, XmlNode node) { Asset a = new Asset(); this.MapAsset(a, d, node); return a; }
/// <summary> /// Updates the drop. /// </summary> /// <param name="drop"> /// The drop. /// </param> /// <param name="name"> /// /// </param> /// <param name="chatPassword"> /// /// </param> /// <returns> /// /// </returns> // public bool UpdateDrop(Drop drop, string newName, string newDescription, string newChatPassword, int newMaxSize) public bool UpdateDrop(Drop drop, string newName ) { return this.ServiceAdapter.UpdateDrop(drop, newName ); }
/// <summary> /// Creates and maps a drop. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected Drop CreateAndMapDrop(XmlNode node) { Drop d = new Drop(); this.MapDrop(d, node); return d; }
/// <summary>Copies the asset to the given drop and returns the new asset.</summary> /// <param name="targetDrop">The target drop.</param> /// <returns>a <see cref="bool"/> indicating the success of the copy</returns> public bool CopyTo(Drop targetDrop) { return ServiceProxy.Instance.CopyAsset(this, targetDrop); }
/// <summary> /// Creates the and map subscription. /// </summary> /// <param name="d">The d.</param> /// <param name="node">The node.</param> /// <returns></returns> protected Subscription CreateAndMapSubscription(Drop d, XmlNode node) { Subscription s = new Subscription(); this.MapSubscription(d, s, node); return s; }
/// <summary>Finds the specified asset name.</summary> /// <param name="drop">A <see cref="Drop"/> object containing the drop in which to retrieve the asset</param> /// <param name="name">A <see cref="string"/> object specifying the ID of the asset to get</param> /// <returns>An <see cref="Asset"/> object of the returned asset</param> /// <exception cref="Dropio.Core.ServiceException">Thrown when the asset does not exist</exception> /// </returns> public static Asset Find(Drop drop, string assetId) { return ServiceProxy.Instance.FindAsset(drop, assetId); }
/// <summary> /// Maps the drop. /// </summary> /// <param name="d">The d.</param> /// <param name="node">The doc.</param> /// <returns></returns> protected void MapDrop(Drop d, XmlNode node) { XmlNode dropNode = node; d.Name = this.ExtractInnerText(dropNode, "name"); d.AssetCount = this.ExtractInt(dropNode, "asset_count"); d.CurrentBytes = this.ExtractInt(dropNode, "current_bytes"); d.MaxBytes = this.ExtractInt(dropNode, "max_bytes"); d.Email = this.ExtractInnerText(dropNode, "email"); d.Description = this.ExtractInnerText(dropNode, "description"); d.ChatPassword = this.ExtractInnerText(dropNode, "chat_password"); }