Пример #1
0
        internal CompositeRoot CreateCompositeRoot(CompositeRootConfiguration configuration, EventHandler eventHandler, IEnumerable <IService> services)
        {
            var compositeRoot = CompositeRoot.Create(configuration, eventHandler, services);

            compositeRoot.ActiveCompositeRoots = this;
            compositeRoots.Add(configuration.Id.ToString(), compositeRoot);
            return(compositeRoot);
        }
        public CompositeRootConfiguration CreateNewRootConfiguration(string endpoint, Type compositeRootType, Type compositeRootAuthenticatorType, CompositeRootMode mode, TimeSpan sessionExpiration)
        {
            if (mode == CompositeRootMode.None)
            {
                throw new ArgumentException(string.Format(Resources.CompositeRootModeParameterCannotBeNone, nameof(mode), mode.ToString()), nameof(mode), null);
            }

            var newRootConfiguration = new RootConfiguration(ServerConfiguration.rootHttpServerConfiguration)
            {
                Endpoint          = endpoint,
                CompositeRootType = compositeRootType,
                CompositeRootAuthenticatorType = compositeRootAuthenticatorType,
                Mode = mode,
                SessionExpiration = sessionExpiration
            };

            var compositeRootConfiguration = new CompositeRootConfiguration(newRootConfiguration, this)
            {
                Endpoint          = endpoint,
                CompositeRootType = compositeRootType,
                CompositeRootAuthenticatorType = compositeRootAuthenticatorType,
                Mode = mode,
                SessionExpiration = sessionExpiration
            };

            rootConfigurations.Add(compositeRootConfiguration.Id, compositeRootConfiguration);

            return(compositeRootConfiguration);
        }
        public PostComposite CreateNewPost(CompositeRootHttpContext context)
        {
            var newPost = new PostComposite(Blog.BlogModel.CreateNewPost(), this)
            {
                State = CompositeState.New
            };

            posts.Add(newPost.Id, newPost);
            return(newPost);
        }
        internal CompositeRootConfigurationContainer(CompositeRootHttpServerConfiguration serverConfiguration)
        {
            ServerConfiguration = serverConfiguration;
            rootConfigurations  = new CompositeDictionary <Guid, CompositeRootConfiguration>();
            RootConfigurations  = new ReadOnlyCompositeDictionary <Guid, CompositeRootConfiguration>(rootConfigurations);

            foreach (var configuration in ServerConfiguration.rootHttpServerConfiguration.rootConfigurations.Values)
            {
                rootConfigurations.Add(configuration.Id, new CompositeRootConfiguration(configuration, this));
            }
        }
Пример #5
0
        public void ThreadsTest()
        {
            var compositeDictionary = new CompositeDictionary <string, string, int>
            {
                { "Id1", "Name1", 1 },
                { "Id1", "Name2", 2 },
                { "Id2", "Name1", 3 },
                { "Id2", "Name2", 4 },
                { "Id3", "Name1", 5 }
            };

            var initCount = compositeDictionary.Count;

            Task.Run(() => compositeDictionary.Add("TId1", "TName1", 6));
            Task.Run(() => compositeDictionary.Add("TId2", "TName2", 7));
            Task.Run(() => compositeDictionary.Add("TId3", "TName3", 8));

            Thread.Sleep(10);

            Assert.AreEqual(initCount + 3, compositeDictionary.Count);
        }
Пример #6
0
        public CommentComposite CreateNewComment(CompositeRootHttpContext context)
        {
            var blogApplication = CompositeRoot as BlogApplicationCompositeRoot;

            var newComment = new CommentComposite(Post.PostModel.CreateNewComment(), this)
            {
                State = CompositeState.New,
                User  = blogApplication.CurrentUser
            };

            comments.Add(newComment.Id, newComment);
            return(newComment);
        }
Пример #7
0
        public void Count_ShouldGiveNumberOfElements()
        {
            CompositeDictionary <int, double, string> dict = new CompositeDictionary <int, double, string>();

            string[] values =
            {
                "Bart",
                "Homer",
                "Marge",
                "Lisa",
                "Maggie"
            };

            dict.Add(1, 6.1, values[0]);
            dict.Add(2, 0.1, values[1]);
            dict.Add(3, 2.0, values[2]);
            dict.Add(4, -2.1, values[3]);
            dict.Add(5, 7.01, values[4]);

            dict.Should()
            .HaveCount(values.Length);
        }
Пример #8
0
        public void Add_ShouldAddMultipleElements()
        {
            CompositeDictionary <int, double, string> dict = new CompositeDictionary <int, double, string>();

            string[] values =
            {
                "Bart",
                "Homer",
                "Marge",
                "Lisa",
                "Maggie"
            };

            dict.Add(1, 6.1, values[0]);
            dict.Add(2, 0.1, values[1]);
            dict.Add(3, 2.0, values[2]);
            dict.Add(4, -2.1, values[3]);
            dict.Add(5, 7.01, values[4]);

            dict.Values
            .Should()
            .Contain(values);
        }
Пример #9
0
 public BlogComposite CreateNewBlog(CompositeRootHttpContext context)
 {
     if (context.Request.UserName.ToLowerInvariant() == "admin")
     {
         var newBlog = new BlogComposite(new Blog(), this)
         {
             State = CompositeState.New
         };
         blogs.Add(newBlog.Id, newBlog);
         return(newBlog);
     }
     else
     {
         throw new UnauthorizedAccessException();
     }
 }
