private static ReadOnlyMemory <byte> ValueToMemory(NSObject?value) { return(value switch { NSData data => data.ToArray(), NSString str => str.Encode(NSStringEncoding.UTF8).ToArray(), _ => throw new NotImplementedException(), });
public NSData CreateNSData(string str) { //var str = "my string"; var macStr = new NSString(str); return(macStr.Encode(NSStringEncoding.Unicode)); }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("Text") && Control != null) { // http://forums.xamarin.com/discussion/15530/nsattributedstringdocumentattributes-exception-on-ios-6 NSParagraphStyle ps = NSParagraphStyle.Default; NSDictionary dict = new NSMutableDictionary() { { UIStringAttributeKey.Font, ((ExtendedLabel)Element).Font.ToUIFont() }, }; var attr = new NSAttributedStringDocumentAttributes(dict); var nsError = new NSError(); // This line announces, that content is html. attr.DocumentType = NSDocumentType.HTML; attr.StringEncoding = NSStringEncoding.UTF8; var html = ((ExtendedLabel)Element).TextExt + Environment.NewLine; NSString htmlString = new NSString(html); NSData htmlData = htmlString.Encode(NSStringEncoding.UTF8); NSAttributedString attrStr = new NSAttributedString(htmlData, attr, out dict, ref nsError); Control.AttributedText = attrStr; Control.SizeToFit(); Control.SetNeedsLayout(); Element.HeightRequest = Control.Bounds.Height; return; } if (e.PropertyName == "Height" || e.PropertyName == "Width") { // We calculate the correct height, because of the attributed string, Xamarin.Forms don't do it correct var width = (float)((ExtendedLabel)Element).Width; // Only do this, if we have a valid width if (width != -1) { var rect = Control.AttributedText.GetBoundingRect(new CoreGraphics.CGSize(width, float.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, null); if (rect.Height != ((ExtendedLabel)Element).Height) { ((ExtendedLabel)Element).HeightRequest = rect.Height; } } } base.OnElementPropertyChanged(sender, e); }
public override NSObject ContentsForType(string typeName, out NSError outError) { // Clear the error state outError = null; // Convert the contents to a NSData object and return it NSData docData = _dataModel.Encode(NSStringEncoding.UTF8); return(docData); }
// return contents for iCloud to save (from the local model) public override NSObject ContentsForType(string typeName, out NSError outError) { outError = null; Console.WriteLine("ContentsForType({0})", typeName); Console.WriteLine("DocumentText:{0}", dataModel); NSData docData = dataModel.Encode(NSStringEncoding.UTF8); return(docData); }
CIImage CreateQRForString(NSString qrString, QRCodeCorrectionLevel level) { NSData strData = qrString.Encode(NSStringEncoding.UTF8); // 创建filter CIFilter qrFilter = CIFilter.FromName("CIQRCodeGenerator"); // 设置内容和纠错级别 qrFilter.SetValueForKey(strData, new NSString("inputMessage")); qrFilter.SetValueForKey(new NSString(level.ToString()), new NSString("inputCorrectionLevel")); // 返回CIImage return(qrFilter.OutputImage); }
public static NSDictionary ToIOSDictionary(this IDictionary self) { if (self == null) { return(null); } var jsonString = new NSString(SimpleJson.SerializeObject(self)); var jsonData = jsonString.Encode(NSStringEncoding.UTF8); NSError error; return((NSDictionary)NSJsonSerialization.Deserialize(jsonData, 0, out error)); }
public static NSAttributedString HtmlToAttributedString(string htmlString) { var nsString = new NSString(htmlString); var data = nsString.Encode(NSStringEncoding.UTF8); var dictionary = new NSAttributedStringDocumentAttributes(); dictionary.DocumentType = NSDocumentType.HTML; NSError error = new NSError(); var attrString = new NSAttributedString(data, dictionary, ref error); var mutString = ResetFontSize(new NSMutableAttributedString(attrString)); return(mutString); }
public static NSDictionary DictToNSDict(Dictionary <string, object> dict) { if (dict == null) { return(null); } string jsonString = Json.Serialize(dict); NSString jsonNSString = new NSString(jsonString); NSData jsonData = jsonNSString.Encode(NSStringEncoding.UTF8); NSError error; NSDictionary nsDict = NSJsonSerialization.Deserialize(jsonData, 0, out error) as NSDictionary; return(nsDict); }
public override void WindowDidLoad() { base.WindowDidLoad(); Window.BackgroundColor = NSColor.White; ContentTextView.EnclosingScrollView.BorderType = NSBorderType.NoBorder; Window.Title = ""; AboutTitle.StringValue = "About Lexisnexis Legal & Professional"; if (GlobalAccess.Instance.CurrentUserInfo != null) { LastSyncTime.StringValue = "Latest server sync " + SettingsUtil.Instance.GetLastSyncedTime().ToString("HH:mmtt dd MMM yyyy"); } else { LastSyncTime.StringValue = ""; } LoginUserDetails userDetail = GlobalAccess.Instance.CurrentUserInfo; if (userDetail == null) { string filePath = NSBundle.MainBundle.PathForResource("/Images/Setting/LexisNexisLegal", "htm"); NSData fileHtmData = NSData.FromFile(filePath); NSDictionary docAttribute = new NSDictionary(); var htmContent = NSAttributedString.CreateWithHTML(fileHtmData, out docAttribute); //new NSAttributedString (fileHtmData, out docAttribute); ContentTextView.TextStorage.SetString(htmContent); return; } var htmlString = SettingsUtil.Instance.GetLexisNexisInfo(); htmlString = htmlString.Replace("font-size:12px;", "font-size:12px;\n font-family: \"HelveticaNeue-Medium\";"); //htmlString = htmlString.Replace ("line-height:16px;", "line-height:14pt;"); htmlString = htmlString.Replace("<h3>\nLexisNexis Legal & Professional \n</h3>", ""); htmlString = htmlString.Replace("color:#000000;", "color:#808085;"); //# 808085 6D6D72 var nsString = new NSString(htmlString); var fileData = nsString.Encode(NSStringEncoding.UTF8); NSDictionary docAttributeo = new NSDictionary(); var url = new NSUrl(""); var content = new NSAttributedString(fileData, url, out docAttributeo); ContentTextView.TextStorage.SetString(content); }
public void WriteToFile(string filename, string text) { var textToWrite = new NSString(text); string path = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true)[0]; path = string.Format("{0}/{1}", path, filename); NSError error = new NSError(); if (NSFileManager.DefaultManager.FileExists(path)) { NSFileManager.DefaultManager.Remove(path, out error); } NSFileManager.DefaultManager.CreateFile(path, new NSData(), NSFileAttributes.FromDictionary(new NSDictionary())); var data = textToWrite.Encode(NSStringEncoding.UTF8); data.Save(path, false); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); // Network test Console.WriteLine(QNNetworkInfo.Ip); // des test NSData key = NSData.FromString("12345678", NSStringEncoding.UTF8); NSString origin = new NSString("abcdef"); QNDes des = new QNDes(key); NSData enc = des.Encrypt(origin.Encode(NSStringEncoding.UTF8)); NSData dec = des.Decrpyt(enc); NSString n = new NSString(dec, NSStringEncoding.UTF8); Console.WriteLine("Origin:{0} n:{1}", origin, n); }
internal static void SummonThreeDSecure(PaymentRequiresThreeDSecureModel threedDSecureReceipt, SecureWebView secureWebView) { secureWebView.ReceiptID = threedDSecureReceipt.ReceiptId; NSCharacterSet allowedCharecterSet = NSCharacterSet.FromString(@":/=,!$&'()*+;[]@#?").InvertedSet; NSString paReq = new NSString(threedDSecureReceipt.PaReq); var encodedPaReq = paReq.CreateStringByAddingPercentEncoding(allowedCharecterSet); NSString termUrl = new NSString("judo1234567890://threedsecurecallback"); var encodedTermUrl = termUrl.CreateStringByAddingPercentEncoding(allowedCharecterSet); NSUrl url = new NSUrl(threedDSecureReceipt.AcsUrl); NSMutableUrlRequest req = new NSMutableUrlRequest(url); NSString postString = new NSString("MD=" + threedDSecureReceipt.Md + "&PaReq=" + encodedPaReq + "&TermUrl=" + encodedTermUrl + ""); NSData postData = postString.Encode(NSStringEncoding.UTF8); req.HttpMethod = "POST"; req.Body = postData; try { DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { secureWebView.LoadRequest(req); LoadingScreen.HideLoading(); secureWebView.Hidden = false; }); } catch (Exception e) { if (secureWebView._failureCallback != null) { var judoError = new JudoError { Exception = e }; secureWebView.CloseView(); secureWebView._failureCallback(judoError); } } }
public void WriteFile() { try { // Gets the direct path to the file NSString folderPath = dataPath.AppendPathComponent(new NSString("testfile.txt")); // The text who should be written NSString someText = new NSString("Test"); // The data NSData data = someText.Encode(NSStringEncoding.UTF8); // Handle the data and writes it to the specific path NSFileHandle nsfh = NSFileHandle.OpenWrite(folderPath); // Writes the data nsfh.WriteData(data); } catch (Exception ex) { // Failed write data into a file } }
public static void SummonThreeDSecure (PaymentRequiresThreeDSecureModel threedDSecureReceipt, SecureWebView secureWebView) { secureWebView.ReceiptID = threedDSecureReceipt.ReceiptId; NSCharacterSet allowedCharecterSet = NSCharacterSet.FromString (@":/=,!$&'()*+;[]@#?").InvertedSet; NSString paReq = new NSString (threedDSecureReceipt.PaReq); var encodedPaReq = paReq.CreateStringByAddingPercentEncoding (allowedCharecterSet); NSString termUrl = new NSString ("judo1234567890://threedsecurecallback"); var encodedTermUrl = termUrl.CreateStringByAddingPercentEncoding (allowedCharecterSet); NSUrl url = new NSUrl (threedDSecureReceipt.AcsUrl); NSMutableUrlRequest req = new NSMutableUrlRequest (url); NSString postString = new NSString ("MD=" + threedDSecureReceipt.Md + "&PaReq=" + encodedPaReq + "&TermUrl=" + encodedTermUrl + ""); NSData postData = postString.Encode (NSStringEncoding.UTF8); req.HttpMethod = "POST"; req.Body = postData; try { DispatchQueue.MainQueue.DispatchAfter (DispatchTime.Now, () => { secureWebView.LoadRequest (req); JudoSDKManager.HideLoading (); secureWebView.Hidden = false; }); } catch (Exception e) { if (secureWebView._failureCallback != null) { var judoError = new JudoError { Exception = e }; secureWebView._failureCallback (judoError); } } }