What could be reasons for this android EditText control to convert the input to the ascii sequence - xamarin.forms

So for some project i'm working with Xamarin.Forms.
Since one area is just unbearably slow with Xamarin.Forms i've used a CustomRenderer to solve one particular area where a list is involved.
After getting back to the project and upgrading packages, i've suddenly got the weirdest bug.
I am setting "1234" to an EditText, and the EditText.Text Property is suddenly "49505152" - the string is converted to its ascii equivalent.
Is this a known issue? Does anyone know how to fix it?

The cause of the issue was that my EditText had an InputFilter applied and that after updating a package suddenly another code path of FilterFormatted was executed.
public ICharSequence FilterFormatted(ICharSequence source, int start, int end, ISpanned dest, int dstart, int dend)
{
var startSection = dest.SubSequenceFormatted(0, dstart);
var insert = source.SubSequenceFormatted(start, end);
var endSection = dest.SubSequenceFormatted(dstart, dest.Length());
var merged = $"{startSection}{insert}{endSection}";
if (ValidationRegex.IsMatch(merged) && InputRangeCheck(merged, CultureInfo.InvariantCulture))
{
StringBuilder sb = new StringBuilder(end - start);
for (int i = start; i < end; i++)
{
char c = source.CharAt(i);
sb.Append(c);
}
if (source is ISpanned) {
SpannableString sp = new SpannableString(sb);
TextUtils.CopySpansFrom((ISpanned)source, start, sb.Length(), null, sp, 0);
return sp;
} else {
// AFTER UPDATE THIS PATH WAS ENTERED UNLIKE BEFORE
return sb;
}
}
else
{
return new SpannableString(string.Empty);
}
}

Related

abc PDF generate a blank page on IIS

