示例#1
0
        public SharableInfoPage(Sharable SelectedSharable)
        {
            StackLayout layout = new StackLayout();

            Label Name = new Label
            {
                Text = SelectedSharable.Name
            };

            layout.Children.Add(Name);

            Label Type = new Label
            {
                Text = SelectedSharable.Type
            };

            layout.Children.Add(Type);

            Label Periodicty = new Label
            {
                Text = SelectedSharable.Periodicity
            };

            layout.Children.Add(Periodicty);

            Label Price = new Label
            {
                Text = SelectedSharable.Price
            };

            layout.Children.Add(Price);

            Content = layout;
        }
示例#2
0
        protected async Task <IMailWriteReference> CreateWriteReference(
            string sender,
            CancellationToken token,
            IEnumerable <string> recipients,
            Func <string, string> getTempPathFromName,
            Func <string, string> getPathFromName)
        {
            IEnumerable <string> targetRecipients = recipients;

            string mailName = Guid.NewGuid().ToString("D");

            string tempPath   = getTempPathFromName(mailName);
            string targetPath = getPathFromName(mailName);

            // ReSharper disable AssignNullToNotNullAttribute
            Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
            Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
            // ReSharper restore AssignNullToNotNullAttribute

            using (Sharable <FileStream> shared =
                       Sharable.Create(File.Open(tempPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)))
            {
                FileStream           stream     = shared.Peek();
                IEnumerable <string> enumerable = targetRecipients.ToList();
                // Save room for header length
                using (var writer = new StreamWriter(stream, new UTF8Encoding(false), 1024, true))
                {
                    await writer.WriteLineAsync($"{HeaderLengthHeader}000000000");

                    await writer.WriteLineAsync($"FROM:{sender}");

                    foreach (string recipient in enumerable)
                    {
                        token.ThrowIfCancellationRequested();
                        await writer.WriteLineAsync($"TO:{recipient}");
                    }

                    await writer.FlushAsync();

                    var location = (int)stream.Position;
                    stream.Seek(0, SeekOrigin.Begin);
                    await writer.FlushAsync();

                    await writer.WriteLineAsync($"{HeaderLengthHeader}{location:D9}");

                    await writer.FlushAsync();

                    stream.Seek(location, SeekOrigin.Begin);
                }

                return(new WriteReference(
                           mailName,
                           tempPath,
                           targetPath,
                           sender,
                           enumerable,
                           new StreamSpan(shared.TakeValue()),
                           this));
            }
        }
示例#3
0
        public void ASharedArticleCreatesANewArticleReferingToTheOriginal()
        {
            Sharable sharable = new Sharable(
                // From
                "*****@*****.**",

                // To
                "*****@*****.**",

                // Article to create then share
                NullNormalized(a =>
            {
                a.Slug = "Article_Zero";
            })
                );

            // Share
            Article new_ = GetArticleLike(sharable);

            sharable.MergeWith(new_);

            // count before the operation
            int count1 = GetBlogArticlesCount(sharable.BlogDestin);

            // Operate
            Share shared = Wrapper.Share.ShareArticle(sharable, sharable.BlogDestin);

            // Count after the operation
            int count2 = GetBlogArticlesCount(sharable.BlogDestin);

            Assert.AreNotEqual(shared.BlogId, shared.SharingBlogId);
            Assert.AreNotEqual(count1, count2);
        }
示例#4
0
        public void ASharedArticleStaysUptoDate()
        {
            Sharable sharable = new Sharable(
                // From
                "*****@*****.**",

                // To
                "*****@*****.**",

                // Article to create then share
                NullNormalized(a =>
            {
                a.Title = "A Third Article, yupiie !!!";
                a.Slug  = "Third_Article";
            })
                );

            sharable.MergeWith(Wrapper.Article.CreateArticle(sharable));

            Share shared = Share(sharable, sharable.BlogDestin);

            // loop to create modifications over the third article
            LoopModify(sharable, contentUpdates[1]);

            Share resultedShare = Wrapper.Share.getShare(shared);
        }
