Loader Event Complete function only being called once - apache-flex

So, I'm trying to load resources, add them to a dictionary, and have a drawing method search through that dictionary and draw based on certain predicates. I have a function that iterates through an Vector of Strings, calling on an instance of Loader to load them instantiated as a URLRequest.
private function loadImages(urls:Vector.<String>):void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
var loadResource:Function = function(item:String,index:int,vector:Vector.<String>):void
{
loader.load(new URLRequest(item));
}
urls.forEach(loadResource);
}
I then have an event handler that's handling the load completion, calling a drawing method that finds the Loaded bitmap in a Dictionary.
public function completeHandler(event:Event):void
{
var loader:Loader = Loader(event.target.loader);
var bm:BitmapData = new BitmapData(loader.width,loader.height,false);
bm.draw(loader,new Matrix());
this.bmDict[loader.contentLoaderInfo.url] = bm;
trace("complete handler" + loader.contentLoaderInfo.url);
trace(this.bmDict[loader.contentLoaderInfo.url]);
this.drawSprite(loader.contentLoaderInfo.url);
}
My drawsprite function
public function drawSprite(resourceUrl:String):void
{
var drawFunct:Function = function(spr:Dictionary,index:int,vector:Vector.):void
{
var sprRen:SpriteRenderer = new SpriteRenderer();
trace(resourceUrl.search("blue"));
trace(resourceUrl.search("drkOrange"));
trace(resourceUrl.search("green"));
trace(resourceUrl.search("ltblue"));
trace(resourceUrl.search("orange"));
trace(resourceUrl.search("pink"));
trace(resourceUrl.search("purple"));
trace(resourceUrl.search("red"));
trace(resourceUrl.search("yellow"));
trace(spr.color);
if((resourceUrl.search("blue") != -1) && (spr["color"] == 1)) {
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("drkOrange") != -1) && (spr["color"] == 2)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("green") != -1) && (spr["color"] == 3)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("ltblue") != -1) && (spr["color"] == 4)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("orange") != -1) && (spr["color"] == 5)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("pink") != -1) && (spr["color"] == 6)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("purple") != -1) && (spr["color"] == 7)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("red") != -1) && (spr["color"] == 8)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
} else if ((resourceUrl.search("yellow") != -1) && (spr["color"] == 9)){
var bigBm:BitmapData = sprRen.renderType(spr["type"],bmDict[resourceUrl]);
spr["sprite"].graphics.beginBitmapFill(bigBm,null,true,false);
spr["sprite"].graphics.drawRect(0,0,BIG_SPRITE_SCALE,BIG_SPRITE_SCALE);
spr["sprite"].graphics.endFill();
}
}
sprites.forEach(drawFunct);
}
So the issue is: Only the first images in my Vector are drawing. Upon further inspection, I found that the completeHandler was only being called once (I put a trace in the complete handler to check). However, the Loader is invoking load everytime the loop iterates. I tried instantiating separate loaders for each resource, just to see if it would work, but I had no luck with that. Do I need to make separate loaders and event handlers? Or am I just not using Loader correctly?

You are using only one loader to load multiple files in the same time, it can't work, a Loader can handle only one file at the same time.
So you need one loader by resource or load resources one by one if you want to use only one loader.

Related

Datatables Object Reference not set to instance of an object for one variable

