I am researching for a Barcode scanning application with iOS iPhone Camera.
I can use Swift to get the string data that I actually need from the image I scan. However, when using Xamarin with the Xamarin implementation of the AVFoundation.AVMetadataObject and AVMetadataMachineReadableCodeObject, I don't get all of the characters. The C# code appears to execute in the same way as the Swift code with two different results.
Example Xcode Swift:
if let metadataObject = metadataObjects.first {
guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return }
guard let stringValue = readableObject.stringValue else { return }
AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
found(code: stringValue)
}
will render something like this: WHICH I WANT
[)>\u{1e}06\u{1d}1SMYDATA\u{1d}S1MYDATA\u{1d}1PMYDATA\u{1d}WMYDATA\u{1d}4LUS\u{1e}\u{4}
Example Xamarin Foundation Code:
var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject;
if (barcodeMetadataObject != null)
{
var barcodeOverlayPath = this.BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners);
metadataObjectOverlayLayer.Path = barcodeOverlayPath;
// If the metadata object has a string value, display it.
string textLayerString = null;
if (!string.IsNullOrEmpty(barcodeMetadataObject.StringValue))
{
textLayerString = barcodeMetadataObject.StringValue;
}
else
{
// TODO: add Descriptor (line 618 in original iOS sample)
}
will render something like this: WHICH I DO NOT WANT...I WANT THE ENTIRE CHARACTER SET
[)>061SMYDATAS1911500531PMYDATAWMYDATA
So I have this: (Xcode)
[)>\u{1e}06\u{1d}1SMYDATA\u{1d}S1MYDATA\u{1d}1PMYDATA\u{1d}WMYDATA\u{1d}4LUS\u{1e}\u{4}
Versus this:(Xamarin)
[)>061SMYDATAS1911500531PMYDATAWMYDATA
I am not understanding why the implementation in Xamarin would not be supplying all of the same characters of the scan when it essentially acts only as a wrapper.
Does anyone have any idea?
Related
I would like to create tags in the Visual Studio editor to insert all sorts of glyphs, adornments, text hightlightings, etc., based on line/column/length locations in the code.
I have been carefully reading the documentation walkthrough pages (https://learn.microsoft.com/en-us/visualstudio/extensibility/walkthrough-creating-a-margin-glyph?view=vs-2017 and related pages). Although a bit complex and hard to understand, it seems like the API is very much oriented on giving the means to analyse the code: it is able to give your code split into spans, with classifications, etc.
However, I have the "opposite" need: I already have the analysis done by my external analysis engine. And I already have a set of results to be displayed in the editor with line/column/length for each one. Like:
function "foo", located at line 345, column 1, length 3, and other fields containing information to be displayed,
variable "my_var", located at line 349, column 13, length 6, and other fields containing information to be displayed,
Is it possible to create tags in the Visual Studio editor directly based on their line/column/length location? Any hint, any pointer to more detailed documentation or tutorial would be greatly appreciated.
Lance's link was quite helpful to understand another way to create tags different from the MS documentation example.
Indeed, I don't analyse the text contained into the spans, the analysis is already done outside. I get some list of "defects" locations.
I get them into a defectsLocation dictionary (defectsLocation[filename][line] = location data (...)
Here is was I did:
internal class MyDefectTagger : ITagger<MyDefectTag>
{
private IClassifier m_classifier;
private ITextBuffer m_buffer;
internal MyDefectTagger(IClassifier classifier, ITextBuffer buffer)
{
m_classifier = classifier;
m_buffer = buffer;
}
IEnumerable<ITagSpan<MyDefectTag>>
ITagger<MyDefectTag>.GetTags(NormalizedSnapshotSpanCollection spans)
{
if (MyModel.Instance == null || MyModel.Instance.defectsLocation == null)
{
yield return null;
}
var filename = GetFileName(m_buffer);
if (!MyModel.Instance.defectsLocation.ContainsKey(filename))
{
yield return null;
}
foreach (SnapshotSpan span in spans)
{
ITextSnapshot textSnapshot = span.Snapshot;
foreach (ITextSnapshotLine textSnapshotLine in textSnapshot.Lines)
{
var line = textSnapshotLine.LineNumber + 1; // Lines start at 1 in VS Editor
if (MyModel.Instance.defectsLocation[filename].ContainsKey(line) &&
!MyModel.Instance.defectsLocation[filename][line].rendered)
{
var rendered = MyModel.Instance.defectsLocation[filename][line].rendered;
yield return new TagSpan<MyDefectTag>(
new SnapshotSpan(textSnapshotLine.Start, 0),
new MyDefectTag()
);
}
}
}
}
}
So I want to build this little code sandbox in Unity, which would allow me to teach students the basics of algorithmics and coding.
The idea would be for them to enter (very basic) code in a text box or something of the kind, and to observe the effects of their code onto objects present in a Unity scene. I'm pretty sure this has been done a million times, but I'd love to try my hand at this. The rub is, I have no idea where to start...
I guess the idea is that the string would be compiled into code & executed at runtime, at the press of a button.
I've read about numerous other questions on SO, and have come up with very diverse solutions such as using a C# parser, reflection, expression trees, CodeDom, etc.
From what I understood of all these (i.e., not much), CodeDom seemed more appropriate, but then I read that it only ran inside of Visual Studio and generated errors in public builds. So does that mean that this is going to be a problem within Unity3D (as it is based on Mono?)
Thank you for your help,
In the following case, you look for an existing method of the given name on the same script (you can easily convert it to another script or any script in the assembly (not recommended though)):
string actionStr = inputField.text;
Type t = this.GetType();
MethodInfo mi = t.GetMethod(actionStr);
if(mi == null)
{
ErrorMethod(actionStr + " method could not be found");
}else
{
mi.Invoke(this);
}
Another way would be to store all the methods in a dictionary (faster):
Dictionary<string, Action>dict = null;
void Start()
{
this.dict = new Dictionary<string, Action>();
this.dict.Add("dosomething", DoSomething);
}
void DoSomething(){}
public void OnActionCall(string inputFieldStr)
{
string str = inputFieldStr.ToLower();
if(this.dict.Contains(str) == false)
{
ErrorMethod(actionStr + " method could not be found");
return;
}
this.dict[str]();
}
I am trying to implement PushKit in my ios app. However the Xamarin document for PushKit is very limited. Do you have a sample code how to use it in Xamarin C#? Thanks a lot.
You can get idea from following link
Swift Code
Binding
If you have pure swift code, then you can download sample code from below link.
Download
import UIKit
import PushKit
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate{
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
self. PushKitRegistration()
return true
}
//MARK: - PushKitRegistration
func PushKitRegistration()
{
let mainQueue = dispatch_get_main_queue()
// Create a push registry object
if #available(iOS 8.0, *) {
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
// Set the registry's delegate to self
voipRegistry.delegate = self
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [PKPushTypeVoIP]
} else {
// Fallback on earlier versions
}
}
#available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
// Register VoIP push token (a property of PKPushCredentials) with server
let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes),
count: credentials.token.length).map { String(format: "%02x", $0) }.joinWithSeparator("")
print(hexString)
}
#available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
// Process the received push
}
}
Env :
Visual Studio 2013,
Winform / C# / Framework 4.5,
nHapi DLL 2.4.0.9,
HL7 Version 2.3
I'm building a little windows application that read HL7 messages and send them to an Interface system.
Everything is working just fine but I would like to know if it's possible to replace/add/modify a segment value : EVN 5.2 (Operator ID / Family name).
At the moment, I'm reading the content of the HL7 file on the computer, put the content in a string, parse the message, encode the message and return it.
public static String ParseMessage(String message)
{
var parser = new NHapi.Base.Parser.PipeParser();
var parsedMessage = parser.Parse(message);
/* I guess it's here that I should do the change for the EVN 5.2 ? But How ;-) */
var msgType = parsedMessage.GetStructureName();
var pipeDelimitedMessage = parser.Encode(parsedMessage);
return pipeDelimitedMessage;
}
Thanks everyone for you help
Richard
The way the nHapi would have you do this is cast the 'parsed' abstract message down to its concrete type so that you are able to walk the object model and set the properties you'd like.
As an example, take the case of an ADT A01 admit message:
[Test]
public void TestPopulateEVNOperaterID()
{
string message = #"MSH|^~\&|SUNS1|OVI02|AZIS|CMD|200606221348||ADT^A01|1049691900|P|2.3
EVN|A01|200601060800
PID||8912716038^^^51276|0216128^^^51276||BARDOUN^LEA SACHA||19981201|F|||AVENUE FRANC GOLD 8^^LUXEMBOURGH^^6780^150||053/12456789||N|S|||99120162652||^^^|||||B
PV1||O|^^|U|||07632^MORTELO^POL^^^DR.|^^^^^|||||N||||||0200001198
PV2|||^^AZIS||N|||200601060800
IN1|0001|2|314000|||||||||19800101|||1|BARDOUN^LEA SACHA|1|19981201|AVENUE FRANC GOLD 8^^LUXEMBOURGH^^6780^150|||||||||||||||||ZIN|0164652011399|0164652011399|101|101|45789^Broken bone";
var parser = new PipeParser();
var abstractMessage = parser.Parse(message);
// this is the normal / expected way of working with NHapi parsed messages
var typedMessage = abstractMessage as ADT_A01;
if (typedMessage != null)
{
typedMessage.EVN.OperatorID.FamilyName.Value = "Surname";
typedMessage.EVN.OperatorID.GivenName.Value = "Firstname";
}
var pipeDelimitedMessage = parser.Encode(typedMessage);
// alternatively, you can apply this modification to any HL7 2.3 message
// with an EVN segment using this more generic method
var genericMethod = abstractMessage as AbstractMessage;
var evn = genericMethod.GetStructure("EVN") as EVN;
if (evn != null)
{
evn.OperatorID.FamilyName.Value = "SurnameGeneric";
evn.OperatorID.GivenName.Value = "FirstnameGeneric";
}
pipeDelimitedMessage = parser.Encode(typedMessage);
}
I believe the second more generic way is probably what you'll be wanting for this case, however I thought I'd just show you as well how to get to parsed / concrete type so that you can work with it that way if you are dealing with a specific message type.
I'm working with C# and the .NET 2.0 framework in Visual Studio 2010.
I'm trying to extract a URL which is returned by a web service.
This URL is returned in an array of features containing keys and values. (I think this is similar to what I learned in school is called a hash table).
My intellisense doesn't pick up anything useful and I can't figure out what I'm doing wrong.
This is the code. What goes in serverInfo.FeatureSet[]?
public string wfl_reqURL(string username, string password)
{
MyWorkflow.ServerInfo serverInfo = new MyWorkflow.ServerInfo();
myURL = serverInfo.FeatureSet[];
}
This is how it's described in the WSDL. FeatureSet is being returned as an array with a string key and a string value:
<ServerInfo>
<FeatureSet>
<Feature>
<Key>FileUploadUrl</Key>
<Value>http://localhost/transferindex.php</Value>
</Feature>
</FeatureSet>
</ServerInfo>
Have I provided enough detail about my problem? Most of the information I've found seems to be about how to create such arrays in web services, not select one from a web service as I'd like to do.
Try something like this:
object neededItem = null;
foreach (string item in serverInfo.FeatureSet.Keys)
{
if (item == "FileUploadUrl")
{
neededItem = serverInfo.FeatureSet[item];
break;
}
}
if (neededItem != null)
{
//Do something
}
If you're using c# 3.5 then something in linq like
myURL = serverInfo.FeatureSet.First(o=>o.Key == "FileUploadUrl").Value
The problem was in the data type. Changing the code to this solved the problem, albeit in a messy way. I thought it had something to do with types and how it was defined...either as dictionary or arrays, but it was a bit different than I'd thought...
foreach( MyWorkFlow.Feature feature in serverInfo.FeatureSet) {
if (feature.Key.ToString() == "FileUploadUrl") {
string myURL = feature.Value;
Console.WriteLine(myURL);
}