Пример #1
0
        private Document GetOrCreateDocument(string name)
        {
            var document = documents.FirstOrDefault(x => x.Name == name);

            if (document == null)
            {
                documents.Add(document = new Document(name, string.Empty));
            }

            return document;
        }
Пример #2
0
        public Project AddOrUpdate(Document document)
        {
            if (document != null)
            {
                if (Documents.Any(x => x.Name == document.Name))
                {
                    var existing = Documents.First(x => x.Name == document.Name);

                    // update only if the edit is newer
                    if (document.LastEdited > existing.LastEdited)
                    {
                        existing.Content = document.Content;
                        existing.LastEdited = document.LastEdited;
                    }
                }
                else
                {
                    Documents.Add(document);
                }
            }

            return this;
        }
Пример #3
0
        private static Document BuildSampleDocument()
        {
            var post = new Document { Name = "Person" };

            var builder = new StringBuilder();
            post.Content = builder.AppendLine("public class Person")
                                  .AppendLine("{")
                                  .AppendLine("    public Person(string name)")
                                  .AppendLine("    {")
                                  .AppendLine("        Name = name;")
                                  .AppendLine("    }")
                                  .AppendLine()
                                  .AppendLine("    public string Name { get; private set; }")
                                  .AppendLine()
                                  .AppendLine("    public string Greet()")
                                  .AppendLine("    {")
                                  .AppendLine("        if (string.IsNullOrEmpty(Name))")
                                  .AppendLine("        {")
                                  .AppendLine("            return \"Hello, stranger!\";")
                                  .AppendLine("        }")
                                  .AppendLine()
                                  .AppendLine("        return string.Format(\"Hello, {0}!\", Name);")
                                  .AppendLine("    }")
                                  .AppendLine("}")
                                  .ToString();

            return post;
        }