I am creating an PDF from HTML using ABC PDF 8.0, it works well on my local end but generate a blank page on IIS, I already down grade IE, and provide the all permission to folder. When I tried to generate the PDF through any external link like Google.com it works perfectly. more over my link is accessible and there is no error on the page. please find below the code for your reference.
var url="test.com"
if (XSettings.InstallLicense(abcPDFkey))
{
using (Doc theDoc = new Doc())
{
//apply a rotation transform
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);
// To fix time out
theDoc.HtmlOptions.RetryCount = 1;
theDoc.HtmlOptions.Timeout = 25000;
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
theDoc.HtmlOptions.Engine = EngineType.Gecko;
theDoc.HtmlOptions.ImageQuality = 60;
int theID;
theID = theDoc.AddImageUrl(url);
while (true)
{
theDoc.FrameRect();
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
int NewtheID = theDoc.GetInfoInt(theDoc.Root, "Pages");
theDoc.SetInfo(NewtheID, "/Rotate", "90");
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
foreach (IndirectObject io in theDoc.ObjectSoup)
{
if (io is PixMap)
{
PixMap pm = (PixMap)io;
pm.Realize(); // eliminate indexed color images
pm.Resize(pm.Width / 6, pm.Height / 6);
}
}
theDoc.Save(System.Web.HttpContext.Current.Server.MapPath("PDFFileName"));
theDoc.Clear();
}
Please help, thanks
Ok, I figured out what was the issue.
First of all I define the relative path for all my Images, and secondly Our server have internal IP, I define the URL for internal IP instead of public domain. that fix my issue..
cheers !!

Setting default TWAIN data source without using API UI menu

Using the twaindotnet library in C#, I'm wondering if there's a way to set the default datasource using the library.
As a feeble attempt, I've tried adding a SetDefault method to the DataSource class of twaindonet, like this
public static void SetDefault(Identity applicationId, IWindowsMessageHook messageHook, DataSource newDataSource)
{
var defaultSourceId = newDataSource.SourceId;
// Attempt to get information about the system default source
var result = Twain32Native.DsmIdentity(
applicationId,
IntPtr.Zero,
DataGroup.Control,
DataArgumentType.Identity,
Message.Set,
defaultSourceId);
if (result != TwainResult.Success)
{
var status = DataSourceManager.GetConditionCode(applicationId, null);
throw new TwainException("Error getting information about the default source: " + result, result, status);
}
}
which is called from the DataSourceManage class like this
public void SelectSource(DataSource dataSource)
{
DataSource.Dispose();
DataSource.SetDefault(ApplicationId, _messageHook, dataSource);
}
But when I try to use SetDefault, Twain32Native.DsmIdentity always results in Failure being returned.
I basically copied from SetDefault the setDefaultDataSource method from TWAIN sample Data Source and Application
pTW_IDENTITY TwainApp::setDefaultDataSource(unsigned int _index)
{
if(m_DSMState < 3)
{
cout << "You need to open the DSM first." << endl;
return NULL;
}
else if(m_DSMState > 3)
{
PrintCMDMessage("A source has already been opened, please close it first\n");
return NULL;
}
if(_index >= 0 && _index < m_DataSources.size())
{
m_pDataSource = &(m_DataSources[_index]);
// set the specific data source
TW_UINT16 twrc;
twrc = _DSM_Entry(
&m_MyInfo,
0,
DG_CONTROL,
DAT_IDENTITY,
MSG_SET,
(TW_MEMREF) m_pDataSource);
switch (twrc)
{
case TWRC_SUCCESS:
break;
case TWRC_FAILURE:
printError(0, "Failed to get the data source info!");
break;
}
}
else
{
return NULL;
}
return m_pDataSource;
}
Any help would be greatly appreciated.
The possible cause is that the version of your TWAIN DSM is too low. Only DSM 2.0 or above supports setting default TWAIN data source.

X++ passing current selected records in a form for your report

I am trying to make this question sound as clear as possible.
Basically, I have created a report, and it now exists as a menuitem button so that the report can run off the form.
What I would like to do, is be able to multi-select records, then when I click on my button to run my report, the current selected records are passed into the dialog form (filter screen) that appears.
I have tried to do this using the same methods as with the SaleLinesEdit form, but had no success.
If anyone could point me in the right direction I would greatly appreciate it.
Take a look at Axaptapedia passing values between forms. This should help you. You will probably have to modify your report to use a form for the dialog rather than using the base dialog methods of the report Here is a good place to start with that!
Just wanted to add this
You can use the MuliSelectionHelper class to do this very simply:
MultiSelectionHelper selection = MultiSelectionHelper::createFromCaller(_args.caller());
MyTable myTable = selection.getFirst();
while (myTable)
{
//do something
myTable = selection.getNext();
}
Here is the resolution I used for this issue;
Two methods on the report so that when fields are multi-selected on forms, the values are passed to the filter dialog;
private void setQueryRange(Common _common)
{
FormDataSource fds;
LogisticsControlTable logisticsTable;
QueryBuildDataSource qbdsLogisticsTable;
QueryBuildRange qbrLogisticsId;
str rangeLogId;
set logIdSet = new Set(Types::String);
str addRange(str _range, str _value, QueryBuildDataSource _qbds, int _fieldNum, Set _set = null)
{
str ret = _range;
QueryBuildRange qbr;
;
if(_set && _set.in(_Value))
{
return ret;
}
if(strLen(ret) + strLen(_value) + 1 > 255)
{
qbr = _qbds.addRange(_fieldNum);
qbr.value(ret);
ret = '';
}
if(ret)
{
ret += ',';
}
if(_set)
{
_set.add(_value);
}
ret += _value;
return ret;
}
;
switch(_common.TableId)
{
case tableNum(LogisticsControlTable):
qbdsLogisticsTable = element.query().dataSourceTable(tableNum(LogisticsControlTable));
qbrLogisticsId = qbdsLogisticsTable.addRange(fieldNum(LogisticsControlTable, LogisticsId));
fds = _common.dataSource();
for(logisticsTable = fds.getFirst(true) ? fds.getFirst(true) : _common;
logisticsTable;
logisticsTable = fds.getNext())
{
rangeLogId = addrange(rangeLogId, logisticsTable.LogisticsId, qbdsLogisticsTable, fieldNum(LogisticsControlTable, LogisticsId),logIdSet);
}
qbrLogisticsId.value(rangeLogId);
break;
}
}
// This set the query and gets the values passing them to the range i.e. "SO0001, SO0002, SO000£...
The second methods is as follows;
private void setQueryEnableDS()
{
Query queryLocal = element.query();
;
}
Also on the init method this is required;
public void init()
{
;
super();
if(element.args() && element.args().dataset())
{
this.setQueryRange(element.args().record());
}
}
Hope this helps in the future for anyone else who has the issue I had.

How to determine via UIAutomation, whether a button is pressed or not?

I want to find out whether a button is pressed or not. This seems not to be an official property of a button (not a button-style checkbox!), but seems accessible, there is the BM_GETSTATE message for example that should get the desired result.
Problem is, frequently, I dont get window-handles for my buttons (they are just part of another Toolbar, though they can be distinguihed by the AutomationElement). And I would need such a handle for the SendMessage function.
So.. is there a way for me to access that property? I know it is accessible, since I have seen it in other automation-programmes, I just dont konw how to get at it.
I am going to use C#, but any C code would be fine.
Many thanks
(edit: so I finally managed to make the code format properly here - just insert 4 spaces at the beginning.)
Enjoy it, it took me quite a long time to get it to work.. but now I feel like having reached a new level. :)
(please tell me how to make it format properly - both quote and code failed on me)
int res;
#region direct method
int hwnd = ae.Current.NativeWindowHandle;
if (hwnd != 0)
{
const UInt32 BM_GETSTATE = 0x00F2;
res = SendMessage(hwnd, BM_GETSTATE, 0, 0);
}
#endregion
else
#region method via toolbar
{
AutomationElement parent = TreeWalker.RawViewWalker.GetParent(ae);
while ((parent != null) && (parent.Current.ControlType != ControlType.ToolBar))
parent = TreeWalker.RawViewWalker.GetParent(ae);
if (parent != null)
{
int toolBarHandle = parent.Current.NativeWindowHandle;
#region defines
const int WM_USER = 0x400;
const int TB_GETSTATE = (WM_USER + 18);
const int TB_GETBUTTON = (WM_USER + 23);
const int TB_BUTTONCOUNT = (WM_USER + 24);
#endregion
#region get correct child number
int numButtons = SendMessage(toolBarHandle, TB_BUTTONCOUNT, 0, 0);
AutomationElement sibling = ae;
int cnt = -1;
while (sibling != null)
{
sibling = TreeWalker.RawViewWalker.GetPreviousSibling(sibling);
++cnt;
}
if (cnt >= numButtons)
cnt = 0; // nonsense value, but pass a valid one
#endregion
#region get command id
TBBUTTON butInfo = new TBBUTTON();
butInfo.idCommand = 1234;
uint pid;
GetWindowThreadProcessId((IntPtr)toolBarHandle, out pid);
IntPtr process = OpenProcess(ProcessAccessFlags.VMOperation | ProcessAccessFlags.VMRead |
ProcessAccessFlags.VMWrite | ProcessAccessFlags.QueryInformation, false, pid);
IntPtr p = VirtualAllocEx(process, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(TBBUTTON)), AllocationType.Commit
, MemoryProtection.ReadWrite);
int _res = SendMessage(toolBarHandle, TB_GETBUTTON, cnt, p.ToInt32());
#region getresult
int read;
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TBBUTTON)));
Marshal.StructureToPtr(butInfo, ptr, true);
bool __res = ReadProcessMemory(process, p, ptr, Marshal.SizeOf(typeof(TBBUTTON)), out read);
System.Diagnostics.Debug.Assert(read == Marshal.SizeOf(typeof(TBBUTTON)));
butInfo = (TBBUTTON)Marshal.PtrToStructure(ptr, typeof(TBBUTTON));
#endregion
int commandId = butInfo.idCommand;
VirtualFreeEx(process, p, 0, FreeType.Release);
#endregion
//!define BST_UNCHECKED 0
//!define BST_CHECKED 1
//!define BST_INDETERMINATE 2
//!define BST_PUSHED 4
//!define BST_FOCUS 8
#region get state
res = SendMessage(toolBarHandle, TB_GETSTATE, commandId, 0);
#endregion
}
}
#endregion
EDIT:
Here http://www.andreas-reiff.de/2011/06/c-speicher-anderen-prozess-befullen-lassen-checken-ob-ein-button-gedruckt/ with readable code and explanations in a strange, foreign language.. code comments are english, though. hope you find it useful.
Also, I would not have been able to solve this without the info here How come some controls don't have a windows handle?.

