|
Hi, please read my answer to Mycroft above. The only solution is to format your cells as accounting or currency.
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Hello,
I made an application with clients who connect to a server with .Net remoting. The client requests some values from the server and then the server putts all these request in a buffer (buffer is necessary) and emptys them each 500ms, these requests are send to a "black box" on a socket connection, and then the answer of the black box is being send back to the client with an eventhandler.
Now I have something like
remoteServer.GetValue(Name);
which is given back to the client in an event
But what I want is getting something like this.
Int32 receivedVal = (Int32)remoteServer.GetValue(Name);
Does anyone know the solution?
Thank you 
|
|
|
|
|
My suggestion may not be usable by you:
First get rid of remoting services and deploy your service as a WCF service.
Second make sure your WCF service is NOT deployed as Asynchronous.
Third pull the 'black box' into your service so make it a class that you can instantiate and call internally.
When your service gets the answer back then return it.
In the WCF service your service would be written as if it was an inline method call making the setup quite simple. It also gets rid of the buffering and polling.
If you cannot get rid of the black box behaviour then you might be SOL.
Software Zen: delete this;
|
|
|
|
|
My goal is to try to use the same logic when verifying groups in the active directory for users if they are on the web or in a windows application. However my current problem is the web application is currently using a config file and having users enter their user name and password. The windows application is having the user click on a desktop shortcut and the application obtains the user infromation from windows authenication.
Is there a way to make code listed in the windows application be more like the web application?
If not,why not?
If so, how would you change the code to make to the windows application?
The windows code is the following:
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
hread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if ((!Thread.CurrentPrincipal.IsInRole("TEST"))
{
MessageBox.Show("Please contact your network administrator if you have any questions",MessageBoxIcon.Error);
return;
}
else
{
Application.Run(new newm());
break;
}
The web code is the following:
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace RtSup
{
public class Validator
{
private string _path;
private string _filterAttribute;
public Validator(string path)
{
_path = path;
}
public bool IsAuthenticated(string domainName, string userName, string password)
{
string domainAndUsername = domainName + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, password);
try
{
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return true;
}
}
}
|
|
|
|
|
I would like to setup a switch statement in a C#.net 2008 desktop application. I basically want to check for who has 'group' access according to the active directory. The following is the two statements I am using to obtain the active directory groups.
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
Some how I would need to use Thread.CurrentPrincipal. How would you set this up in the switch statement?
|
|
|
|
|
I don't see why you would decide on syntax before having a concept of the task -- what is it that you want to accomplish?
|
|
|
|
|
You can't. Switch statements can only work on constant values - Thread.CurrentPrincipal is a reference type so it's value range cannot be evaluated as a compile time constant.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I showed you how determine group membership in this post[^]
You need to use the IsInRole method of the CurrentPrincipal object to check for membership, which you could do in a simple if statement.
if (Thread.CurrentPrincipal.IsInRole(@"MYDOMAIN\MyApplicationAdministrators")
{
}
else if (Thread.CurrentPrincipal.IsInRole(@"MYDOMAIN\MyApplicationMangers")
{
}
You wouldn't really use a switch statement for this. Also, you can use imperative or declarative security to check for group membership at method level as well, e.g.
http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermissionattribute.aspx[^]
[PrincipalPermission(SecurityAction.Demand, Role = "MYDOMAIN\MyApplicationAdministrators")]
static void CheckAdministrator()
{
Console.WriteLine("User is an administrator");
}
|
|
|
|
|
Hello, i have designed a window in c# which contains one combobox(contains detected USB devices), one picturebox(for the video), one label, one start button(starts the camera)and one refresh button.
I have a USB security IR camera which i want to connect to the computer and hopefully get some video feed in the picturebox.
I have debugged and builded the project and the designed window pops up as it should. When i push the refresh button while the USB camera is connected,it is written in the combobox "USB 2.0 grabber". When i then push the start button nothing happens. Can somebody help me/explain to me how to get the video feed into the picture box? I really appreciate some help.
Source code follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
namespace cam_aforge1
{
public partial class Form1 : Form
{
private bool DeviceExist = false;
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource = null;
public Form1()
{
InitializeComponent();
}
private void getCamList()
{
try
{
videoDevices = new FilterInfoCollection (FilterCategory.VideoInputDevice);
comboBox1.Items.Clear();
if (videoDevices.Count == 0)
throw new ApplicationException();
DeviceExist = true;
foreach (FilterInfo device in videoDevices)
{
comboBox1.Items.Add(device.Name);
}
comboBox1.SelectedIndex = 0;
}
catch (ApplicationException)
{
DeviceExist = false;
comboBox1.Items.Add("No capture device on your system");
}
}
private void rfsh_Click(object sender, EventArgs e)
{
getCamList();
}
private void start_Click(object sender, EventArgs e)
{
if (start.Text == "&Start")
{
if (DeviceExist)
{
videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
064 CloseVideoSource();
videoSource.DesiredFrameSize = new Size(160,120);
videoSource.Start();
label2.Text = "Device running...";
start.Text = "&Stop";
timer1.Enabled = true;
}
else
{
label2.Text = "Error: No Device selected.";
}
}
else
{
if (videoSource.IsRunning)
{
timer1.Enabled = false;
CloseVideoSource();
label2.Text = "Device stopped.";
start.Text = "&Start";
}
}
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = img;
}
private void CloseVideoSource()
{
if (!(videoSource == null))
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource = null;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = "Device running... " + videoSource.FramesReceived.ToString() + " FPS";
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
CloseVideoSource();
}
}
}
<pre>
|
|
|
|
|
Nothing happens? The label on the button at least should change. If that isn't happening, make sure you actually hooked the event up to the button.
064 CloseVideoSource();
This is a pasting failure, right? Calling Close there would mess up the rest of the start code.
|
|
|
|
|
Edit your original message and in the pre block add the attribute/value lang="cs", that way you will get the colour syntax for C#, like the bit below;
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = "Device running... " + videoSource.FramesReceived.ToString() + " FPS";
}
|
|
|
|
|
How would one access each pixel on a form quick enough for a bitmap to be drawn 30 times a second?
I would like to avoid Bitmap.SetPixel and if possible avoid XNA/Direct X. I built a 3D engine that plots its own triangles etc with textures and shadows. I just don't think using Bitmaps is quick enough. I.E really slow just drawing a black screen.
Is it possible to access per-pixel data in XNA?
|
|
|
|
|
Search for the use of LockBits() .
It converts bitmap images to and from byte arrays. You have to keep track of which byte means what colour component (Alpha, Red, Green, Blue, order may be mangled). Byte array operations are a lot faster than SetPixel() .
Some code I wrote after searching the web for the same thing:
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
System.Drawing.Imaging.BitmapData imageData = image.LockBits(
rectangle,
System.Drawing.Imaging.ImageLockMode.ReadWrite,
image.PixelFormat
);
IntPtr ptr = imageData.Scan0;
int byteCount = Math.Abs(imageData.Stride) * image.Height;
byte[] rgbValues = new byte[byteCount];
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, byteCount);
for (int rgbIndex = 3; rgbIndex < rgbValues.Length; rgbIndex += 4)
{
}
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, byteCount);
image.UnlockBits(imageData);
Ciao,
luker
|
|
|
|
|
I already was using locked bits, sorry. I should have mentioned that much. Looking from the code you've posted though, i've managed to fix the colouring in what I do have. The Red and the Blue were the wrong way aroung :p
Thanks for teh help
|
|
|
|
|
You mentioned SetPixel in the initial question. You're not using that after locking, right? Something similar to what's posted here (locking the bits, marshalling into a byte[], setting the byte values, marshalling it back) is the usual procedure and it is quite fast (I believe, never done it myself).
|
|
|
|
|
Nah, I'm not doing that. I'm locking and unlocking. I just used set pixel to deter people from recommending to use it. I looked back in my previous questions and saw you had made some comments
Locking and Unlocking is still not quick enough unfortunatley
|
|
|
|
|
You can always work with the bits using pointers. Christian Graus outlines a method here[^].
|
|
|
|
|
Interesting article. Its quite similar to my implementaion. In his though he changes the data in the loop. Whilst in mine on the other hand I calculate the entire image in a byte[] then transfer it to a function similar to his to write the bitmap. Maybe I could directly interact in the image processing loop.
Time to experiment
|
|
|
|
|
I wonder if what you're doing inside that pixel loop is too intensive. In particular, if you're reading R, G, B, A properties from a Color each time, that might cause speed issues. If you can have your renderer write directly into the byte array that might help.
|
|
|
|
|
Not going to lie. My ambition in this project is a raytracer. If I can realtime
|
|
|
|
|
A realtime ray tracer will be hard (understatement) without using some hardware acceleration, unless for a very small viewport.
|
|
|
|
|
true, true, Worth a shot. To get a frame a second it has to be ~300px * 150px viewport with reflections and ambient occlusion turned off. I don't know anything about handling hardware though. Currently it is all handled by c# .NET & GDI
|
|
|
|
|
It's tricky to write a software renderer that will be fast enough.
If you want direct pixel access, LockBits is indeed the answer. Depending on what your engine is producing, you may want to draw shapes instead (though if you are texture mapping and lighting, by pixel may be necessary).
|
|
|
|
|
My old engine used the graphics.DrawLine and the graphics.FillPolygon . This (even drawing a simple triangle) was much quicker than using a hand built pixel plotter using locked bits :/
My new engine has lighting and diffuse textures (working but slow at a frame per second with a few meshes on the screen)
Thanks
|
|
|
|
|
i have created a wcf service in 3.5 and trying to host it on 11s6. service was created on windows 7
when i host and browse for the service i get the error
"This collection already contains an address with scheme http. There can be at most one address per scheme in this collection"
i tried couple of things in web config but still getting the error
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://localhost/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
any idea how to get through this
|
|
|
|