This is my datatables serverside implementation. FilterInput contains 5 variables:
Level <- string
Message <- string
Exception <-string
StartDate <- DateTime
EndDate <- DateTime
For some reason when I run this code as it is, I will always get this error:
{System.NullReferenceException: Object reference not set to an
instance of an object.
This is referring to this line:
data = data.Where(
u => u.Level.ToString().ToLower().Contains(FilterInput.Level.ToLower()) &&
u.Message.ToString().ToLower().Contains(FilterInput.Message.ToLower()) &&
u.Exception.ToString().ToLower().Contains(FilterInput.Exception.ToLower())
).ToList();
However, if I remove the search for FilterInput.Exception, everything runs fine again. I have tested it with input ("abc") or without input ("") and the results are the same. The other FilterInputs don't have the same error.
public JsonResult Search(SearchViewModels Input, EventLogsSearchViewModel FilterInput)
{
JsonResult result = new JsonResult(null);
try
{
var data = dbContext.EventLogs.ToList();
int totalRecords = data.Count;
var modelStructure = new Dictionary<int, string>();
modelStructure.Add(1, "Level");
modelStructure.Add(2, "TimeStamp");
modelStructure.Add(3, "LogEvent");
modelStructure.Add(4, "Message");
modelStructure.Add(5, "MessageTemplate");
modelStructure.Add(6, "Exception");
modelStructure.Add(7, "Properties");
var StartDate = FilterInput.StartDate != default(DateTime);
var EndDate = FilterInput.EndDate != default(DateTime);
if ((!string.IsNullOrEmpty(FilterInput.Level) && !string.IsNullOrWhiteSpace(FilterInput.Level)) ||
(!string.IsNullOrEmpty(FilterInput.Message) && !string.IsNullOrWhiteSpace(FilterInput.Message)) ||
(!string.IsNullOrEmpty(FilterInput.Exception) && !string.IsNullOrWhiteSpace(FilterInput.Exception)) ||
(StartDate && EndDate))
{
data = data.Where(
u => u.Level.ToString().ToLower().Contains(FilterInput.Level.ToLower()) &&
u.Message.ToString().ToLower().Contains(FilterInput.Message.ToLower()) &&
u.Exception.ToString().ToLower().Contains(FilterInput.Exception.ToLower())
).ToList();
data = data.Where(u => u.TimeStamp >= FilterInput.StartDate && u.TimeStamp <= FilterInput.EndDate).ToList();
}
if (!(string.IsNullOrEmpty(Input.Order) && string.IsNullOrEmpty(Input.OrderDir)))
{
var columnName = modelStructure.FirstOrDefault(f => f.Key == Convert.ToInt32(Input.Order));
data = data.AsQueryable().OrderBy(columnName.Value + " " + Input.OrderDir).ToList();
}
int recFilter = data.Count;
data = data.Skip(Input.StartRec).Take(Input.PageSize).ToList();
var modifiedData = data.Select(u => new EventLogsListViewModel
{
Id = u.Id,
Message = u.Message,
MessageTemplate = u.MessageTemplate,
Level = u.Level,
TimeStamp = u.TimeStamp,
Exception = u.Exception,
Properties = u.Properties,
LogEvent = u.LogEvent
});
result = this.Json(new
{
draw = Convert.ToInt32(Input.Draw),
recordsTotal = totalRecords,
recordsFiltered = recFilter,
data = modifiedData,
order = Input.Order,
orderdir = Input.OrderDir
});
}
catch (Exception e)
{
logger.LogError(e, LoggingGlobals.LoadingException);
}
return result;
}
EDIT: The exception still happens even when FilterInput.Exception is not null

How to populate data related to an item from the location which is same for all items in Xamarin.forms

I am developing an xamarin.forms app ,I have various fields like Item Name ,Item Number and location ,here Location of all the items are same ,by entering names or number of the items the values are generated automatically because name and number are unique but since the location number is common is for all the items I am not able to populate correct data related to a particular field ,I am using sqlite database in my project can anyone please suggest me on what basis can I generate related values ?
Here is the code
public async void OnSearch_Location(object o, EventArgs args)
{
if (location.Text == string.Empty || location.Text == null)
{
await Navigation.PushAsync(new ListValuePage("Location", filePath,
pos, list));
}
else
{
for (int p = 0; p < list.Count; p++)
{
if (list.ElementAt(p).Aisle + "." + list.ElementAt(p).Bin +
"." + list.ElementAt(p).Level == location.Text)
{
line.Text =
Convert.ToString(list.ElementAt(p).Line_Number);
location.Text = list.ElementAt(p).Aisle + "." +
list.ElementAt(p).Bin + "." + list.ElementAt(p).Level;
item.Text = list.ElementAt(p).Item_Number;
name.Text = list.ElementAt(p).Name;
if (list.ElementAt(p).Order_Qty == 0)
{
order_uom.Text = "";
}
else
{
order_qty.Text =
Convert.ToString(list.ElementAt(p).Order_Qty);
}
order_uom.Text = list.ElementAt(p).Order_UOM;
if (list.ElementAt(p).Consumption_UOM == string.Empty ||
list.ElementAt(p).Consumption_UOM == null)
{
consume_lbl.IsVisible = false;
consume_qty.IsVisible = false;
consume_uom.IsVisible = false;
}
else
{
consume_lbl.IsVisible = true;
consume_qty.IsVisible = true;
consume_uom.IsVisible = true;
if (list.ElementAt(p).Consumption_Qty == 0)
{
consume_qty.Text = "";
}
else
{
consume_qty.Text =
Convert.ToString(list.ElementAt(p).Consumption_Qty);
}
consume_uom.Text = list.ElementAt(p).Consumption_UOM;
}
}
}
}
}

web api call performance tuning

I am trying to figure find why my api is taking ~5 secs working on 1000 records,is that good or bad?I want to know what tools are there in asp.net webapi to figure out which piece of code or where its consuming time and fine tune the performance
CODE:-
List<LookaheadRunInfo> lookaheadRunsInfo = new List<LookaheadRunInfo>();
List<lookahead_run> lookaheadRunData = new List<lookahead_run>();
if (!filterCriteria.labeled)
{
lookaheadRunData = bitDB.lookahead_run.Where(x => x.lookahead_run_status == null && x.submission_time != null).OrderByDescending(x => x.submission_time).Skip(filterCriteria.PageNumber * filterCriteria.PageSize).Take(filterCriteria.PageSize).ToList();
}
else
{
lookaheadRunData = bitDB.lookahead_run.OrderByDescending(x => x.submission_time).Skip(filterCriteria.PageNumber * filterCriteria.PageSize).Take(filterCriteria.PageSize).ToList();
}
foreach (var lookaheadRunRow in lookaheadRunData)
{
var lookaheadRunInfo = new LookaheadRunInfo();
var lookaheadRunId = lookaheadRunRow.lookahead_run_id;
lookaheadRunInfo.ECJobLink = lookaheadRunRow.ec_job_link;
lookaheadRunInfo.UserSubmitted = lookaheadRunRow.submitted_by;
lookaheadRunInfo.SubmittedTime = lookaheadRunRow.submission_time.ToString();
lookaheadRunInfo.RunStatus = lookaheadRunRow.lookahead_run_status;
var completionTime = lookaheadRunRow.completion_time;
if (completionTime == null)
{
lookaheadRunInfo.ElapsedTime = (DateTime.UtcNow - lookaheadRunRow.submission_time).ToString();
}
else
{
lookaheadRunInfo.ElapsedTime = (lookaheadRunRow.completion_time - lookaheadRunRow.submission_time).ToString();
}
List<String> gerrits = new List<String>();
List<string> lookaheadRunChangeListIds = new List<string>();
if (!filterCriteria.labeled)
{
lookaheadRunChangeListIds = (from lrcl in bitDB.lookahead_run_change_list
join cl in bitDB.change_lists on lrcl.change_list_id equals cl.change_list_id
where lrcl.lookahead_run_id == lookaheadRunId
//and cl.change_list_id not in (select clcl.change_list_id from component_labels_change_lists as clcl)
//where !(from clcl in bitDB.component_labels_change_lists select clcl.change_list_id).Contains(cl.change_list_id)
where !bitDB.component_labels_change_lists.Any(clcl => clcl.change_list_id == cl.change_list_id)
select cl.change_list.ToString()).ToList();
}
else
{
lookaheadRunChangeListIds = (from lrcl in bitDB.lookahead_run_change_list
join cl in bitDB.change_lists on lrcl.change_list_id equals cl.change_list_id
where lrcl.lookahead_run_id == lookaheadRunId
select cl.change_list.ToString()).ToList();
}
//bitDB.Log = Console.Out;
//lookaheadRunInfo.gerrits = gerrits;
lookaheadRunInfo.gerrits = lookaheadRunChangeListIds;
if (lookaheadRunChangeListIds.Count != 0 && filterCriteria.labeled == false)
{
lookaheadRunsInfo.Add(lookaheadRunInfo);
}
else if (filterCriteria.labeled == true)
{
lookaheadRunsInfo.Add(lookaheadRunInfo);
}
}
return lookaheadRunsInfo;

how to make the drop down list to be visible for certain user only in asp.net?

i am trying to make the drop down list to be visible for certain user only. for example for user =1 i want the drop down list to be visible and for user = 2 i don't want the drop down list to be visible.
i have tried this.
if ((Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 1) ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 2 ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 4)
{
ddlSpecialist.Visible = true;
ddlSpecialist.DataSource = Lundbeck.Web.BusinessLogic.FrequencyReport.GetFrequencyReportbySpecialistList();
ddlSpecialist.DataTextField = "Repcode";
ddlSpecialist.DataValueField = "Repcode";
ddlSpecialist.DataBind();
ddlSpecialist.Items.Insert(0, new ListItem("All", "0"));
ddlSpecialist.SelectedValue = "0";
if (Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 3)
{
ddlSpecialist.Visible = false;
}
}
i dont get the result that i want when i do this. why is that?? thanks in advance.
What are you trying to do please see you if condition you are checking if user==1 || user==2 || user==4
than you are showing dropdownlist and in same if condition you are checking if user==3 how is this possible if user==1 || user==2 || user==4 than it cannot be ==3 change your code like this.
if ((Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 1) ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 2 ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 4)
{
ddlSpecialist.Visible = true;
ddlSpecialist.DataSource = Lundbeck.Web.BusinessLogic.FrequencyReport.GetFrequencyReportbySpecialistList();
ddlSpecialist.DataTextField = "Repcode";
ddlSpecialist.DataValueField = "Repcode";
ddlSpecialist.DataBind();
ddlSpecialist.Items.Insert(0, new ListItem("All", "0"));
ddlSpecialist.SelectedValue = "0";
}
else if (Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 3)
{
ddlSpecialist.Visible = false;
}

How to count duplicate items in XMLList and assign them into an ArrayCollection?

I've following XMLList ,
<party/>
<party/>
<party/>
<party>A</party>
<party>B</party>
<party>C</party>
<party>A</party>
<party>B</party>
<party>C</party>
<party>D</party>
<party>E</party>
<party>D</party>
<party>A</party>
<party/>
<party>C</party>
I would like eliminate blank node and to make an ArrayCollection like ( with count of individual party),
tArr = new ArrayCollection([ {Party:"A", Count:3},
{Party:"B", Count:2},
{Party:"C", Count:3},
{Party:"D", Count:2},
{Party:"E", Count:1},
]);
Thanks in advance.
This is untested and may not be the most efficient, but should work:
var partyDict:Dictionary = new Dictionary();
var parties:ArrayCollection = new ArrayCollection();
var xml:XML = <root><party/><party/><party/><party>A</party><party>B</party><party>C</party><party>A</party><party>B</party><party>C</party><party>D</party><party>E</party><party>D</party><party>A</party><party/><party>C</party></root>;
for each (var p:XML in xml.party) {
var val:String = p.toString();
if ((val != null) && StringUtil.trim(val).length > 0) {
if (partyDict[val] != null) {
partyDict[val] = (partyDict[val] as int) + 1; // may simply be able to do partyDict[val]++;
} else {
partyDict[val] = 1;
}
}
}
for (var key:Object in partyDict) {
var o:Object = new Object();
o.Party = key;
o.Count = partyDict[key];
parties.addItem(o);
}
If you have the list of possible parties it's just:
var partiesObjs:ArrayCollection = new ArrayCollection();
var xml:XML = <root><party/><party/><party/><party>A</party><party>B</party><party>C</party><party>A</party><party>B</party><party>C</party><party>D</party><party>E</party><party>D</party><party>A</party><party/><party>C</party></root>;
var parties:Array = ["A","B","C","D"]
for each(var p:String in parties){
var count:int = xml..party.(toString() == p).length()
partiesObjs.addItem( {Party:p, Count:count} )
}

Resources