I have a number of objects that I need to create and add to an array. However the code below seems dirty and difficult to maintain in the long run. What I'm thinking is, I should store the Name and Value properties in a table and build each comCommand object at runtime.
However, I'm not exactly sure what the best method to about doing this... Reflection, Activator.CreateInstance or some kind of object factory?
Thanks in advance.
var engine = new comCommand() { commandName = "-e", commandValue = "PNetTNative" };
var outputFile = new comCommand() { commandName = "-f", commandValue = OutputFile };
var groupSize = new comCommand() { commandName = "-GroupSizeParamInput1ParamsIn", commandValue = GroupSize };
var pagesPerSheet = new comCommand() { commandName = "-PagesPerSheetParamInput1ParamsIn", commandValue = PagesPerSheet };
var outputFileName = new comCommand { commandName = "-OutputFileNameParamInput1ParamsIn", commandValue = OutputFileName };
var duplex = new comCommand { commandName = "-DuplexParamInput1ParamsIn", commandValue = Duplex };
var processId = new comCommand { commandName = "-ProcessIDParamInput1ParamsIn", commandValue = ProcessID };
var request = new comRunWorkFlowReq();
request.command = new[] { engine, outputFile, groupSize, pagesPerSheet, outputFileName, duplex, processId };
Create a command constructor (as Kirk suggested) and keep it as you have: multiple comCommand("-e","PNetTNative") etc calls.
The reason for keeping it in code is you get compiler-time type and error checking... Yes, you can do it at runtime (various methods) but for just 7 declarations, it's best to keep it at compile time.
Related
I'm currently stuck with this issue, and really got 0 ideas on how to resolve it. So I'm basically calling the export function after setting this data. Without async and dummy data It works, on implementing this, I'm not able to export anything. This is what I've done by far, and I'm not sure what I am doing wrong here. IF you have any idea, please help me. I can also provide more code if needed.
this is the code:
private async Task<IEnumerable> OnExport(SearchCriteria cr)
{
var sr = await GetResult(cr);
var results = sr.Results;
var exportData = results.Select(async export =>
{
var data = await dataService.GetById(export.Id);
var pAddress = export.ContactInformation?.Addresses.FirstOrDefault(x => x.AddressType == Framework.Contracts.Enums.AddressTypes.Physical);
var mAddress = export.ContactInformation?.Addresses.FirstOrDefault(x => x.AddressType == Framework.Contracts.Enums.AddressTypes.Mailing);
return new
{
LegalBusinessName = export.Name,
DBA = export.DBAName,
BusinessEmail = export.ContactInformation?.PrimaryEmail,
PhonePrimary = export.ContactInformation?.PrimaryPhone,
PhoneTypePrimary = export.ContactInformation?.PrimaryPhoneType,
PhoneSecondary = export.ContactInformation?.SecondaryPhone,
PhoneTypeSecondary = export.ContactInformation?.SecondaryPhoneType,
Website = export.WebAddress,
PhysicalStreetAddress = pAddress?.Address1,
PhysicalAddressLine2 = pAddress?.Address2,
PhysicalCity = pAddress?.City,
PhysicalCounty = pAddress?.County,
PhysicalState = pAddress?.State,
PhysicalZipCode = pAddress?.Zip,
MailingStreetAddress = mAddress?.Address1,
MailingAddressLine2 = mAddress?.Address2,
MailingCity = mAddress?.City,
MailingCounty = mAddress?.County,
MailingState = mAddress?.State,
MailingZipCode = mAddress?.Zip,
SchoolOnboarding = data?.ConfirmedVideo,
SchoolStartDate = data?.SchoolStartDate,
SchoolEndDate = data?.SchoolEndDate,
Grades = string.Join(",", data?.GradeLevels.Select(x => x.GradeLevel)),
IsReligiousSchool = data?.ConfirmedIsReligious,
ReligiousAffiliation = data?.ReligiousAffiliation,
TCSignatureName = export.SignatureName,
TCDateSigned = export.TermsAcceptedOn
};
});
return exportData;
}
It looks like you try to export a System.Type
Definiton of System.Type: Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.
Check if your ExportData has any value that is not a string.
What is the Uniform Type Identifer to provide to a UIDocumentMenuViewController to allow a user to select *.docx files?
The documentation in System-Declared Uniform Type Identifiers does not list a public UTType that allows filtering by .docx. An identifier exists for a standard *.doc file but not *.docx, is there instead an alternate UTType?
This is my current code:
var allowedDocumentTypes = new string[] {
UTType.RTF,
UTType.Text,
UTType.PDF,
UTType.UTF8PlainText,
UTType.RTFD,
UTType.UTF16ExternalPlainText,
UTType.UTF16PlainText,
UTType.UTF8PlainText,
UTType.FlatRTFD,
"com.microsoft.word.doc",
"com.microsoft.word.docx" // An attempt to include docx filtering.
};
var pickerMenu = new UIDocumentMenuViewController(allowedDocumentTypes, UIDocumentPickerMode.Open);
pickerMenu.DidPickDocumentPicker += (sender, args) =>
{
args.DocumentPicker.DidPickDocument += (sndr, pArgs) =>
{
var securityEnabled = pArgs.Url.StartAccessingSecurityScopedResource();
FileInfo fi = new FileInfo(pArgs.Url.Path);
var result = new SelectFileResult();
result.FilePath = fi.FullName;
result.FileName = fi.Name;
NSUrlRequest urlReq = NSUrlRequest.FromUrl(pArgs.Url);
NSUrlResponse response;
NSError error;;
var data = NSUrlConnection.SendSynchronousRequest(urlReq, out response, out error);
result.MimeType = response.MimeType;
Action onFileConsumeDone = () =>
{
pArgs.Url.StopAccessingSecurityScopedResource();
};
onFileSelected(result, onFileConsumeDone);
};
// Display the document picker
AppDelegate.TopViewController.PresentViewController(args.DocumentPicker, true, null);
};
pickerMenu.ModalPresentationStyle = UIModalPresentationStyle.Popover;
AppDelegate.TopViewController.PresentViewController(pickerMenu, true, null);
I had a shot in the dark and included the identifier com.microsoft.word.docx but it does not trigger filtering by docx.
My current solution is C# but objective-c and swift solutions accepted.
Try org.openxmlformats.wordprocessingml.document
Try
let supportedTypes: [UTType] = [UTType.content]
I am trying to set the value of object property which is of type List and initialise it by using a foreach to add the items to the list e.g.
var sessionPlanner = new SessionPlannerDTO()
{
Age = "",
NumberOfPlayers = session.numberOfPlayers.Value,
MedicalInformation = "",
PlayerNeeds = "",
SessionDate = session.daySessionDate.Value,
Location = session.Location.locationName,
PracticeView = new List<PracticeViewDTO>(foreach(var practice in session.Sessions){
new PracticeViewDTO(){AbilityLevel = practice.ActivityPlan.abilityLevel.Value,
ActivityUrl = practice.ActivityPlan.activityUrl,
EquipmentNeeds = practice.ActivityPlan.equipmentNeeds,
FacilityNeeds = practice.ActivityPlan.activityNeeds,
HealthAndSafety = practice.ActivityPlan.healthAndSafetyIssues,
SessionTitle = practice.ActivityPlan.activityName
};
})
};
PracticeView is what I am trying to achieve by making it a list without doing the below:
var practiceViewList = new List<PracticeViewDTO>();
foreach(var practice in session.Sessions)
{
var practiceX = new PracticeViewDTO()
{
AbilityLevel = practice.ActivityPlan.abilityLevel.Value,
ActivityUrl = practice.ActivityPlan.activityUrl
};
practiceViewList.Add(practiceX);
}
You can't use other code than assignments in object or collection initializers. So your foreach() there won't compile.
Use session.Sessions.Select() to map the source entities to your DTO, and ToList() to create a list of the result:
sessionPlanner = new SessionPlannerDTO
{
Age = "",
// ...
PracticeView = session.Sessions.Select(s =>
new PracticeViewDTO
{
AbilityLevel = s.ActivityPlan.abilityLevel.Value,
// ...
}).ToList()
};
You also may want to consider using AutoMapper, instead of hand-writing mapping code.
Let's say I have a workflow created progrmatically like this
ActivityBuilder<int> ab = new ActivityBuilder<int>();
ab.Name = "Add";
ab.Properties.Add(new DynamicActivityProperty {Name = "Operand1", Type = typeof (InArgument<int>)});
ab.Properties.Add(new DynamicActivityProperty {Name = "Operand2", Type = typeof (InArgument<int>)});
ab.Implementation = new Sequence
{
Activities =
{
new WriteLine
{
Text =
new VisualBasicValue<string>(
"Operand1.ToString() + \" + \" + Operand2.ToString()")
}
}
};
One way I know to execute it is to first serialize the ActivityBuilder object into XAML. Next, load the serialized XAML using ActivityXamlServices. Create a dictionary for parameters. Execute it using WorkflowInvoker or WorkflowApplication
Is there any way to execute this workflow without the need to convert/serialize activity builder to XAML?
WorkflowApplication and WorkflowInvoker takes an Activity as input for execution. Can I somehow use activityBuilder.Implementation directly with WorkflowApplication or WorkflowInvoker?
Why I want this? Because we have a workflow designer which user uses to create and execute workflow. User also creates workflow progrmatically. Workflow can be up to 80MB in size. This is hurting application's memory due to serialization and de-serialization of 80MB files to and from XAML. I want to somehow skip this step and directly execute activity.
Does it makes sense?
No need to use an ActivityBuilder, just create the activities you want and execute them.
var wf = new Sequence()
{
Variables =
{
new Variable<int>("Operand1", 7),
new Variable<int>("Operand2", 42)
},
Activities =
{
new WriteLine
{
Text =
new VisualBasicValue<string>(
"Operand1 & \" + \" & Operand2")
}
}
};
WorkflowInvoker.Invoke(wf);
An example using DynamicActivityProperty:
var wf = new DynamicActivity<int>
{
Properties =
{
new DynamicActivityProperty { Name = "Operand1", Type = typeof(InArgument<int>) },
new DynamicActivityProperty { Name = "Operand2", Type = typeof(InArgument<int>) }
},
Implementation = () => new Sequence()
{
Activities =
{
new WriteLine
{
Text =
new VisualBasicValue<string>(
"Operand1 & \" + \" & Operand2")
},
new Assign<int>
{
To = new ArgumentReference<int> { ArgumentName = "Result" },
Value = new VisualBasicValue<int>("Operand1 + Operand2")
}
}
}
};
var inputs = new Dictionary<string, object>();
inputs["Operand1"] = 7;
inputs["Operand2"] = 42;
var output = WorkflowInvoker.Invoke(wf, inputs);
Console.WriteLine(output);
Currently I’m having some difficulties with using new Magento's soap v2 from c# interface.
With php i was able to do something like this:
$params["created_at"]["from"] = date("Y-m-d H:i:s",Functions::convert_time($dataDa));
$params["created_at"]["to"] = date("Y-m-d H:i:s",Functions::convert_time($dataA));
MageInterface::getSingleton()->shipmentList($params);
In this mode i was able to find list of orders which were created from $dataDa to $dataA without problems. With c# however it seems that only the last one of the selectors work.
My code:
var cpf = new complexFilter[2];
cpf[0] = new complexFilter
{
key = "created_at",
value = new associativeEntity
{
key = "to",
value = uxDataA.DateTime.ToString("yy-MM-dd HH:mm:ss")
}
});
cpf[1] = new complexFilter
{
key = "created_at",
value = new associativeEntity
{
key = "from",
value = uxDataDa.DateTime.ToString("yy-MM-dd HH:mm:ss")
}
});
var filters = new filters();
filters.complex_filter = cpf;
var risultato = mage.salesOrderList(sessionKey, filters);
In this mode only created_at->from criteria is taken in consideration (it's like second complex filter override previous one with the same key). Ideas?
Thanks in advance.
This works for me :
private filters addFilter(filters filtresIn, string key, string op, string value)
{
filters filtres = filtresIn;
if (filtres == null)
filtres = new filters();
complexFilter compfiltres = new complexFilter();
compfiltres.key = key;
associativeEntity ass = new associativeEntity();
ass.key = op;
ass.value = value;
compfiltres.value = ass;
List<complexFilter> tmpLst;
if (filtres.complex_filter!=null)
tmpLst = filtres.complex_filter.ToList();
else tmpLst = new List<complexFilter>();
tmpLst.Add(compfiltres);
filtres.complex_filter = tmpLst.ToArray();
return filtres;
}
and call
{
Mage_Api_Model_Server_V2_HandlerPortTypeClient clientSoap = new Mage_Api_Model_Server_V2_HandlerPortTypeClient();
string sessionId = clientSoap.login(LOG, PASS);
filters filtres = new filters();
filtres = addFilter(filtres, "status", "eq", "processing");
filtres = addFilter(filtres, "created_at", "from", "2014-09-07 08:00:00");
filtres = addFilter(filtres, "created_at", "to", "2014-09-07 00:00:00");
salesOrderEntity[] lst = clientSoap.salesOrderList(sessionId, filtres);
}
Solved, there was a bug (or the feature?) in mage\sales\order\api\v2.php
See more info in this thread: http://www.magentocommerce.com/boards/viewthread/70368/