public void TestMaterializeAdd() { TagPrimitiveCollection collection = new TagPrimitiveCollection(); int firstTagID = 1236; int secondTagID = 76409; Expression<Func<long, TagPrimitive>> materializeFirstTag = tagID => GetTag(firstTagID); Expression<Func<long, TagPrimitive>> materializeSecondTag = tagID => GetTag(secondTagID); TagPrimitive firstTag = new TagPrimitive(firstTagID, materializeFirstTag); TagPrimitive secondTag = new TagPrimitive(secondTagID, materializeSecondTag); collection.AddTag(firstTag); collection.AddTag(secondTag); Assert.AreEqual(2, collection.Count); TagPrimitive firstRetrievedTag = collection.GetTag(firstTagID); Assert.AreEqual(firstTag.ID, firstRetrievedTag.ID); StringAssert.IsMatch(firstTag.Text, firstRetrievedTag.Text); TagPrimitive secondRetrievedTag = collection.GetTag(secondTagID); Assert.AreEqual(secondTag.ID, secondRetrievedTag.ID); StringAssert.IsMatch(secondTag.Text, secondRetrievedTag.Text); }
public void TestGetEnumerator() { TagPrimitiveCollection collection = new TagPrimitiveCollection(); const int firstTagID = 1236; const int secondTagID = 76409; TagPrimitive firstTag = new TagPrimitive(firstTagID, "tag_1236"); TagPrimitive secondTag = new TagPrimitive(secondTagID, "tag_654709"); collection.AddTag(firstTag); collection.AddTag(secondTag); Assert.AreEqual(2, collection.Count); foreach (TagPrimitive tagPrimitive in collection) { switch (tagPrimitive.ID) { case firstTagID: case secondTagID: continue; default: Assert.Fail(string.Format("TagID = [{0}] shouldn't be in collection", tagPrimitive.ID)); break; } } }
internal TagPrimitiveCollection ParseExportTagsMessage(string message) { TagPrimitiveCollection toReturn = new TagPrimitiveCollection(); XDocument messageDocument = XDocument.Parse(message); XElement tagsElement = GetTagsElement(messageDocument.Root); IEnumerable<XElement> tagELements = GetTagElements(tagsElement); foreach (XElement tagElement in tagELements) { toReturn.AddTag(ParseTagElement(tagElement)); } return toReturn; }
public void TestClear() { TagPrimitiveCollection collection = new TagPrimitiveCollection(); TagPrimitive firstTag = new TagPrimitive(1236, "tag_1236"); TagPrimitive secondTag = new TagPrimitive(654709, "tag_654709"); collection.AddTag(firstTag); collection.AddTag(secondTag); Assert.AreEqual(2, collection.Count); collection.Clear(); Assert.AreEqual(0, collection.Count); }
public void AddToMyBox(string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList, OperationFinished<AddToMyBoxResponse> addToMyBoxCompleted, object userState);
public void AddToMyBox(long targetFileID, long destinationFolderID, TagPrimitiveCollection tagList, OperationFinished<AddToMyBoxResponse> addToMyBoxCompleted);
public AddToMyBoxStatus AddToMyBox(string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList);
public ExportTagsStatus ExportTags(out TagPrimitiveCollection tagList);
/// <summary> /// Retrieves list of user's tags /// </summary> /// <param name="tagList">List of user's tags</param> /// <returns>Operation status</returns> public ExportTagsStatus ExportTags(out TagPrimitiveCollection tagList) { byte[] xmlMessage; string result = _service.export_tags(_apiKey, _token, out xmlMessage); ExportTagsStatus status = StatusMessageParser.ParseExportTagStatus(result); tagList = MessageParser.Instance.ParseExportTagsMessage(Encoding.ASCII.GetString(xmlMessage)); return status; }
/// <summary> /// Asyncronously copies a file publicly shared by someone to a user's folder /// </summary> /// <param name="targetFileName">Name of the file which needs to be copied</param> /// <param name="destinationFolderID">ID of the destination folder</param> /// <param name="tagList">Tags which need to be assigned to the target file</param> /// <param name="addToMyBoxCompleted">Callback method which will be invoked after operation completes</param> /// <param name="userState">A user-defined object containing state information. /// This object is passed to the <paramref name="addToMyBoxCompleted"/> delegate as a part of response when the operation is completed</param> /// <exception cref="ArgumentException">Thrown if <paramref name="addToMyBoxCompleted"/> is null</exception> public void AddToMyBox( string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList, OperationFinished<AddToMyBoxResponse> addToMyBoxCompleted, object userState) { ThrowIfParameterIsNull(addToMyBoxCompleted, "addToMyBoxCompleted"); _service.add_to_myboxCompleted += AddToMyBoxFinished; object[] state = { addToMyBoxCompleted , userState}; _service.add_to_myboxAsync(_apiKey, _token, 0, targetFileName, destinationFolderID, ConvertTagPrimitiveCollection2String(tagList), state); }
/// <summary> /// Asyncronously copies a file publicly shared by someone to a user's folder /// </summary> /// <param name="targetFileName">Name of the file which needs to be copied</param> /// <param name="destinationFolderID">ID of the destination folder</param> /// <param name="tagList">Tags which need to be assigned to the target file</param> /// <param name="addToMyBoxCompleted">Callback method which will be invoked after operation completes</param> /// <exception cref="ArgumentException">Thrown if <paramref name="addToMyBoxCompleted"/> is null</exception> public void AddToMyBox( string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList, OperationFinished<AddToMyBoxResponse> addToMyBoxCompleted) { AddToMyBox(targetFileName, destinationFolderID, tagList, addToMyBoxCompleted, null); }
/// <summary> /// Copies a file publicly shared by someone to a user's folder /// </summary> /// <param name="targetFileName">Name of the file which needs to be copied</param> /// <param name="destinationFolderID">ID of the destination folder</param> /// <param name="tagList">Tags which need to be assigned to the target file</param> /// <returns>Operation status</returns> public AddToMyBoxStatus AddToMyBox( string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList) { string result = _service.add_to_mybox(_apiKey, _token, 0, targetFileName, destinationFolderID, ConvertTagPrimitiveCollection2String(tagList)); return StatusMessageParser.ParseAddToMyBoxStatus(result); }
private void GetTag(long id, OperationFinished<ExportTagsStatus, TagPrimitive> getTagFinishedHandler) { if (_tagCollection == null || _tagCollection.IsEmpty) { OperationFinished<ExportTagsResponse> exportTagsFinishedHandler = (response) => { _tagCollection = response.TagsList; getTagFinishedHandler(response.Status, response.TagsList.GetTag(id)); }; ExportTags(exportTagsFinishedHandler); } else { getTagFinishedHandler(ExportTagsStatus.Successful, _tagCollection.GetTag(id)); } }
/// <summary> /// Converts list of tags to comma-separated string which contains tags' IDs /// </summary> /// <param name="tagList">List of tags</param> /// <returns>Comma-separated string which contains tags' IDs</returns> private static string ConvertTagPrimitiveCollection2String(TagPrimitiveCollection tagList) { StringBuilder result = new StringBuilder(); foreach (TagPrimitive tag in tagList) { result.Append(tag.ID + ","); } if (result.Length > 0) { result.Remove(result.Length - 1, 1); } return result.ToString(); }