Beispiel #1
0
        /// <summary>
        /// 构造函数,创建一个指定活动记录时间、活动编号,分支名称,发起账户ID、活动类型和活动注释的活动记录器实例。
        /// </summary>
        /// <param name="recordTime">指定的活动时间。</param>
        /// <param name="activityId">指定的活动编号。</param>
        /// <param name="branch">指定的分支名称。</param>
        /// <param name="accountId">指定的发起账户ID。</param>
        /// <param name="activityType">指定的活动类型。</param>
        /// <param name="repositoryManager">指定记录的版本仓库。</param>
        /// <param name="description">指定的活动注释信息。</param>
        public ActivityRecorder(DateTime recordTime, long activityId, string branch, string accountId, EActivityType activityType, RepositoryManager repositoryManager, string description)
        {
            string activityTypeString = EnumerationDescriptionAttribute.GetEnumDescription(activityType);

            _recordTime        = recordTime;
            _activityId        = activityId;
            _activityType      = activityType;
            _repositoryManager = repositoryManager;
            if (string.IsNullOrWhiteSpace(branch))
            {
                _branch = @"master";
            }
            else
            {
                _branch = branch;
            }
            if (string.IsNullOrWhiteSpace(accountId))
            {
                _accountId = EnvironmentInformation.GetCurrentUserName();
            }
            else
            {
                _accountId = accountId;
            }
            if (string.IsNullOrWhiteSpace(description))
            {
                _description = _recordTime.ToString() + "--" + activityTypeString;
            }
            else
            {
                _description = description;
            }
        }
Beispiel #2
0
        private static EnvironmentInformation RegisterEnvironmentInformation(ContainerBuilder builder)
        {
            var environmentInformation = new EnvironmentInformation();

            builder
            .RegisterInstance(environmentInformation)
            .As <IEnvironmentInformation>()
            .SingleInstance();
            return(environmentInformation);
        }
        public void ToStringContainsAll()
        {
            var envInfo       = new EnvironmentInformation();
            var serialization = envInfo.ToString();

            Assert.IsTrue(serialization.Contains(envInfo.ClientVersion));
            Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture));
            Assert.IsTrue(serialization.Contains(envInfo.RuntimeFramework));
            Assert.IsTrue(serialization.Contains(envInfo.ClientId));
        }
        public void ClientVersionIsNotNull()
        {
            var envInfo = new EnvironmentInformation();

            Assert.IsNotNull(envInfo.ClientVersion);

            Version sdkVersion = Assembly.GetAssembly(typeof(CosmosClient)).GetName().Version;

            Assert.AreEqual($"{sdkVersion.Major}.{sdkVersion.Minor}.{sdkVersion.Build}", envInfo.ClientVersion, "Version format differs");
        }
        public void ClientIdIncrementsUpToMax()
        {
            // Max is 10
            const int max = 10;

            for (int i = 0; i < max + 5; i++)
            {
                EnvironmentInformation envInfo = new EnvironmentInformation();
                Assert.AreEqual(i > max ? max : i, int.Parse(envInfo.ClientId));
            }
        }
Beispiel #6
0
 private IApplication FindApplication(EnvironmentInformation environmentInformation)
 {
     foreach (IApplication application in _collection)
     {
         EnvironmentInformation temp = application.EnvironmentInformation;
         if (environmentInformation.Equals(temp))
         {
             return(application);
         }
     }
     return(null);
 }
        public void ValidateUniqueClientIdHeader()
        {
            EnvironmentInformation.ResetCounter();
            using (CosmosClient client = TestCommon.CreateCosmosClient())
            {
                string firstClientId = this.GetClientIdFromCosmosClient(client);

                using (CosmosClient innerClient = TestCommon.CreateCosmosClient())
                {
                    string secondClientId = this.GetClientIdFromCosmosClient(innerClient);
                    Assert.AreNotEqual(firstClientId, secondClientId);
                }
            }
        }
