|
You should talk to the people who created it - Metter Toledo[^] - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!
The link gives you the technical manual to download and read, plus a link to their support service.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
There may not be a driver for it if the scale exposes itself as a serial device. Look in Device Manager for it and see if it has a COM port associated with it.
|
|
|
|
|
Currently, I am having difficulty in opening firefox browser in mobile emulation mode in selenium c# with MS Test , can someone please help me in that?
Fifrefox code
private static IWebDriver GetFireFoxDriver(string userAgent)
{
var rand = new Random();
var firefox_options = new FirefoxOptions();
firefox_options.AddArgument("-private");
firefox_options.AddArguments("--window-size=1024,768");
firefox_options.AddArguments("--window-position=0,0");
firefox_options.AddArgument($"--user-agent= {userAgent}");
firefox_options.AddArgument("--disable-backgrounding-occluded-windows");
var driver = new FirefoxDriver("C:\\selenium\\firefoxdriver", firefox_options, TimeSpan.FromMinutes(3));
if (userAgent.Contains("Mobile") == true)
{
driver.Manage().Window.Size = new Size(411, 731);
}
return driver;
}
I have done in Chrome Browser - Mobile Emulation
private static IWebDriver GetChromeDriver(string userAgent)
{
var options = new ChromeOptions();
options.AddArgument("incognito");
options.AddArguments("disable-infobars");
options.AddArguments("--window-size=1024,768");
options.AddArguments("--window-position=0,0");
options.AddArgument($"--user-agent= {userAgent}");
if (userAgent.Contains("Mobile") == true)
{
var settings = new ChromeMobileEmulationDeviceSettings(userAgent)
{
Height = 731,
Width = 411,
PixelRatio = 2.6
};
options.EnableMobileEmulation(settings);
}
options.AddArgument("--disable-backgrounding-occluded-windows");
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.SuppressInitialDiagnosticInformation = true;
var driver = new ChromeDriver(service, options, TimeSpan.FromMinutes(3));
return driver;
}
|
|
|
|
|
|
Hi,
I have a web service developed in C# running over Windows 2012 server. This service receives data and connects to destination server for processing. When it establishes connection with remote server it uses only 20 fixed Source Ports. Every new connection is initialized with one of those 20 fixed Source ports. Problem happens when it uses the last source port. Web service can't use the first port again without restarting application pool. I do not see source ports in TIME_WAIT state as well. Strangely web service starts working again after pool re-start but then works until the 20th port only . I know we should have dynamic source ports but there is requirement to setup source ports only given 20 port numbers.
I think code is not doing socket close /cleanup properly and thereby not letting me use the same port again without restarting the pool. Can somebody please help me in any direction where should I check?
|
|
|
|
|
I want to collapse or expand all TreeView nodes under parent node if user holds down Left Control key and presses left mouse button on expansion arrow of tree view.
How do you do this in WPF? It's not as obvious as it was in WinForms.
|
|
|
|
|
Try asking in the WPF forum: Silverlight / WPF Discussion Boards[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Probably a philosophical question, yet what are the reasons to create your own custom localization infrastructure instead of .NET native localization through resx and satellite assemblies?
E.g. ABP framework for web apps includes its own localization engine which boils down to logical method Localize(key, resource), i.e. same logic as native.
My rationale is that an app these days is a bunch of libraries (most commonly .NET standard). A GUI (ASP, winforms, WPF etc.) is just a (graphical) view of the app behind it with little to no business logic/entities. If the app libraries are properly localized, GUI has very little localization left. Each part of an app, is a library, which makes it conveniently localizable using .NET built in mechanism. There should be a good reason not to use it and I see none. Substitution of localization by DI is highly unlikely as that would mean somebody knowing more about app logic and entities than the app itself. It seams unlikely that one could get a significant performance improvement (worth building/supporting infrastructure) as well. Frequency of localization resources changes without respective changes in the app is very low. Therefore no need for "hot install" as well. To sum it up, KISS tends to be on native side.
|
|
|
|
|
It's re-inventing the wheel when you haven't discovered what you already have (access to).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
DI injecting is not that hard to build on top of for example resx - but indeed - is it worth it? There is no single answer to that. I would for example be tempted to use it for supporting pseudo-translation tests directly in the app without having to go through the localization tools to get the pseudo-translated resources for a quick I18N test.
If I have translations with the UI or not depends on a lot of things - for example, if it is a WinForm application (not that I do those anymore) then the size of the controls is typically in the resource file along with the translation - typically making it more of a view thing than entity/business logic. Even in WPF/HTML the layout can effect the chosen translation (i.e. a less accurate but more concise translation being chosen for a label). In reality I think you always end up with plenty of strings throughout the layers.
I understand both the translation and programming workflows, which makes it a bit easier for me to know when to customize and when to stick to standards. If you do not understand the translation workflow, stick to standards. Your little "optimization" could end up being rather problematic. This is less of a problem if you do not use professional translators with access to proper tools though (they won't know when you are wasting their time)
|
|
|
|
|
Hello - I had records to be processed at a time, and the 4th record had an issue. The entire program failed, not processing the rest of the records which had no issue. How can I can continue the program processing the good records?
Thanks!!
|
|
|
|
|
|
I have a catch block in the code which catches all exceptions and writes to log file.
How can I make it that the program continues processing the good records instead of not processing the entire batch.
|
|
|
|
|
You haven't supplied any relevant code so it's impossible to tell you with any accuracy.
But, the try/catch block should surround only the processing of a single record, NOT THE ENTIRE LIST OF THEM.
|
|
|
|
|
That sums it up.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
There is no specific way to answer you because we have no idea how you are processing the records.
One way to do it is to process one record at a time and put that code in a try catch, inside the loop. That way the loop will continue. However, if the problem is that the database is not available, for example, then it's going to throw an exception for every single record you are processing.
|
|
|
|
|
Ask what you want the try-catch to do; retry the current item, or skip it and progress to the next.
Retrying should be limited.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
To add to what the others have said, you might also want to look at why the record failed - what did it contain that you didn't expect? Was it something you should have expected, or been able to handle?
For example, if a user is to enter a page full of information and a single item is wrong, you shouldn't invalidate the whole page - just get the user to enter the right value.
We can't see your screen, access your HDD, or read your mind - so we have no idea what your code is doing, or how it is doing it; but graceful error handling is an important part of any app!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm trying to get the list of allocated ranges for a sparse file on Windows 10 from a C# program. DeviceIOControl requires an array of FILE_ALLOCATED_RANGE_BUFFER structures as the output buffer. I just can't seem to get the correct way of passing these. So far I have....
public static bool GetSparseRange(SafeFileHandle hdrive, in FILE_ALLOCATED_RANGE_BUFFER query, ref FILE_ALLOCATED_RANGE_BUFFER[] response, int count)
{
int nInBufferSize = (int)Marshal.SizeOf(typeof(FILE_ALLOCATED_RANGE_BUFFER));
IntPtr lpInBuffer = Marshal.AllocHGlobal(nInBufferSize);
Marshal.StructureToPtr(query, lpInBuffer, true);
uint bytesread=0;
IntPtr[] ptrArr = new IntPtr[count];
for (int i = 0; i < count; ++i)
{
ptrArr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FILE_ALLOCATED_RANGE_BUFFER)));
Marshal.StructureToPtr(response[i], ptrArr[i], true);
}
bool rc = DeviceIoControl(
hdrive, // device to be queried
(uint)EIOControlCode.FsctlQueryAllocatedRanges, // operation to perform
lpInBuffer, (uint)nInBufferSize, // input buffer
ptrArr, (uint)(nInBufferSize * count)), // output buffer
ref bytesread, // # bytes returned
IntPtr.Zero); // synchronous I/O
// Get the last error and display it.
int error = Marshal.GetLastWin32Error();
for (int j = 0; j < count / nInBufferSize; ++j)
{
if (j < bytesread / nInBufferSize)
Marshal.PtrToStructure(ptrArr[j], response[j]);
Marshal.FreeHGlobal(ptrArr[j]);
}
Marshal.FreeHGlobal(lpInBuffer);
return rc;
}
However this return rc=false, byteread=0 and error=5.
Can anyone suggest the correct way to do this?
Thanks
|
|
|
|
|
|
He was so casual about "error 5" that I assumed everyone knew what it meant, except me ...and it was somehow not relevant.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Yeah, At least one of his problems is ERROR_ACCESS_DENIED but it's entirely possible that there are other errors. I don't see anything else that stands out. I guess it would be nice to know how the SafeFileHandle hdrive is obtained.
|
|
|
|
|
Radnor,
You were on the right track. The program was running as administrator so the "Access denied" was confusing me as well. The SafeFileHandle was created like this ...
using (dd = new FileStream(path + ".dd", FileMode.Open, FileAccess.Write, FileShare.Write))
{
bool finished = NativeMethods.GetSparseRange(ldd.SafeFileHandle, query, ref response, 1024);
}
So when the DeviceIoControl was called the file was empty which for some reason caused the return code 5.
Changing the FileStream creation for an existing file stopped the error.
However now I get an 0x00000057 error, parameter error which brings me back to the original question as how to pass an array of structures to DeviceIoControl.
This is what I've tried, the output buffer is the issue I think....
public static bool GetSparseRange(SafeFileHandle hdrive, in FILE_ALLOCATED_RANGE_BUFFER query, ref FILE_ALLOCATED_RANGE_BUFFER[] response, int count)
{
int nInBufferSize = (int)Marshal.SizeOf(typeof(FILE_ALLOCATED_RANGE_BUFFER));
IntPtr lpInBuffer = Marshal.AllocHGlobal(nInBufferSize);
Marshal.StructureToPtr(query, lpInBuffer, true);
uint bytesread=0;
int nOutBufferSize = nInBufferSize * count;
IntPtr lpOutBuffer = Marshal.AllocHGlobal(nOutBufferSize);
bool rc = DeviceIoControl(
hdrive,
(uint)EIOControlCode.FsctlQueryAllocatedRanges,
lpInBuffer, (uint)nInBufferSize,
lpOutBuffer, (uint)nOutBufferSize,
ref bytesread,
IntPtr.Zero);
int error = Marshal.GetLastWin32Error();
Marshal.PtrToStructure(lpOutBuffer, response);
Marshal.FreeHGlobal(lpInBuffer);
Marshal.FreeHGlobal(lpOutBuffer);
return rc;
}
Thanks
|
|
|
|
|
Hello,
Your GetSparseRange function is working for me. I simply wrote a quick test application and used the function you provided.
using System;
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace SparseRanges
{
#region Structs
struct FILE_ZERO_DATA_INFORMATION
{
public long offset;
public long zero;
}
struct FILE_ALLOCATED_RANGE_BUFFER
{
public long offset;
public long length;
}
#endregion
class Program
{
#region Const ints
const uint FSCTL_SET_SPARSE = 590020;
const uint FSCTL_QUERY_ALLOCATED_RANGES = 606415;
#endregion
[DllImport("kernel32.dll", SetLastError = true)]
extern static bool GetVolumeInformation(string vol, StringBuilder name, int nameSize, out uint serialNum, out uint maxNameLen, out uint flags, StringBuilder fileSysName, int fileSysNameSize);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, IntPtr lpInBuffer, [In] int nInBufferSize, IntPtr lpOutBuffer, [In] int nOutBufferSize, ref uint lpBytesReturned, [In] IntPtr lpOverlapped);
public static bool GetSparseRange(SafeFileHandle hdrive, in FILE_ALLOCATED_RANGE_BUFFER query, ref FILE_ALLOCATED_RANGE_BUFFER[] response, int count)
{
int nInBufferSize = (int)Marshal.SizeOf(typeof(FILE_ALLOCATED_RANGE_BUFFER));
IntPtr lpInBuffer = Marshal.AllocHGlobal(nInBufferSize);
Marshal.StructureToPtr(query, lpInBuffer, true);
int nOutBufferSize = nInBufferSize * count;
IntPtr lpOutBuffer = Marshal.AllocHGlobal(nOutBufferSize);
uint bytesread = 0;
bool rc = DeviceIoControl(hdrive, FSCTL_QUERY_ALLOCATED_RANGES, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, ref bytesread, IntPtr.Zero);
int error = Marshal.GetLastWin32Error();
Marshal.FreeHGlobal(lpInBuffer);
Marshal.FreeHGlobal(lpOutBuffer);
return rc;
}
private static void PrintSparseRange(FILE_ALLOCATED_RANGE_BUFFER range)
{
Console.WriteLine("{0:d} offset, length = {1:d}", range.offset, range.length);
}
static void Main(string[] args)
{
uint temp1, temp2, flags, bytes=0;
if (GetVolumeInformation("C:\\", null, 0, out temp1, out temp2, out flags, null, 0))
{
uint supports_sparse = flags & 0x40;
if (supports_sparse == 0x40)
{
Console.WriteLine("Volume supports sparse files...");
string sparse_filename = Path.GetTempFileName();
System.IO.FileStream f = System.IO.File.Create(sparse_filename);
if (DeviceIoControl(f.SafeFileHandle, FSCTL_SET_SPARSE, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytes, IntPtr.Zero))
{
Console.WriteLine("Successfully generated a sparse file.");
f.SetLength(10240);
FILE_ALLOCATED_RANGE_BUFFER[] response = new FILE_ALLOCATED_RANGE_BUFFER[64];
FILE_ALLOCATED_RANGE_BUFFER query;
query.length = 10240;
query.offset = 0;
int count = 64;
if(GetSparseRange(f.SafeFileHandle, query, ref response, count))
{
Action<FILE_ALLOCATED_RANGE_BUFFER> print_all = new Action<FILE_ALLOCATED_RANGE_BUFFER>(PrintSparseRange);
Array.ForEach(response, print_all);
}
f.Close();
Console.WriteLine("Removing temp sparse file.");
File.Delete(sparse_filename);
}
}
}
}
}
}
BobZscharnagk wrote: The SafeFileHandle was created like this ...
using (dd = new FileStream(path + ".dd", FileMode.Open, FileAccess.Write, FileShare.Write)) Any particular reason why you are opening the file without Read access?
Best Wishes,
-David Delaune
|
|
|
|
|
Radnor,
Thanks for the reply and the time. When I tried your code, unmodified, i just get 64 lines of "0 offset, length = 0", which is because I think you didn't copy the Marshall'd response back into the passed response. I added two lines to your code...
f.SetLength(10240);
f.Write(new byte[] { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o' }, 0, 5);
and
int error = Marshal.GetLastWin32Error();
Marshal.PtrToStructure(lpOutBuffer, response);
Adding f.Write by itself should cause one of the blocks to be allocated and not show in the output. Testing with just this line gives the same result as if the write wasn't there.
Adding the second change, Marshal.PtrToStructure, causes an error "Quote: System.ArgumentException: 'The specified structure must be blittable or have layout information.
Which I think is where I started.
|
|
|
|
|