Sitefinity new Document SetBoost - sitefinity

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

Related

Index Out of Bound exception while rendering RDLC Reports in ASP.NET Core

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);

What Should be done in place of the error showing on my sql table in the code below?

{
using (RegistrationEntities1 dc = new RegistrationEntities1())
{
var state = dc.tblState.ToList(); //It provides an error here pointing towards the table
List<SelectListItem> li = new List<SelectListItem>();
li.Add(new SelectListItem { Text = "--Select State--", Value = "0" });
foreach (var m in state)
{
li.Add(new SelectListItem { Text = m.statename, Value = m.stateid.ToString()});
ViewBag.state = li;
}
}
}
Error: CS1061 'RegistrationEntities1' does not contain a definition for 'tblState' and no accessible extension method 'tblState' accepting a first argument of type 'RegistrationEntities1' could be found (are you missing a using directive or an assembly reference?)

Create Defect in Rally using REST API and C#

I am trying to programatically create a defect in Rally using C#. Below is my code and errors i am getting is
Error in creating defect!!!
Cannot parse object reference from "Unspecified"
Code:
RallyRestApi restApi;
restApi = new RallyRestApi(webServiceVersion: "v2.0");
//after successful authentication...
String workspaceRef = "/workspace/12345";
String projectRef = "/project/78321";
DynamicJsonObject badDefect = new DynamicJsonObject();
newDefect["Name"] = "Defect " + DateTime.Now;
newDefect["Project"] = projectRef ;
newDefect["Environment"] = "test branch";
newDefect["c_DefectSourceNEW"] = "old";
newDefect["Severity"] = "minor";
newDefect["Release"] = "Unspecificed";
CreateResult createResult = restApi.Create("Defect", newDefect);
if (createResult.Success == true)
{
Console.WriteLine("Defect created Successfully!!!");
}
else
{
Console.WriteLine("Error in creating defect!!!");
}
foreach (string s in createResult.Errors)
{
Console.WriteLine(s);
}
Can some one suggest what i might be doing incorrectly and in general the correct way to sepcify "Release" value for a defect???
All object relationships in wsapi are represented by refs. So you just need to set the value as its ref rather than its name, much like you're already doing with workspace and project.
Thanks Kyle for inputs. Since the Release ID was mandatory i solved by below for Release Input:
Request reRequest = new Request("Release");
reRequest.Workspace = workspaceRef;
reRequest.Query = new Query("Project", Query.Operator.Equals, projectRef);
QueryResult queryResult = restApi.Query(reRequest);
string reprojectRef = null;
foreach (DynamicJsonObject result in queryResult.Results)
{
reprojectRef = result["_ref"];
Console.WriteLine(reprojectRef);
Console.WriteLine("Name: " + result["Name"]);
if (result["Name"] == "MyReleaseName")
{
newDefect["Release"] = result["_ref"];
}
}

how can I query for releases / iterations via rally c# api?

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!");
}
}
}
}

Set the value of custom webpart property in c#

How to set the value of custom webpart property Programatically in C#.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite SiteCollection = new SPSite(mySiteGuid))
{
SPWeb myWeb = SiteCollection.OpenWeb(myWebGuid);
myWeb .AllowUnsafeUpdates = true;
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
mgr = myWeb.GetLimitedWebPartManager ("default.aspx",System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts)
{
if (myWebPart.Title == "Other Webpart Name")
{
myWebPart.Visible = ! myWebPart.Visible;
myWeb.Update();
break;
}
}
}
});
I have a custom property in the webpart of type string to get the input from the user.
I wanted to updated the value of the property from c#.
Is there any way to set the value?
TIA
Try myWebPart.Update() instead of myWeb.Update().
Maybe it's a bit late for the answer, but here i let a piece of code i used for this.
var webCollection = new SPSite("http://mySharePointSite").AllWebs;
foreach (SPWeb web in webCollection)
{
var landingPageReference = #"/Pages/default.aspx";
var page = web.GetFile(landingPageReference);
if (!page.Exists)
continue;
page.CheckOut();
var spLimitedWebPartManager = web.GetLimitedWebPartManager(page.ServerRelativeUrl, PersonalizationScope.Shared);
foreach (WebPart webPartItem in spLimitedWebPartManager.WebParts)
{
if (webPartItem.Title.Equals("myWebPartTitle"))
{
// Specify Properties to change here
webPartItem.ChromeType = PartChromeType.Default;
webPartItem.Description = "AGAIN CHANGED";
// Save made changes
spLimitedWebPartManager.SaveChanges(webPartItem);
break;
}
}
page.CheckIn("Add Comment if desired");
page.Publish("Add Comment if desired");
web.Update();
web.Dispose();
}