Beispiel #8
0
        public void VerifyUserAgentContent()
        {
            EnvironmentInformation envInfo = new EnvironmentInformation();

            Cosmos.UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer(clientId: 0);
            string serialization = userAgentContainer.UserAgent;

            Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture));
            string[] values = serialization.Split('|');
            Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}", values[0]);
            Assert.AreEqual(envInfo.DirectVersion, values[1]);
            Assert.AreEqual("0", values[2]);
            Assert.AreEqual(envInfo.ProcessArchitecture, values[3]);
            Assert.AreEqual(envInfo.OperatingSystem, values[4]);
            Assert.AreEqual(envInfo.RuntimeFramework, values[5]);
        }
Beispiel #9
0
        public void UserAgentContainsEnvironmentInformation()
        {
            EnvironmentInformation environmentInformation = new EnvironmentInformation();
            string expectedValue = environmentInformation.ToString();
            CosmosClientOptions cosmosClientOptions = new CosmosClientOptions();
            string userAgentSuffix = "testSuffix";

            cosmosClientOptions.ApplicationName = userAgentSuffix;

            Assert.IsTrue(cosmosClientOptions.UserAgentContainer.Suffix.EndsWith(userAgentSuffix));
            Assert.IsTrue(cosmosClientOptions.UserAgentContainer.Suffix.Contains(expectedValue));

            ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy();

            Assert.IsTrue(connectionPolicy.UserAgentSuffix.EndsWith(userAgentSuffix));
            Assert.IsTrue(connectionPolicy.UserAgentSuffix.Contains(expectedValue));
        }
Beispiel #10
0
        public void UserAgentContainsEnvironmentInformation()
        {
            EnvironmentInformation environmentInformation = new EnvironmentInformation();
            string expectedValue = "cosmos-netstandard-sdk/" + environmentInformation.ClientVersion;
            CosmosClientOptions cosmosClientOptions = new CosmosClientOptions();
            string userAgentSuffix = "testSuffix";

            cosmosClientOptions.ApplicationName = userAgentSuffix;
            Assert.AreEqual(userAgentSuffix, cosmosClientOptions.ApplicationName);
            Assert.AreEqual(userAgentSuffix, cosmosClientOptions.UserAgentContainer.Suffix);
            Assert.IsTrue(cosmosClientOptions.UserAgentContainer.UserAgent.StartsWith(expectedValue));
            Assert.IsTrue(cosmosClientOptions.UserAgentContainer.UserAgent.EndsWith(userAgentSuffix));

            ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy();

            Assert.AreEqual(userAgentSuffix, connectionPolicy.UserAgentSuffix);
            Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.StartsWith(expectedValue));
            Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.EndsWith(userAgentSuffix));
        }
Beispiel #11
0
 public bool Disconnect(IApplication application)
 {
     lock (Lock)
     {
         VerifyDisposed();
         EnvironmentInformation environmentInformation = application.EnvironmentInformation;
         application = FindApplication(environmentInformation);
         if (application == null)
         {
             return(false);
         }
         bool result = _collection.Remove(application);
         if (result)
         {
             _applicationDisconnectedEvent.Invoke(() => new ApplicationEventArgs(application));
         }
         return(result);
     }
 }
        public void VerifyUserAgentContent(bool useMacOs)
        {
            this.SetEnvironmentInformation(useMacOs);

            EnvironmentInformation envInfo = new EnvironmentInformation();

            Cosmos.UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer();
            string serialization = userAgentContainer.UserAgent;

            Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture));
            string[] values = serialization.Split('|');
            Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}", values[0]);
            Assert.AreEqual(envInfo.DirectVersion, values[1]);
            Assert.AreEqual(envInfo.ClientId.Length, values[2].Length);
            Assert.AreEqual(envInfo.ProcessArchitecture, values[3]);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(values[4]));
            if (useMacOs)
            {
                Assert.AreEqual("Darwin 18.0.0 Darwin Kernel V", values[4]);
            }
            Assert.AreEqual(envInfo.RuntimeFramework, values[5]);
        }
        static void CreateContainerIfNotExists()
        {
            if (container != null)
            {
                return;
            }

            var environmentInformation = new EnvironmentInformation();
            if (environmentInformation.GetIsInDesignTime())
            {
                container = DesignTimeContainerHelper.CreateDesignTimeContainer();
            }
            else
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule(new DefaultWiringModule());
                builder.RegisterInstance(environmentInformation)
                       .As<IEnvironmentInformation>();

                container = builder.Build();
            }
        }
        static void CreateContainerIfNotExists()
        {
            if (container != null)
            {
                return;
            }

            var environmentInformation = new EnvironmentInformation();

            if (environmentInformation.IsInDesignTime)
            {
                container = DesignTimeContainerHelper.CreateDesignTimeContainer();
            }
            else
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule(new DefaultWiringModule());
                builder.RegisterInstance(environmentInformation).As <IEnvironmentInformation>();

                container = builder.Build();
            }
        }
