I am collecting external data and then doing an ServiceBus.ResolveService<ISearchService>().UpdateIndex. This is working great but I wanted to SetBoost on the new Document. I have created an flag setboost with is using doc.SetBoost(1.5f); but I am getting a runtime error. Is this the correct way to set the boost score?
Severity Code Description Project File Line Suppression State Suppression State
Error CS1061 'Document' does not contain a definition for 'SetBoost' and no accessible extension method 'SetBoost' accepting a first argument of type 'Document' could be found (are you missing a using directive or an assembly reference?)\
public static void ExternalIndexerAdd(ExternalIndexModel externalIndexer,boolean setBoost)
{
try
{
var fields = new List<IField>();
var identityFld = new Field();
identityFld.Name = "IdentityField";
identityFld.Value = externalIndexer.IdentityField;
fields.Add(identityFld);
var titleField = new Field();
titleField.Name = "Title";
titleField.Value = externalIndexer.TitleField;
fields.Add(titleField);
var contentField = new Field();
contentField.Name = "Content";
contentField.Value = externalIndexer.ContentField;
fields.Add(contentField);
var linkField = new Field();
linkField.Name = "Link";
linkField.Value = externalIndexer.LinkField;
fields.Add(linkField);
var lastModifiedField = new Field();
lastModifiedField.Name = "LastModified";
lastModifiedField.Value = externalIndexer.LastModifiedField;
fields.Add(lastModifiedField);
var doc = new Document(fields, String.Format("{0}", "IdentityField"));
if (SetBoost == true){
doc.SetBoost(1.5f);
}
ServiceBus.ResolveService<ISearchService>().UpdateIndex("nccn-search-index", new List<IDocument>() { doc });
}
catch (Exception ex)
{
}
}
In order to accomplish this I believe you will need to customize the search scoring of Sitefinity's lucene search index. Here is the search API available: https://www.progress.com/documentation/sitefinity-cms/for-developers-customize-the-lucene-search-scoring
My ASP.NET Core MVC project has several reports. To render the reports as PDF, I'm using AspNetCore.Reporting library.
This library works fine for a single report but due to some cache issues it throws an exception while generating another report. The solution I found on the internet was to run report generation as a new process but I don't know how to implement that.
I found the suggestion to use Tmds.ExecFunction to run report generation as a seperate process. But I dont know how to pass parameters to the function.
Here is my code:
string ReportName = "invoiceDine";
DataTable dt = new DataTable();
dt = GetInvoiceItems(invoiceFromDb.Id);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("bParam", $"{invoiceFromDb.Id}");
param.Add("gParam", $"{salesOrderFromDb.Guests}");
param.Add("tParam", $"{invoiceFromDb.Table.Table}");
param.Add("dParam", $"{invoiceFromDb.Time}");
param.Add("totalP", $"{invoiceFromDb.SubTotal}");
param.Add("t1", $"{tax1}");
param.Add("t2", $"{tax2}");
param.Add("tA1", $"{tax1Amount}");
param.Add("tA2", $"{tax2Amount}");
param.Add("AT1", $"{totalAmountWithTax1}");
param.Add("AT2", $"{totalAmountWithTax2}");
param.Add("terminalParam", $"{terminalFromDb.Name}");
param.Add("addressParam", $"{t.Address}");
param.Add("serviceParam", "Service Charges of applicable on table of " + $"{personForServiceCharges}" + " & Above");
var result = reportService.GenerateReport(ReportName, param, "dsInvoiceDine", dt);
return File(result,"application/Pdf");
This is my version of the function:
``` public byte[] GenerateReport(string ReportName, Dictionary<string,string> Parameters,string DataSetName,DataTable DataSource )
{
string guID = Guid.NewGuid().ToString().Replace("-", "");
string fileDirPath = Assembly.GetExecutingAssembly().Location.Replace("POS_Website.dll", string.Empty);
string ReportfullPath = Path.Join(fileDirPath, "\\Reports");
string JsonfullPath = Path.Join(fileDirPath,"\\JsonFiles");
string rdlcFilePath = string.Format("{0}\\{1}.rdlc", ReportfullPath, ReportName);
string generatedFilePath = string.Format("{0}\\{1}.pdf", JsonfullPath, guID);
string jsonDataFilePath = string.Format("{0}\\{1}.json", JsonfullPath, guID);
File.WriteAllText(jsonDataFilePath, JsonConvert.SerializeObject(DataSource));
FunctionExecutor.Run((string[] args) =>
{
// 0 : Data file path - jsonDataFilePath
// 1 : Filename - generatedFilePath
// 2 : RDLCPath - rdlcFilePath
ReportResult result;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.GetEncoding("windows-1252");
LocalReport report = new LocalReport(args[2]);
DataTable dt = JsonConvert.DeserializeObject<DataTable>(File.ReadAllText(args[0]));
report.AddDataSource(args[3], dt);
result = report.Execute(RenderType.Pdf, 1,Parameters);
using (var fs = new FileStream(args[1], FileMode.Create, FileAccess.Write))
{
fs.Write(result.MainStream);
}
}, new string[] {jsonDataFilePath, generatedFilePath, rdlcFilePath, DataSetName });
var memory = new MemoryStream();
using (var stream = new FileStream(Path.Combine("", generatedFilePath), FileMode.Open))
{
stream.CopyTo(memory);
}
File.Delete(generatedFilePath);
File.Delete(jsonDataFilePath);
memory.Position = 0;
return memory.ToArray();
}
But it throws exception "Field marshaling is not supported by ExecFunction" on line:
var result = reportService.GenerateReport(ReportName, param, "dsInvoiceDine", dt);
No Need to run report generation as a seperate process. Just Dont Pass extension as 1
in:
var result = localReport.Execute(RenderType.Pdf, 1, param);
The Solution is:
int ext = (int)(DateTime.Now.Ticks >> 10);
var result = localReport.Execute(RenderType.Pdf, ext, param);
I want to use the HttpBrowserCapabilities in .net-core. I tried it following way:
var userAgent = httpContext.Request.Headers["user-agent"];
var userBrowser = new HttpBrowserCapabilities { Capabilities = new Hashtable { { string.Empty, userAgent } } };
var factory = new BrowserCapabilitiesFactory();
factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
var mobileString = userBrowser.IsMobileDevice ? "(mobil)" : string.Empty;
var browserString = $"{userBrowser.Browser} version {userBrowser.Version} {mobileString} OS: {userBrowser.Platform}";
But an InvalidCastException is thrown. How ca i get this code retun the right values?
Got it!
userAgent is of the type Microsoft.Extensions.Primitives.StringValues.
But HttpBrowserCapabilities expects a string as input parameter.
Therefore i had to check if userAgent contains a value (userAgent.Any()) and use the following code
var userBrowser = new HttpBrowserCapabilities {Capabilities = new Hashtable {{string.Empty, userAgent.First()}}};
I am using NEST to connect to the elasticsearch server:
var searchBoxUri = new Uri("xxx");
var elasticSettings = new ConnectionSettings(searchBoxUri).SetDefaultIndex("xxx");
var client = new ElasticClient(elasticSettings);
I got this error:
'ElasticClient' is a 'namespace' but is used like a 'type'
Try this one:
var client = new Nest.ElasticClient(elasticSettings);
You should use full qualified class name.
You can use something like this :
private ElasticClient _Instance;
var elasticSearchURI = ConfigurationManager.AppSettings["elasticSearchURI"];
var node = new Uri(elasticSearchURI);
var connectionPool = new SniffingConnectionPool(new[] { node });
var config = new ConnectionSettings(connectionPool, defaultIndex)
.SniffOnConnectionFault(false)
.SniffOnStartup(false)
.DisablePing();
_Instance = new ElasticClient(config);
Where defaultIndex is a string with the name of the index .
I am trying to query on both Release and Iteration so I can fill out a drop down list with these various values. I'm not quite sure how to do this, however. What are the members of the object that come back via the query if we are able to do this? (Name, FormattedID, CreationDate, etc). Do we just create a new request of type "Release" and "Iteration" ?
Thanks!
Here is a code that queries on releases based on a project reference. If this project is not in a default workspace of the user that runs the code we either need to hardcode the workspace reference or get it from the project.
class Program
{
static void Main(string[] args)
{
RallyRestApi restApi;
restApi = new RallyRestApi("user#co.com", "TopSecret1984", "https://rally1.rallydev.com", "1.40");
var projectRef = "/project/22222222"; //use your project OID
DynamicJsonObject itemWorkspace = restApi.GetByReference(projectRef, "Workspace");
var workspaceRef = itemWorkspace["Workspace"]["_ref"];
Dictionary<string, string> result = new Dictionary<string, string>();
try
{
Request request = new Request("Release");
request.ProjectScopeDown = false;
request.ProjectScopeUp = false;
request.Workspace = workspaceRef;
request.Fetch = new List<string>()
{
"Name"
};
// request.Query = new Query("Project.ObjectID", Query.Operator.Equals, "22222222"); //also works
request.Query = new Query("Project", Query.Operator.Equals, projectRef);
QueryResult queryResult = restApi.Query(request);
foreach (var r in queryResult.Results)
{
Console.WriteLine("Name: " + r["Name"]);
}
}
catch
{
Console.WriteLine("problem!");
}
}
}
}