Пример #1
0
        public DDialog GetFullHistoryByUserId(long userId)
        {
            var user = Api.Users.Get(userId);
            DDialog dDialog = new DDialog(userId, user.FirstName + " " + user.LastName);

            int totalCount = 0;
            int offset = 0;
            int downloadCount = 30;

            IReadOnlyCollection<VkNet.Model.Message> dialog = null;
            bool ok = false;
            while (!ok)
            {
                try
                {
                    dialog = this.Api.Messages.GetHistory(userId, false, out totalCount,0,10);
                    ok = true;
                }
                catch (Exception e)
                {
                    ok = false;
                    Console.WriteLine("Error in download dialog " + dDialog.WithUsername + "offset: " + offset);
                }
            }
            bool isSended;
            foreach (var msg in dialog)
            {
                isSended = (msg.Type == VkNet.Enums.MessageType.Sended) ? true : false;
                dDialog.Add(new DMessage(msg.Body, (DateTime)msg.Date, isSended));
            }

            for (long i = dDialog.DMessages.Count; i < totalCount; i += downloadCount)
            {
                //It isn't good
                offset = (int)i;
                ok = false;
                while (!ok)
                {
                    try
                    {
                        dialog = this.Api.Messages.GetHistory(userId, false, out totalCount, offset, downloadCount);
                        ok = true;
                    }
                    catch (Exception e)
                    {
                        ok = false;
                        Console.WriteLine("Error in download dialog " + dDialog.WithUsername + "offset: " + offset);
                    }
                }
                foreach (var msg in dialog)
                {
                    isSended = (msg.Type == VkNet.Enums.MessageType.Sended) ? true : false;
                    dDialog.Add(new DMessage(msg.Body, (DateTime)msg.Date, isSended));
                }
            }

            return dDialog;
        }
Пример #2
0
 public static void SaveDialog(DDialog dialog)
 {
     DataContractSerializer formatter = new DataContractSerializer(typeof(DDialog));
     var settings = new XmlWriterSettings { Indent = true };
     using (XmlWriter xw = XmlWriter.Create(directory + "\\" + dialog.WithUsername + "-" + dialog.DMessages.Count + ".xml",settings))
     {
         formatter.WriteObject(xw, dialog);
     }
 }
 public void ShowDialog(DDialog dialog)
 {
     Console.WriteLine("Dialog with: " + dialog.WithUsername);
     foreach (var msg in dialog.GetDMessages())
     {
         Console.WriteLine("===================");
         Console.WriteLine("Text: " + msg.Text);
         Console.WriteLine("Date: " + msg.Date);
         Console.WriteLine("My: " + msg.IsSended);
     }
 }