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;
                }
            }
        }
예제 #3
0
        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);
        }
예제 #5
0
 public void AddToMyBox(string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList, OperationFinished<AddToMyBoxResponse> addToMyBoxCompleted, object userState);
예제 #6
0
 public void AddToMyBox(long targetFileID, long destinationFolderID, TagPrimitiveCollection tagList, OperationFinished<AddToMyBoxResponse> addToMyBoxCompleted);
예제 #7
0
 public AddToMyBoxStatus AddToMyBox(string targetFileName, long destinationFolderID, TagPrimitiveCollection tagList);
예제 #8
0
 public ExportTagsStatus ExportTags(out TagPrimitiveCollection tagList);
예제 #9
0
        /// <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;
        }
예제 #10
0
        /// <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);
        }
예제 #11
0
 /// <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);
 }
예제 #12
0
        /// <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);
        }
예제 #13
0
        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));
            }
        }
예제 #14
0
        /// <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();
        }