In the below code I want ordernumber of a order in which document are drag and drop in attachment folder and title of that document .I will send these two in parameter as payload in api call when attachmentadded event trigger.
And it show red line in "GetService<>()" with message that it is not in current context
I am sharing my code below please let me know if you find any mistake in this :
using SoftPro.Accounting.Client;
using SoftPro.ClientModel;
using SoftPro.EntityModel.Packaging;
using SoftPro.OrderTracking.Client;
using SoftPro.OrderTracking.Client.Orders;
using SoftPro.Select.Client;
using SoftPro.Select.Service;
using SoftPro.ServerModel;
using System;
using System.Runtime.InteropServices;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net;
using System.Diagnostics;
namespace ServerPackage1
{
[Guid("026ae76b-5489-447a-bafe-63ca269b69c6")]
partial class MyPackage : Package
{
// This method is called when the package is loaded by the server.
protected override void OnInitialize()
{
// Listen to the environment started event.
ISelectServerEnvironment environment = GetService<ISelectServerEnvironment>();
environment.Started += SelectServerEnvironment_Started;
}
// This method is called when the server is finished loading packages and services.
private void SelectServerEnvironment_Started(object sender, System.EventArgs e)
{
// Unhook this event as it is no longer needed.
ISelectServerEnvironment environment = GetService<ISelectServerEnvironment>();
environment.Started -= SelectServerEnvironment_Started;
IOrder order = GetService<IOrderStore>();
order.AttachmentAdded += Order_AttachmentAdded;
}
// This method is called when an attachment is added
private void Order_AttachmentAdded(object sender, AttachmentItemEventArgs e)
{
if (e.Item is IAttachmentFile)
{
IAttachmentFile file = (IAttachmentFile)e.Item;
string extension = file.Extension; // i.e. ".xml"
System.Guid fileID = file.ID; // Proprietary guid used for internal tracking.
string fleName = file.Name;// i.e. "hello"
string filePath = file.Path; // i.e. "\\\\XAT22000149\\Attachments\\hello.xml"
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("
http://localhost:50722/escrowDataService.asmx/");
//HTTP GET
var responseTask = client.GetAsync("updateDocuments?orderId='" + orderNumber + "'&documents='" + documents + "'&rootId='" + rootId + "'+&officeId='" + officeid);
responseTask.Wait();
var result = responseTask.Result;
if (result.IsSuccessStatusCode)
{
Trace.TraceInformation("Email success:New document added email send");
// You must close or flush the trace to empty the output buffer.
Trace.Flush();
}
}
}
catch (Exception ex)
{
Trace.TraceError($"Exception while sending mail for new added document: {ex}");
}
}
}
}
}