MethodAccessException when updating a record in sqlite db

I encounter this exception when I try to updating a record with following statement.
UPDATE GroupTable SET groupId=100 WHERE groupId=101
I tested the statement under SQLite Manager of Firefox plug-in, and it works.
The error message is as following image. It crashed at the os_win_c.cs, the method named getTempname().
Well, I modified the original codes and fixed this bug.
The Path.GetTempPath() doesn't work because the sandbox enviroment. It has no access right.
I fixed by following codes. And it works now.
static int getTempname(int nBuf, StringBuilder zBuf)
{
const string zChars = "abcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder zRandom = new StringBuilder(20);
i64 iRandom = 0;
for (int i = 0; i < 20; i++)
{
sqlite3_randomness(1, ref iRandom);
zRandom.Append((char)zChars[(int)(iRandom % (zChars.Length - 1))]);
}
//! Modified by Toro, 2011,05,10
string tmpDir = "tmpDir";
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
store.CreateDirectory(tmpDir);
//zBuf.Append(Path.GetTempPath() + SQLITE_TEMP_FILE_PREFIX + zRandom.ToString());
zBuf.Append(tmpDir + "/" + SQLITE_TEMP_FILE_PREFIX + zRandom.ToString());
return SQLITE_OK;
}
The above patch will result in an extra folder tmpDir in the isolatedstorage, and the temp files won't be deleted automatically, so it needs to be delete by self. I tried to delete those files in tmpDir in the method of winClose inside os_win_c.cs, and I found it will result in crash when I do VACUUM. Finally, I delete those tmp files when I closed the database. The following is a Dispose method in SQLiteConnection class.
public void Dispose()
{
if (_open)
{
// Original codes for close sqlite database
Sqlite3.sqlite3_close(_db);
_db = null;
_open = false;
// Clear tmp files in tmpDir, added by Toro 2011,05,13
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
string tmpDir = "tmpDir";
if (store.DirectoryExists(tmpDir) == false) return;
string searchPath = System.IO.Path.Combine(tmpDir, "*.*");
foreach (string file in store.GetFileNames(searchPath)) {
store.DeleteFile(System.IO.Path.Combine(tmpDir, file));
}
}
}

Resources