Ejemplo n.º 1
0
Archivo: Get.cs Proyecto: DnAp/VKDrive
        public static VFile WallPostToFolder(JObject jToken, bool isTop = false)
        {
            var wallPost = jToken.ToObject <SerializationObject.WallPost>();

            // Я хотел значек музыки или фотки засунуть если они есть в посте
            var folderName = wallPost.Text.Trim();

            var folder = new Folder("")
            {
                CreationTime  = wallPost.Date,
                LastWriteTime = wallPost.Date
            };

            JToken jArray;

            if (jToken.TryGetValue("copy_history", out jArray))
            {
                // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
                foreach (JObject historyItem in (JArray)jArray)
                {
                    if (isTop && folderName.Length == 0)
                    {
                        folderName = historyItem.GetValue("text").ToString().Trim();
                    }

                    var copyFolder = WallPostToFolder(historyItem);
                    folder.ChildsAdd(copyFolder);
                }
            }
            folder.FileName = VFile.ClearName(wallPost.Date.ToString("yyyy-MM-dd ") + folderName, false);
            if (wallPost.Text.Trim().Length > 0)
            {
                folder.ChildsAdd(new PlainText("Текст.txt", wallPost.Text.Trim()));
            }
            //folder.ChildsAdd(new PlainText("debug.json", jToken.ToString()));

            if (jToken.TryGetValue("attachments", out jArray))
            {
                // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
                foreach (var attachFile in (JArray)jArray)
                {
                    folder.ChildsAdd(ConvertAttachToFile((JObject)attachFile));
                }
            }
            folder.IsLoaded = true;
            return(folder);
        }