示例#1
0
        public ChatService()
        {
            users = new Dictionary <string, User>();
            emailAddressToUserId = new Dictionary <string, string>();
            friends       = new Dictionary <string, List <string> >();
            photoRecords  = new List <PhotoRecord>();
            photoContents = new Dictionary <string, PhotoContent>();

            // Timer to expire any photos that were read more than
            // 30 seconds ago
            timer = new Timer(new TimerCallback((o) =>
            {
                List <PhotoRecord> expired = photoRecords
                                             .Where((p) =>
                {
                    return((p.Received != new DateTimeOffset()) &&
                           (DateTimeOffset.Now - p.Received > TimeSpan.FromSeconds(5)));
                })
                                             .ToList();
                expired.ForEach((p) =>
                {
                    p.Expired = true;

                    PhotoContent content = null;
                    if (photoContents.TryGetValue(p.PhotoContentSecretId, out content))
                    {
                        DeletePhotoContent(content.SecretId);
                    }
                });
            }),
                              null,
                              TimeSpan.FromSeconds(0),
                              TimeSpan.FromSeconds(1));
        }
示例#2
0
        public Task CreatePhotoRecordAsync(PhotoRecord record)
        {
            PhotoContent content = new PhotoContent();

            content.SecretId = Guid.NewGuid().ToString();
            content.Uri      = new Uri(String.Format("http://{0}", Guid.NewGuid()));
            photoContents[content.SecretId] = content;
            content.Id = photoContents.Count - 1;

            photoRecords.Add(record);
            record.Id                   = photoRecords.IndexOf(record);
            record.Sent                 = DateTimeOffset.Now;
            record.SenderName           = App.CurrentUser.Name;
            record.SenderUserId         = App.CurrentUser.UserId;
            record.PhotoContentSecretId = content.SecretId;
            record.Expired              = false;

            // These two are returned but not stored in the
            // datastore, we delete them later
            record.UploadKey = String.Empty; // Doesn't matter in this case
            record.Uri       = content.Uri;

            content.PhotoRecordId = record.Id;

            return(Task.FromResult(0));
        }
示例#3
0
        public Task <ObservableCollection <PhotoContent> > ReadPhotoContentAsync(string id)
        {
            PhotoContent content = null;

            if (photoContents.TryGetValue(id, out content))
            {
                PhotoRecord record = photoRecords[content.PhotoRecordId];
                record.Received = DateTimeOffset.Now;
            }

            ObservableCollection <PhotoContent> wrapper = new ObservableCollection <PhotoContent>();

            wrapper.Add(content);
            return(Task.FromResult <ObservableCollection <PhotoContent> >(wrapper));
        }
示例#4
0
        public Task CreatePhotoRecordAsync(PhotoRecord record)
        {
            PhotoContent content = new PhotoContent();
            content.SecretId = Guid.NewGuid().ToString();
            content.Uri = new Uri(String.Format("http://{0}", Guid.NewGuid()));
            photoContents[content.SecretId] = content;
            content.Id = photoContents.Count - 1;

            photoRecords.Add(record);
            record.Id = photoRecords.IndexOf(record);
            record.Sent = DateTimeOffset.Now;
            record.SenderName = App.CurrentUser.Name;
            record.SenderUserId = App.CurrentUser.UserId;
            record.PhotoContentSecretId = content.SecretId;
            record.Expired = false;

            // These two are returned but not stored in the
            // datastore, we delete them later
            record.UploadKey = String.Empty; // Doesn't matter in this case
            record.Uri = content.Uri;

            content.PhotoRecordId = record.Id;

            return Task.FromResult(0);
        }