Beispiel #15
0
 private const string VCS_ACTIVITY_RECORD_LOG_DBTABLE = @"activityRecordLog"; //本地文件版本控制系统活动记录数据表名称。
 /// <summary>
 /// 构造函数,创建一个指定活动记录时间、活动编号,分支名称,发起账户ID和活动类型的活动记录器实例。
 /// </summary>
 /// <param name="recordTime">指定的活动时间。</param>
 /// <param name="activityId">指定的活动编号。</param>
 /// <param name="branch">指定的分支名称。</param>
 /// <param name="accountId">指定的发起账户ID。</param>
 /// <param name="activityType">指定的活动类型。</param>
 /// <param name="repositoryManager">指定记录的版本仓库。</param>
 public ActivityRecorder(DateTime recordTime, long activityId, string branch, string accountId, EActivityType activityType, RepositoryManager repositoryManager)
 {
     _recordTime        = recordTime;
     _activityId        = activityId;
     _activityType      = activityType;
     _repositoryManager = repositoryManager;
     if (string.IsNullOrWhiteSpace(branch))
     {
         _branch = @"master";
     }
     else
     {
         _branch = branch;
     }
     if (string.IsNullOrWhiteSpace(accountId))
     {
         _accountId = EnvironmentInformation.GetCurrentUserName();
     }
     else
     {
         _accountId = accountId;
     }
 }
        public void ClientIdIncrementsUpToMax_Concurrent()
        {
            const int  max      = 10;
            const int  tasks    = max + 5;
            List <int> expected = new List <int>(tasks);

            for (int i = 0; i < tasks; i++)
            {
                expected.Add(i > max ? max : i);
            }

            List <int> results = new List <int>(tasks);

            Parallel.For(0, tasks, (int i) =>
            {
                EnvironmentInformation envInfo = new EnvironmentInformation();
                results.Add(int.Parse(envInfo.ClientId));
            });

            results.Sort();

            CollectionAssert.AreEqual(expected, results);
        }
        public void ClientIdIsNotNull()
        {
            var envInfo = new EnvironmentInformation();

            Assert.IsNotNull(envInfo.ClientId);
        }
        public void FrameworkIsNotNull()
        {
            var envInfo = new EnvironmentInformation();

            Assert.IsNotNull(envInfo.RuntimeFramework);
        }
        public void ProcessArchitectureIsNotNull()
        {
            var envInfo = new EnvironmentInformation();

            Assert.IsNotNull(envInfo.ProcessArchitecture);
        }
        static UserAgentContainer()
        {
            EnvironmentInformation environmentInformation = new EnvironmentInformation();

            UserAgentContainer.cosmosBaseUserAgent = environmentInformation.ToString();
        }
Beispiel #21
0
        private Task <int> CreateAndReturnClientId()
        {
            EnvironmentInformation envInfo = new EnvironmentInformation();

            return(Task.FromResult(int.Parse(envInfo.ClientId)));
        }
 public void Reset()
 {
     EnvironmentInformation.ResetCounter();
 }