public JsonResult Save([FromBody] AssetDto pAsset) { var loUser = HttpContext.Session.GetObject <UserDto>("User"); var loAssetFiles = new List <AssetPhoto>(); var loFileListToSave = new List <FileModel>(); if (Directory.Exists(_environment.WebRootPath + "\\" + "Uploads\\Temp\\" + loUser.session_id)) { string[] filePaths = Directory.GetFiles(_environment.WebRootPath + "\\" + "Uploads\\Temp\\" + loUser.session_id); foreach (var file in filePaths) { var loFileModel = new FileModel { FileContent = System.IO.File.ReadAllBytes(file), FileName = Path.GetFileName(file), FilePath = loUser.session_id }; var loAssetFile = new AssetPhoto { file_path = loFileModel.FilePath + "\\" + loFileModel.FileName }; if (loFileModel.FileName.Contains("thumb_")) { pAsset.thumb_path = loAssetFile.file_path; loAssetFile.is_thumb = true; } loFileListToSave.Add(loFileModel); loAssetFiles.Add(loAssetFile); } } if (!loFileListToSave.Any() || HelperMethods.SaveFilesToFileServer(_environment.WebRootPath + "\\" + "Uploads\\", loFileListToSave)) { if (pAsset.asset_photos != null && pAsset.asset_photos.Any()) { pAsset.asset_photos.AddRange(loAssetFiles); } else { pAsset.asset_photos = loAssetFiles; } pAsset.asset_photos.ForEach(x => x.file_path = x.file_path.Replace(",", "\\")); HelperMethods.DeleteFiles(pAsset.asset_photos.FindAll(x => x.is_deleted), _environment.WebRootPath + "\\" + "Uploads\\"); //var loAsset = RestCalls.UpdateAsset(pAsset, loUser.token); var loAsset = RestCalls.SaveAsset(pAsset, loUser.token); if (!string.IsNullOrEmpty(loAsset.message) || loAsset.id <= 0) { return(Json(loAsset)); } try { if (loFileListToSave.Any()) // yeni kayıt varsa sil templeri! { Directory.Delete(Path.Combine(_environment.WebRootPath, "Uploads\\Temp\\" + loUser.session_id), true); // temp resimleri sil } } catch (Exception) { //ignored; } return(Json(loAsset)); } return(Json(new AssetDto())); }
public async void GetByIdAsync() { // TODO AssetDto asset = await sut.GetByIdAsync(Guid.Empty); }
private void SaveRowAsset(AssetDto asset) { _assetGrid.UpdateRow(asset); }
private void CancelEditAsset(AssetDto asset) { _assetGrid.CancelEditRow(asset); }
public async Task <IActionResult> CreateAsset(AssetDto assetDto) { var assetReturn = await _assetService.CreateAsset(assetDto); return(CreatedAtRoute("GetAsset", new { Controller = "Asset", id = assetReturn.ID }, assetReturn)); }
private void EditRowAsset(AssetDto asset) { _assetGrid.EditRow(asset); }
public static AssetModel ToModel(this AssetDto asset) { return(SimpleMapper.Map(asset, new AssetModel())); }
private static List <DocumentTemplate> GetVstAgreementTemplateValues(AssetDto pAsset, Customer pCustomer, Offer pOffer) { var loDocumentTemplateKeys = new List <DocumentTemplate>(); var loDocumentTemplateKey1 = new DocumentTemplate(); var loDocumentTemplateKey2 = new DocumentTemplate(); var loDocumentTemplateKey3 = new DocumentTemplate(); var loDocumentTemplateKey4 = new DocumentTemplate(); var loDocumentTemplateKey5 = new DocumentTemplate(); var loDocumentTemplateKey6 = new DocumentTemplate(); var loDocumentTemplateKey7 = new DocumentTemplate(); var loDocumentTemplateKey8 = new DocumentTemplate(); var loDocumentTemplateKey9 = new DocumentTemplate(); var loDocumentTemplateKey10 = new DocumentTemplate(); var loDocumentTemplateKey11 = new DocumentTemplate(); var loDocumentTemplateKey12 = new DocumentTemplate(); var loDocumentTemplateKey13 = new DocumentTemplate(); var loDocumentTemplateKey14 = new DocumentTemplate(); var loDocumentTemplateKey15 = new DocumentTemplate(); var loDocumentTemplateKey16 = new DocumentTemplate(); var loDocumentTemplateKey17 = new DocumentTemplate(); var loOfferWinv = Math.Round(pOffer.pre_offer_price.Value * 6 / 100, 2).ToString("N") + " TL"; var loOfferPrice = pOffer.pre_offer_price.Value.ToString("N") + " TL"; var loOfferPriceWinv = IntegerToWritten(Convert.ToInt32(Math.Round(pOffer.pre_offer_price.Value * 6 / 100))) + " TL"; loOfferPrice = loOfferPrice.Replace(",00", ""); loOfferWinv = loOfferWinv.Replace(",00", ""); var loRegisterPriceTen = Math.Round(pAsset.registry_price.Value * 10 / 100, 2).ToString("N") + " TL"; var loRegisterPrice = pAsset.registry_price.Value.ToString("N") + " TL"; var loRegisterPriceTenText = IntegerToWritten(Convert.ToInt32(Math.Round(pAsset.registry_price.Value * 10 / 100))) + " TL"; loRegisterPrice = loRegisterPrice.Replace(",00", ""); loRegisterPriceTen = loRegisterPriceTen.Replace(",00", ""); loDocumentTemplateKey1.document_template_key = ((int)VestelAgreement.mail).ToString(); loDocumentTemplateKey1.document_template_value = pCustomer.mail; loDocumentTemplateKeys.Add(loDocumentTemplateKey1); loDocumentTemplateKey2.document_template_key = ((int)VestelAgreement.ad_soyad).ToString(); loDocumentTemplateKey2.document_template_value = pCustomer.user_type_system_type_id == 1 ? string.Concat(pCustomer.customer_name, " ", pCustomer.customer_surname) : pCustomer.company_name; loDocumentTemplateKeys.Add(loDocumentTemplateKey2); loDocumentTemplateKey3.document_template_key = ((int)VestelAgreement.ada).ToString(); loDocumentTemplateKey3.document_template_value = pAsset.block_number; loDocumentTemplateKeys.Add(loDocumentTemplateKey3); loDocumentTemplateKey4.document_template_key = ((int)VestelAgreement.parsel).ToString(); loDocumentTemplateKey4.document_template_value = pAsset.plot_number; loDocumentTemplateKeys.Add(loDocumentTemplateKey4); loDocumentTemplateKey5.document_template_key = ((int)VestelAgreement.adres).ToString(); loDocumentTemplateKey5.document_template_value = pAsset.address; loDocumentTemplateKeys.Add(loDocumentTemplateKey5); loDocumentTemplateKey6.document_template_key = ((int)VestelAgreement.bagimsiz_bolum).ToString(); loDocumentTemplateKey6.document_template_value = pAsset.free_text_no; loDocumentTemplateKeys.Add(loDocumentTemplateKey6); loDocumentTemplateKey7.document_template_key = ((int)VestelAgreement.il).ToString(); loDocumentTemplateKey7.document_template_value = pAsset.city; loDocumentTemplateKeys.Add(loDocumentTemplateKey7); loDocumentTemplateKey8.document_template_key = ((int)VestelAgreement.ilce).ToString(); loDocumentTemplateKey8.document_template_value = pAsset.district; loDocumentTemplateKeys.Add(loDocumentTemplateKey8); loDocumentTemplateKey9.document_template_key = ((int)VestelAgreement.kimlik_no).ToString(); loDocumentTemplateKey9.document_template_value = pCustomer.identity_no; loDocumentTemplateKeys.Add(loDocumentTemplateKey9); loDocumentTemplateKey10.document_template_key = ((int)VestelAgreement.tarih).ToString(); loDocumentTemplateKey10.document_template_value = DateTime.Now.ToString("f"); loDocumentTemplateKeys.Add(loDocumentTemplateKey10); loDocumentTemplateKey11.document_template_key = ((int)VestelAgreement.teklif_bedeli).ToString(); loDocumentTemplateKey11.document_template_value = loOfferPrice; loDocumentTemplateKeys.Add(loDocumentTemplateKey11); loDocumentTemplateKey12.document_template_key = ((int)VestelAgreement.satis_bedel_yuzde_alti).ToString(); loDocumentTemplateKey12.document_template_value = loOfferWinv; loDocumentTemplateKeys.Add(loDocumentTemplateKey12); loDocumentTemplateKey13.document_template_key = ((int)VestelAgreement.satis_bedel_yuzde_alti_metin).ToString(); loDocumentTemplateKey13.document_template_value = loOfferPriceWinv; loDocumentTemplateKeys.Add(loDocumentTemplateKey13); loDocumentTemplateKey14.document_template_key = ((int)VestelAgreement.tapu_bedeli).ToString(); loDocumentTemplateKey14.document_template_value = loRegisterPrice; loDocumentTemplateKeys.Add(loDocumentTemplateKey14); loDocumentTemplateKey15.document_template_key = ((int)VestelAgreement.tapu_bedel_yuzde_on).ToString(); loDocumentTemplateKey15.document_template_value = loRegisterPriceTen; loDocumentTemplateKeys.Add(loDocumentTemplateKey15); loDocumentTemplateKey16.document_template_key = ((int)VestelAgreement.tapu_bedel_yuzde_on_metin).ToString(); loDocumentTemplateKey16.document_template_value = loRegisterPriceTenText; loDocumentTemplateKeys.Add(loDocumentTemplateKey16); loDocumentTemplateKey17.document_template_key = ((int)VestelAgreement.telefon).ToString(); loDocumentTemplateKey17.document_template_value = pCustomer.phone; loDocumentTemplateKeys.Add(loDocumentTemplateKey17); return(loDocumentTemplateKeys); }
/// <summary> /// Edit an asset /// </summary> /// <remarks> /// Required permissions: Assets.Edit. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// key: Id /// </param> /// <param name='assetDto'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task PutByIdAsync(this IAssets operations, long id, AssetDto assetDto, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { (await operations.PutByIdWithHttpMessagesAsync(id, assetDto, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
public static string?GetFileHash(this IFile file, AssetDto asset) { return(GetFileHash(file, asset.FileName)); }
/// <summary> /// Edit an asset /// </summary> /// <remarks> /// Required permissions: Assets.Edit. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// key: Id /// </param> /// <param name='assetDto'> /// </param> public static void PutById(this IAssets operations, long id, AssetDto assetDto) { operations.PutByIdAsync(id, assetDto).GetAwaiter().GetResult(); }
/// <summary> /// Creates an asset /// </summary> /// <remarks> /// Required permissions: Assets.Create. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='assetDto'> /// </param> public static AssetDto Post(this IAssets operations, AssetDto assetDto) { return(operations.PostAsync(assetDto).GetAwaiter().GetResult()); }
private static AssetDto AssetDto() { var datacenter = new DatacenterDto() { Id = Guid.NewGuid(), Name = "RTP1", Description = "Research Triangle Park lab 1", HasNetworkManagedPower = true }; var rack = new RackDto() { Id = Guid.NewGuid(), RowLetter = "A", RackNumber = 1, Datacenter = datacenter, DatacenterId = datacenter.Id }; rack.Pdus = new List <PduDto> { new PduDto() { Id = Guid.NewGuid(), Location = PduLocation.L, Rack = rack, RackId = rack.Id }, new PduDto() { Id = Guid.NewGuid(), Location = PduLocation.R, Rack = rack, RackId = rack.Id } }; var pduPortL24 = new PduPortDto() { Id = Guid.NewGuid(), Number = 24, Pdu = rack.Pdus.First() }; var pduPortR24 = new PduPortDto() { Id = Guid.NewGuid(), Number = 24, Pdu = rack.Pdus.Last() }; var model = new ModelDto() { Id = Guid.NewGuid(), Vendor = "foo vendor", ModelNumber = "foo number", Height = 4, DisplayColor = "#0f0f0f", NetworkPorts = new List <ModelNetworkPortDto> { new ModelNetworkPortDto { Id = Guid.NewGuid(), Name = "1", Number = 1 }, new ModelNetworkPortDto { Id = Guid.NewGuid(), Name = "2", Number = 2 } }, EthernetPorts = 2, PowerPorts = 2 }; var owner = new UserDto() { Id = Guid.NewGuid(), Username = "******" }; var networkPorts = new List <AssetNetworkPortDto>() { }; var powerPorts = new List <AssetPowerPortDto>() { }; var asset = new AssetDto() { Hostname = "server1", RackPosition = 39, Comment = "important commentary", RackId = rack.Id, Rack = rack, ModelId = model.Id, Model = model, OwnerId = owner.Id, Owner = owner, NetworkPorts = networkPorts, PowerPorts = powerPorts, AssetNumber = 100000 }; asset.NetworkPorts.ForEach(o => { o.Asset = asset; o.AssetId = asset.Id; }); return(asset); }
public Task OnCompletedAsync(AssetUploadCompletedEvent @event, CancellationToken ct) { Asset = @event.Asset; return(Task.CompletedTask); }
static void Main(string[] args) { UnitOfWork efUnit = new UnitOfWork(); UserDto bob = new UserDto { Id = Guid.NewGuid(), Name = "Bob", Email = "*****@*****.**", }; AssetDto asset = new AssetDto { Id = Guid.NewGuid(), Name = "Bob's asset", UserId = bob.Id }; CategoryDto incomeCategory = new CategoryDto { Id = Guid.NewGuid(), Name = "Bob's job", Type = CategoryType.Income, Color = ColorHelper.DefaultColor }; CategoryDto incomeSubCategory = new CategoryDto { Id = Guid.NewGuid(), Name = "Bob's secret job", Type = CategoryType.Income, Color = incomeCategory.Color, ParentCategoryId = incomeCategory.Id }; CategoryDto expenseCategory = new CategoryDto { Id = Guid.NewGuid(), Color = ColorHelper.DefaultColor, Name = "Sport", Type = CategoryType.Expense }; efUnit.Users.Create(bob); efUnit.Assets.Create(asset); efUnit.Categories.Create(expenseCategory); efUnit.Categories.Create(incomeCategory); efUnit.Categories.Create(incomeSubCategory); TransactionDto[] bobsTransactions = new TransactionDto[8]; for (int i = 0; i < 4; i++) { bobsTransactions[i] = new TransactionDto { CategoryId = incomeCategory.Id, AssetId = asset.Id, Amount = (decimal) new Random().NextDouble(), Date = DateTime.Now, Comment = "bob is best" }; efUnit.Transactions.Create(bobsTransactions[i]); } for (int i = 4; i < 8; i++) { bobsTransactions[i] = new TransactionDto { CategoryId = incomeCategory.Id, AssetId = asset.Id, Amount = (decimal) new Random().NextDouble(), Date = DateTime.Now, Comment = "bob..." }; efUnit.Transactions.Create(bobsTransactions[i]); } efUnit.Save(); Console.WriteLine("Saved successfully."); Console.WriteLine("All bob's transactions: "); foreach (var tr in efUnit.Transactions.GetUsersTransactions(bob.Id)) { Console.WriteLine(tr.Comment); } Console.WriteLine("Deleting all bob's transactions for this month: "); efUnit.Transactions.DeleteAllTransactionsForMonth(bob.Id); Console.WriteLine("Get user by email([email protected]): "); Console.WriteLine(efUnit.Users.GetUserByEmail("*****@*****.**").Name); Console.WriteLine("All users ordered by name: "); var users = efUnit.Users.GetAllUsersOrderByName(); foreach (var user in users) { Console.WriteLine(user.Name); } Console.WriteLine("Bob's assets ordered by name: "); var assets = efUnit.Assets.GetUsersAssets(bob.Id); foreach (var a in assets) { Console.WriteLine(a.Name); } Console.WriteLine("Bob's current balance: "); Console.WriteLine(efUnit.Users.GetCurrentBalance(bob.Id).Balance); Console.WriteLine("Transactions month report: "); var transactions = efUnit.Transactions .GetTransactionMonthReports(bob.Id, DateTime.MinValue, DateTime.MaxValue); foreach (var t in transactions) { Console.WriteLine("Expence: {0}; income: {1}; for {2}.{3}", t.TotalExpense, t.TotalIncome, t.Month, t.Year); } Console.WriteLine("Get total amount of incomes: "); var result = efUnit.Transactions.GetTotalAmountOfType(bob.Id, CategoryType.Income); foreach (var r in result) { Console.WriteLine("Name: {0}, Amount: {1}", r.Name, r.Amount); } efUnit.Save(); }
private static List <DocumentTemplate> GetThkAgreementTemplateValues(AssetDto pAsset, Customer pCustomer) { var loDocumentTemplateKeys = new List <DocumentTemplate>(); var loDocumentTemplateKey1 = new DocumentTemplate(); var loDocumentTemplateKey2 = new DocumentTemplate(); var loDocumentTemplateKey3 = new DocumentTemplate(); var loDocumentTemplateKey4 = new DocumentTemplate(); var loDocumentTemplateKey5 = new DocumentTemplate(); var loDocumentTemplateKey6 = new DocumentTemplate(); var loDocumentTemplateKey7 = new DocumentTemplate(); var loDocumentTemplateKey8 = new DocumentTemplate(); var loDocumentTemplateKey9 = new DocumentTemplate(); var loDocumentTemplateKey10 = new DocumentTemplate(); var loDocumentTemplateKey11 = new DocumentTemplate(); var loDocumentTemplateKey12 = new DocumentTemplate(); loDocumentTemplateKey1.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Tarih).ToString(); loDocumentTemplateKey1.document_template_value = DateTime.Now.ToString("dd.MM.yyyy"); loDocumentTemplateKeys.Add(loDocumentTemplateKey1); loDocumentTemplateKey2.document_template_key = ((int)ThkAgreement.ThkSatisSartname.GmNo).ToString(); loDocumentTemplateKey2.document_template_value = pAsset.company_prefix + pAsset.asset_no; loDocumentTemplateKeys.Add(loDocumentTemplateKey2); loDocumentTemplateKey3.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Il).ToString(); loDocumentTemplateKey3.document_template_value = pAsset.city; loDocumentTemplateKeys.Add(loDocumentTemplateKey3); loDocumentTemplateKey4.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Ilce).ToString(); loDocumentTemplateKey4.document_template_value = pAsset.district; loDocumentTemplateKeys.Add(loDocumentTemplateKey4); loDocumentTemplateKey5.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Ada).ToString(); loDocumentTemplateKey5.document_template_value = pAsset.block_number; loDocumentTemplateKeys.Add(loDocumentTemplateKey5); loDocumentTemplateKey6.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Parsel).ToString(); loDocumentTemplateKey6.document_template_value = pAsset.plot_number; loDocumentTemplateKeys.Add(loDocumentTemplateKey6); loDocumentTemplateKey7.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Adres).ToString(); loDocumentTemplateKey7.document_template_value = pAsset.address; loDocumentTemplateKeys.Add(loDocumentTemplateKey7); loDocumentTemplateKey8.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Adsoyad).ToString(); loDocumentTemplateKey8.document_template_value = string.IsNullOrEmpty(pCustomer.company_name) ? pCustomer.customer_name + " " + pCustomer.customer_surname : pCustomer.company_name; loDocumentTemplateKeys.Add(loDocumentTemplateKey8); loDocumentTemplateKey9.document_template_key = ((int)ThkAgreement.ThkSatisSartname.TcKimlik).ToString(); loDocumentTemplateKey9.document_template_value = string.IsNullOrEmpty(pCustomer.tax_no) ? pCustomer.identity_no : pCustomer.tax_no; loDocumentTemplateKeys.Add(loDocumentTemplateKey9); loDocumentTemplateKey10.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Posta).ToString(); loDocumentTemplateKey10.document_template_value = pCustomer.address ?? ""; loDocumentTemplateKeys.Add(loDocumentTemplateKey10); loDocumentTemplateKey11.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Gsm).ToString(); loDocumentTemplateKey11.document_template_value = pCustomer.phone; loDocumentTemplateKeys.Add(loDocumentTemplateKey11); loDocumentTemplateKey12.document_template_key = ((int)ThkAgreement.ThkSatisSartname.Eposta).ToString(); loDocumentTemplateKey12.document_template_value = pCustomer.mail; loDocumentTemplateKeys.Add(loDocumentTemplateKey12); return(loDocumentTemplateKeys); }
private void ProcessDto(AssetDto dto) { if (MyInvocation.BoundParameters.ContainsKey(nameof(Description))) { dto.Description = Description; } if (dto.ValueScope == AssetDtoValueScope.Global && ParameterSetName != AddAsset.RobotValuesSet) { switch (ParameterSetName) { case NewAssetRobotValue.TextValueSet: dto.ValueType = AssetDtoValueType.Text; dto.StringValue = TextValue; break; case NewAssetRobotValue.IntValueSet: dto.ValueType = AssetDtoValueType.Integer; dto.IntValue = IntValue; break; case NewAssetRobotValue.BoolValueSet: dto.ValueType = AssetDtoValueType.Bool; dto.BoolValue = BoolValue; break; case NewAssetRobotValue.DBConnectionStringSet: dto.ValueType = AssetDtoValueType.DBConnectionString; dto.StringValue = DBConnectionString; break; case NewAssetRobotValue.HttpConnectionStringSet: dto.ValueType = AssetDtoValueType.HttpConnectionString; dto.StringValue = HttpConnectionString; break; case NewAssetRobotValue.KeyValueListSet: dto.ValueType = AssetDtoValueType.KeyValueList; dto.KeyValueList = KeyValueList.ToKeyList(); break; case NewAssetRobotValue.WindowsCredentialSet: dto.ValueType = AssetDtoValueType.WindowsCredential; dto.CredentialUsername = WindowsCredential.UserName; dto.CredentialPassword = WindowsCredential.ExtractPassword(); break; case NewAssetRobotValue.CredentialSet: dto.ValueType = AssetDtoValueType.Credential; dto.CredentialUsername = Credential.UserName; dto.CredentialPassword = Credential.ExtractPassword(); break; } } else if (dto.ValueScope == AssetDtoValueScope.PerRobot && ParameterSetName == AddAsset.RobotValuesSet) { dto.RobotValues = dto.RobotValues.MergeAddRemove( AddRobotValues?.Select(rv => rv.ToDto()), // Robot values to add to the list RemoveRobotIdValues?.Select(rid => new AssetRobotValueDto { RobotId = rid }), // Robot IDs to remove, expressed as AssetRobotValue for sake of MergeAddRemove.. IEnumerable<T> ... rv => rv.RobotId) // T->K Key selector expression .ToList(); } else if (ParameterSetName != DescriptionSet) { throw new RuntimeException($"Mismatched parameters and asset scope: {ParameterSetName}:{dto.ValueScope}"); } HandleHttpOperationException(() => Api_19_10.Assets.PutById(dto.Id.Value, dto)); }
/// <summary> /// Edit an asset /// </summary> /// <remarks> /// Required permissions: Assets.Edit. /// </remarks> /// <param name='id'> /// key: Id /// </param> /// <param name='assetDto'> /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="HttpOperationException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse> PutByIdWithHttpMessagesAsync(long id, AssetDto assetDto, Dictionary <string, List <string> > customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { if (assetDto == null) { throw new ValidationException(ValidationRules.CannotBeNull, "assetDto"); } if (assetDto != null) { assetDto.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("id", id); tracingParameters.Add("assetDto", assetDto); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "PutById", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "odata/Assets({Id})").ToString(); _url = _url.Replace("{Id}", System.Uri.EscapeDataString(Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(id, Client.SerializationSettings).Trim('"'))); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (assetDto != null) { _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(assetDto, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); if (_httpResponse.Content != null) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); } else { _responseContent = string.Empty; } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public AssetCreatedEvent(AssetDto asset) { Asset = asset; }