예제 #1
0
        /// <summary>
        /// Creates the specified user filter.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <UserFilterCreatedResponse> CreateAsync(CreateUserFilterRequest model)
        {
            var uri = BaseUri.Append($"{ProjectName}/filter");

            var body     = ModelSerializer.Serialize <CreateUserFilterRequest>(model);
            var response = await HttpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <UserFilterCreatedResponse>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
예제 #2
0
        /// <summary>
        /// Finishes specified launch.
        /// </summary>
        /// <param name="id">ID of specified launch.</param>
        /// <param name="model">Information about representation of launch to finish.</param>
        /// <param name="force">Force finish launch even if test items are in progress.</param>
        /// <returns>A message from service.</returns>
        public async Task <Message> FinishLaunchAsync(string id, FinishLaunchRequest model, bool force = false)
        {
            var uri = BaseUri.Append($"{Project}/launch/{id}");

            uri = force == true?uri.Append("/stop") : uri.Append("/finish");

            var body     = ModelSerializer.Serialize <FinishLaunchRequest>(model);
            var response = await _httpClient.PutAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <Message>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
예제 #3
0
        public void TestMessage(XmlDocument xmlDoc)
        {
            try
            {
                var testId  = xmlDoc.SelectSingleNode("/test-message/@testid").Value;
                var message = xmlDoc.SelectSingleNode("/test-message").InnerText;

                if (_flowItems.ContainsKey(testId))
                {
                    AddLogItemRequest logRequest = null;
                    try
                    {
                        var sharedMessage = ModelSerializer.Deserialize <SharedLogMessage>(message);

                        logRequest = new AddLogItemRequest
                        {
                            Level      = sharedMessage.Level,
                            Time       = sharedMessage.Time,
                            TestItemId = sharedMessage.TestItemId,
                            Text       = sharedMessage.Text
                        };
                        if (sharedMessage.Attach != null)
                        {
                            logRequest.Attach = new Client.Models.Attach
                            {
                                Name     = sharedMessage.Attach.Name,
                                MimeType = sharedMessage.Attach.MimeType,
                                Data     = sharedMessage.Attach.Data
                            };
                        }
                    }
                    catch (Exception)
                    {
                    }

                    if (logRequest != null)
                    {
                        _flowItems[testId].TestReporter.Log(logRequest);
                    }
                    else
                    {
                        _flowItems[testId].TestReporter.Log(new AddLogItemRequest {
                            Level = LogLevel.Info, Time = DateTime.UtcNow, Text = message
                        });
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("ReportPortal exception was thrown." + Environment.NewLine + exception);
            }
        }
        /// <summary>
        /// Returns a list of test items for specified launch and parent test item (optional).
        /// </summary>
        /// <param name="filterOption">Specified criterias for retrieving test items.</param>
        /// <returns>A list of test items.</returns>
        public virtual async Task <TestItemsContainer> GetTestItemsAsync(FilterOption filterOption = null)
        {
            var uri = BaseUri.Append($"{Project}/item");

            if (filterOption != null)
            {
                uri = uri.Append($"?{filterOption}");
            }
            var response = await _httpClient.GetAsync(uri).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <TestItemsContainer>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
예제 #5
0
        /// <summary>
        /// Gets all user filters.
        /// </summary>
        /// <param name="filterOption"></param>
        /// <returns></returns>
        public virtual async Task <Content <UserFilterResponse> > GetAsync(FilterOption filterOption = null)
        {
            var uri = BaseUri.Append($"{ProjectName}/filter");

            if (filterOption != null)
            {
                uri = uri.Append($"?{filterOption}");
            }
            var response = await HttpClient.GetAsync(uri).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <Content <UserFilterResponse> >(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
예제 #6
0
        private void LoadModel(Assembly assembly, object[] attributes, int i, ModelMetadataAttribute metadata)
        {
            var model = serializer.Deserialize(assembly.GetManifestResourceStream(metadata.ResourceName), metadata.ModelUri, this, true);

            for (int j = i + 1; j < attributes.Length; j++)
            {
                var followingAttribute = attributes[j] as ModelMetadataAttribute;
                if (followingAttribute != null)
                {
                    var followUri = new Uri(followingAttribute.ModelUri, MakeRelativePath(metadata.ResourceName, followingAttribute.ResourceName));
                    if (!entries.ContainsKey(followUri))
                    {
                        entries.Add(followUri, model);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Returns a list of launches for current project.
        /// </summary>
        /// <param name="filterOption">Specified criterias for retrieving launches.</param>
        /// <param name="debug">Returns user debug launches or not.</param>
        /// <returns>A list of launches.</returns>
        public async Task <LaunchesContainer> GetLaunchesAsync(FilterOption filterOption = null, bool debug = false)
        {
            var uri = BaseUri.Append($"{Project}/launch");

            if (debug)
            {
                uri = uri.Append("mode");
            }

            if (filterOption != null)
            {
                uri = uri.Append($"?{filterOption}");
            }

            var response = await _httpClient.GetAsync(uri).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <LaunchesContainer>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
예제 #8
0
        private async Task <LaunchesContents> GetLastLaunchesAsync(FilterOption filterOption = null, bool debug = false)
        {
            var uri = _service.BaseUri.Append($"{_info.Project}/launch/latest");

            if (debug)
            {
                uri = uri.Append("mode");
            }

            if (filterOption != null)
            {
                uri = uri.Append($"?{filterOption}");
            }

            var response = await _client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);

            response.EnsureSuccessStatusCode();
            return(ModelSerializer.Deserialize <LaunchesContents>(await response.Content.ReadAsStringAsync()));
        }
예제 #9
0
        protected async Task <TResponse> SendHttpRequestAsync <TResponse>(HttpMethod httpMethod, string uri, HttpContent httpContent)
        {
            using (var httpRequest = new HttpRequestMessage(httpMethod, uri))
            {
                using (httpContent)
                {
                    httpRequest.Content = httpContent;

                    using (var response = await HttpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
                    {
                        using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                        {
                            CheckSuccessStatusCode(response, stream);

                            return(ModelSerializer.Deserialize <TResponse>(stream));
                        }
                    }
                }
            }
        }
예제 #10
0
        public void TestSerializeArray()
        {
            var array = new TestObjectArray();

            array.Objects = new List <TestObject>();
            array.Objects.Add(object1);
            array.Objects.Add(object2);



            var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());

            var strm = new MemoryStream();

            var writer = new StreamWriter(strm);

            s.Serialize(model, writer);


            var deserialized = new Data.ModelContainer();

            writer.Flush();

            strm.Position = 0;

            // For testing
            string serialized = getStringFromStream(strm);

            SimpleModelObject.CurrentModelContainer = deserialized;
            s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());
            s.Deserialize(new StreamReader(strm));


            Assert.AreEqual(model.Objects.Count, deserialized.Objects.Count);
            Assert.AreEqual(model.Objects[0].ToString(), deserialized.Objects[0].ToString());
            Assert.AreEqual(model.Objects[1].ToString(), deserialized.Objects[1].ToString());
            Assert.AreEqual(model.Objects[2].ToString(), deserialized.Objects[2].ToString());
        }
예제 #11
0
        private void RegisterAssembly(Assembly assembly)
        {
            var attributes = assembly.GetCustomAttributes(typeof(ModelMetadataAttribute), false);

            if (attributes != null && attributes.Length > 0 && modelAssemblies.Add(assembly))
            {
                var references = assembly.GetReferencedAssemblies();
                if (references != null)
                {
                    for (int i = 0; i < references.Length; i++)
                    {
                        RegisterAssembly(Assembly.Load(references[i]));
                    }
                }
                var types       = assembly.GetTypes();
                var saveMapping = new List <KeyValuePair <string, System.Type> >();
                if (types != null)
                {
                    for (int i = 0; i < types.Length; i++)
                    {
                        var t = types[i];
                        var modelRepresentation = t.GetCustomAttributes(typeof(ModelRepresentationClassAttribute), false);
                        if (modelRepresentation != null && modelRepresentation.Length > 0)
                        {
                            serializer.KnownTypes.Add(t);
                            var attr = (ModelRepresentationClassAttribute)modelRepresentation[0];
                            saveMapping.Add(new KeyValuePair <string, System.Type>(attr.UriString, t));
                        }
                    }
                }
                var names = assembly.GetManifestResourceNames();
                for (int i = 0; i < attributes.Length; i++)
                {
                    var metadata = attributes[i] as ModelMetadataAttribute;
                    Uri modelUri;
                    if (metadata != null && names.Contains(metadata.ResourceName) && Uri.TryCreate(metadata.ModelUri, UriKind.Absolute, out modelUri))
                    {
#if DEBUG
                        serializer.Deserialize(assembly.GetManifestResourceStream(metadata.ResourceName), modelUri, this, true);
#else
                        try
                        {
                            serializer.Deserialize(assembly.GetManifestResourceStream(metadata.ResourceName), modelUri, this, true);
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine(ex.Message);
                        }
#endif
                    }
                }
                for (int i = 0; i < saveMapping.Count; i++)
                {
                    var cls = ResolveType(saveMapping[i].Key);
                    if (cls != null)
                    {
                        var typeExtension = MappedType.FromType(cls);
                        typeExtension.SystemType = saveMapping[i].Value;
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("The class {0} could not be resolved.", saveMapping[i].Key));
                    }
                }
            }
        }