Пример #10
0
        public AttachmentComposite CreateNewAttachment(CompositeRootHttpContext context)
        {
            var newAttachment = new AttachmentComposite(Post.PostModel.CreateNewAttachment(), this)
            {
                State = CompositeState.New
            };

            var fileAttachment = context.Request.UploadedFiles.FirstOrDefault();

            if (fileAttachment != null)
            {
                var fileAttachmentPath = System.IO.Path.GetTempFileName();
                File.WriteAllBytes(fileAttachmentPath, fileAttachment.GetContent());
                newAttachment.FilePath = fileAttachmentPath;
            }

            attachments.Add(newAttachment.Id, newAttachment);
            return(newAttachment);
        }
Пример #11
0
        public void SecondaryKeys_ShouldContainAll2ndKeys()
        {
            CompositeDictionary <Guid, string, Guid> dict = new CompositeDictionary <Guid, string, Guid>();

            string[] secondaryKeys =
            {
                "Sledge",
                "Leckie",
                "Snaffu"
            };

            foreach (string key2 in secondaryKeys)
            {
                dict.Add(Guid.NewGuid(), key2, Guid.NewGuid());
            }

            dict.SecondaryKeys
            .Should()
            .Contain(secondaryKeys);
        }
Пример #12
0
        private static void Main()
        {
            var firstUser = new UserTypeA {
                UserId = 1, UserName = "******"
            };
            var secondUser = new UserTypeA {
                UserId = 2, UserName = "******"
            };
            var thirdUser = new UserTypeA {
                UserId = 3, UserName = "******"
            };

            var a = new CompositeKey <UserTypeA, UserTypeB>(firstUser, new UserTypeB {
                Level = "First", FriendlyUserTypeA = secondUser
            });
            var b = new CompositeKey <UserTypeA, UserTypeB>(secondUser, new UserTypeB {
                Level = "First", FriendlyUserTypeA = firstUser
            });
            var e = new CompositeKey <UserTypeA, UserTypeB>(firstUser, new UserTypeB {
                Level = "Second", FriendlyUserTypeA = thirdUser
            });

            var c = new CompositeDictionary <UserTypeA, UserTypeB, string>
            {
                { e.Id, e.Name, "One" }
            };

            c.Add(a.Id, a.Name, "Two");
            c[b.Id, b.Name] = "Three";

            c[a.Id, a.Name] = "Four";

            foreach (var variable in c)
            {
                Console.WriteLine($"Id.UserName:{variable.Key.Id.UserName};{Environment.NewLine}"
                                  + $"Name.FriendlyUserTypeA.UserName: {variable.Key.Name.FriendlyUserTypeA.UserName}, Name.Level: {variable.Key.Name.Level};{Environment.NewLine}"
                                  + $"Value: {variable.Value}{Environment.NewLine}{Environment.NewLine}");
            }

            Console.ReadKey();
        }
Пример #13
0
        public void PrimaryKeys_ShouldContainAll1stKeys()
        {
            CompositeDictionary <string, Guid, Guid> dict = new CompositeDictionary <string, Guid, Guid>();

            string[] primaryKeys =
            {
                "Leonard",
                "Raj",
                "Sheldon",
                "Howard"
            };

            foreach (string key1 in primaryKeys)
            {
                dict.Add(key1, Guid.NewGuid(), Guid.NewGuid());
            }

            dict.PrimaryKeys
            .Should()
            .Contain(primaryKeys);
        }
        public CompositeRootSession CreateNewCompositeRootSession(string endPoint, string userName, string token, TimeSpan sessionExpiration, CompositeRootMode mode, CompositeRoot compositeRoot)
        {
            var newCompositeRootSession = new CompositeRootSession(this)
            {
                lastAccessed = DateTime.Now,
                userName     = userName,
                token        = endPoint + token,
                expiration   = sessionExpiration,
                mode         = mode
            };

            sessions.Add(endPoint + token, newCompositeRootSession);
            compositeRoot.CompositeRootSession = newCompositeRootSession;

            if (mode == CompositeRootMode.MultipleHost)
            {
                compositeRoot.ActiveCompositeRoots = Server.ActiveCompositeRoots;
                Server.ActiveCompositeRoots.compositeRoots.dictionary.TryAdd(endPoint + token, compositeRoot);
            }

            return(newCompositeRootSession);
        }
Пример #15
0
        public void DuplicatesIdTest()
        {
            var compositeDictionary = new CompositeDictionary <string, string, int>
            {
                { "Id1", "Name1", 1 },
                { "Id1", "Name2", 2 },
            };

            var initialCompositeDictionaryCount = compositeDictionary.Count;

            var isExceptionThrown = false;

            try
            {
                compositeDictionary.Add("Id1", "Name1", 3);
            }
            catch (ArgumentException e)
            {
                isExceptionThrown = true;
            }

            Assert.That(isExceptionThrown, Is.EqualTo(true), "ArgumentException didn't throw.");
            Assert.That(compositeDictionary.Count, Is.EqualTo(initialCompositeDictionaryCount));
        }