示例#5
0
        public async Task <IMailReadReference> OpenReadAsync(IMailReference reference)
        {
            var mailReference = reference as IReference;

            if (mailReference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            using (var stream = Sharable.Create(File.OpenRead(mailReference.Path)))
            {
                string        sender;
                List <string> recipients = new List <string>();
                using (var reader = new StreamReader(stream.Peek(), Encoding.UTF8, false, 1024, true))
                {
                    var fromLine = await reader.ReadLineAsync();

                    if (!fromLine.StartsWith("FROM:"))
                    {
                        throw new FormatException("Invalid mail file format, expected FROM line");
                    }

                    sender = fromLine.Substring(5);

                    while (true)
                    {
                        var line = await reader.ReadLineAsync();

                        if (line.StartsWith("---"))
                        {
                            break;
                        }

                        if (line.StartsWith("TO:"))
                        {
                            recipients.Add(line.Substring(3));
                            continue;
                        }

                        throw new FormatException("Invalid mail file format, expected TO: line or Begin Message");
                    }
                }

                return(new ReadReference(sender, recipients, mailReference.Path, stream.TakeValue()));
            }
        }
示例#6
0
        public void AnArticleCannotBeAddTwice()
        {
            Sharable sharable = new Sharable(
                // From
                "*****@*****.**",

                // TO
                "*****@*****.**",

                // Article to create then share
                NullNormalized <Article>(a =>
            {
                a.Title = "should not be add twice article";
            })
                );

            Wrapper.Article.CreateArticle(sharable);

            Wrapper.Article.CreateArticle(sharable);
        }
        public void AShareGeneratesANotificationToTheAuthorOfTheArticle()
        {
            int     c1      = Wrapper.Notificaton.GetNotoficationsOf(JeanLucEmmanuel).Count;
            Blog    blog    = Wrapper.Blog.GetBlogOfAccount(JeanLucEmmanuel.Id);
            Article article =
                Wrapper.Article.CreateArticle(
                    NullNormalized <Article>(a =>
            {
                a.Content      = "Hi peeps";
                a.Title        = "Articling very spetial";
                a.Blog         = blog;
                a.VisibilityId = 1;
            })
                    );

            Sharable sharable = new Sharable(
                // From
                "*****@*****.**",

                // To
                "*****@*****.**",

                NullNormalized <Article>(a =>
            {
                a.Slug = article.Slug;
            })
                );

            // Share
            Article new_ = GetArticleLike(sharable);

            sharable.MergeWith(new_);

            // Operate
            Share shared = Wrapper.Share.ShareArticle(sharable, sharable.BlogDestin);

            int c2 = Wrapper.Notificaton.GetNotoficationsOf(JeanLucEmmanuel).Count;

            Assert.IsTrue(c1 + 1 == c2);
        }
示例#8
0
        public void AnAccountCanShareAnArticleOnItsBlog()
        {
            Sharable sharable = new Sharable(
                // From
                "*****@*****.**",

                // TO
                "*****@*****.**",

                // Article to create then share
                NullNormalized <Article>(a =>
            {
                a.Slug = "Article_After_Life";
            })
                );

            // Share
            Share shared = Share(sharable, sharable.BlogDestin);

            // Check
            Assert.AreNotEqual(sharable.BlogSource.Id, shared.Blog.Id);
        }
        private void AddNewItemToDatabase()
        {
            //Constructing "Sharable" table item
            Sharable TableItem = new Sharable
            {
                Name        = SharableName,
                Type        = sharableType,
                Periodicity = periodicity,
                Price       = Price
            };

            //Check existence of a table
            if (DBController.TableExists(nameof(Sharable)))
            {
                //Insertion table item into the table
                DBController.InsertItem(TableItem);
            }
            else
            {
                //Creation of a table then insertion item into it
                DBController.AddTable(TableItem);
                DBController.InsertItem(TableItem);
            }
        }
示例#10
0
        public async Task <IMailWriteReference> NewMailAsync(string sender, IEnumerable <string> recipients, CancellationToken token)
        {
            string mailName = Guid.NewGuid().ToString("D");

            string tempPath   = Path.Combine(Path.GetTempPath(), mailName);
            string targetPath = Path.Combine(_mailDirectory, mailName);

            using (var shared = Sharable.Create(File.Create(tempPath)))
            {
                IEnumerable <string> enumerable = recipients as IList <string> ?? recipients.ToList();
                using (var writer = new StreamWriter(shared.Peek(), Encoding.UTF8, 1024, true))
                {
                    await writer.WriteLineAsync($"FROM:{sender}");

                    foreach (var recipient in enumerable)
                    {
                        await writer.WriteLineAsync($"TO:{recipient}");
                    }
                    await writer.WriteLineAsync("--- BEGIN MESSAGE ---");
                }

                return(new WriteReference(tempPath, targetPath, sender, enumerable, new OffsetStream(shared.TakeValue())));
            }
        }
示例#11
0
        public async Task <IMailReadReference> OpenReadAsync(IMailReference reference, CancellationToken token)
        {
            var mailReference = reference as Reference;

            if (mailReference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            using (Sharable <FileStream> stream = Sharable.Create(File.OpenRead(mailReference.Path)))
            {
                string     sender;
                var        recipients = new List <string>();
                FileStream streamImpl = stream.Peek();
                // 23 ASCII characters, up to 1 GB in size, should be sufficient
                // Header-Legnth:000000000
                string headerSizeHeader = Encoding.ASCII.GetString(await streamImpl.ReadExactlyAsync(23, token));

                if (!headerSizeHeader.StartsWith(HeaderLengthHeader))
                {
                    throw new FormatException($"Invalid mail file format, expected {HeaderLengthHeader} line");
                }

                if (!int.TryParse(headerSizeHeader.Substring(HeaderLengthHeader.Length), out int headerSize) || headerSize <= 0)
                {
                    throw new FormatException($"Invalid mail file format, {HeaderLengthHeader} is not a valid number");
                }

                using (var reader = new StreamReader(new StreamSpan(streamImpl, 0, headerSize), Encoding.UTF8, false, 1, true))
                {
                    // This should be the "new line" at the end of the Header-Length we've already consumed
                    // so all that is left is the rest of the line (which is empty).
                    // If it's not, then we didn't read what we thought we read, bail
                    string blankLine = await reader.ReadLineAsync();

                    if (!string.IsNullOrEmpty(blankLine))
                    {
                        throw new FormatException($"Invalid mail file format, {HeaderLengthHeader} is improperly formatted");
                    }

                    string fromLine = await reader.ReadLineAsync();

                    if (!fromLine.StartsWith("FROM:"))
                    {
                        throw new FormatException("Invalid mail file format, expected FROM line");
                    }

                    sender = fromLine.Substring(5);

                    string line = null;
                    while (await reader.TryReadLineAsync(l => line = l, token))
                    {
                        if (line.StartsWith("TO:"))
                        {
                            recipients.Add(line.Substring(3));
                            continue;
                        }

                        throw new FormatException("Invalid mail file format, expected TO: line or Begin Message");
                    }
                }

                return(new ReadReference(
                           mailReference.Id,
                           sender,
                           recipients,
                           mailReference.Path,
                           new StreamSpan(stream.TakeValue()),
                           this));
            }
        }