Re: WPF - Get scrollbar position of WebBrowser control

2013-09-09 Thread Ben Scott
MarkPad does this to sync the position of the editor and preview. It 
uses Chromium but you might be able to find something useful. I don't 
recall exactly how it works but you would look in the preview view.


https://github.com/Code52/DownmarkerWPF





On 10/09/13 10:18 AM, Jim Baker wrote:

Hello All,

I have a WebBrowser control in my WPF application (Yes some of us still write 
WPF apps !) and I need to find out the x,y positions of the scrollbars.

I'm using this to set the scroll position

mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2;

doc.parentWindow.scrollBy(x,y);   // x and y  passed in to the method.

Sometimes I need to save the scroll positions when scrolling stops for saving 
for use later in the program.

Any assistance appreciated :)

Thanks, Jim




Re: decimal.ToString() (JSON Serialization)

2013-08-10 Thread Ben Scott
Looks like decimal.ToString("G0") will strip the zeros, so 
s1.ToString("G0") == s2.ToString("G0"). I don't know if you can make 
NewtonSoft do that though.


Note that this will fall back to scientific notation, so 
0.1m.ToString("G0") == "1E-25".


Ben


On 11/08/2013 3:02 PM, Corneliu I. Tusnea wrote:

Hi,

Anyone working today?

How can I force the NewtonSoft Json Serializer to serialize two 
decimals the same way? decimal a = 1234.1200M; decimal b = 1234.12M;


|var  sa=  JsonConvert.SerializeObject(new  {  value=  a});
var  sb=  JsonConvert.SerializeObject(new  {value=  b});
Console.WriteLine(sa);
Console.WriteLine(sb);|

Results are: {"value":1234.1200} {"value":1234.12}

How can I force it to serialize them both with 4 decimals so the 
results are identical?


Even simpler, ignoring the serializer, how can I make sa.ToString() == 
sb.ToString() ?

The Json Serializer is only doing a simple .ToString() behind the scenes.

Regards,
Corneliu





Re: Winforms\WIndows Service

2013-07-22 Thread Ben Scott
I have generally written services as console apps first, with 
`Console.WriteLine` injected as a log through the application. Then to 
create an installer I just look at the command line options, so my 
main() looks like:


   if (options.Help) {
 // show help
return;
   }
   if (options.Install) {
InstallTheService(GetTransactedInstaller());
return;
   }
   if (options.Uninstall) {
UninstallTheService(GetTransactedInstaller());
return;
   }

   // nothing to action, just spin up the service


Then you need to decide whether you are running in console or as a 
service, and swap out the console for a windows log if required.


If you want to access the service once it is installed I would have a 
GUI that accesses the service via a socket or RPC or indirectly through 
the file system or a database, surfaced via something like a 
notification icon, so WinForms or WPF. There are limitations on services 
running on the desktop that I believe get stricter the more modern an OS 
you are running so I wouldn't even bother trying to surface it directly.


But if you want to be able to run a WinForms app that provides a service 
- think SMTP4DEV, is a notify app that spins up a loopback SMTP server - 
but with the ability to install that service as a Windows service, you 
would just replace the command line option solution above with a button 
in the application that runs the service installer, I'm guessing with 
options that are controlled in the GUI.


Cheers
Ben Scott
@belfryimages



On 22/07/13 5:34 PM, Tom Rutter wrote:

Does it need to run even when no user is logged in?
If not, then you could just create a gui app as required and add it to 
the Windows startup list. Much cleaner and using the features already 
built into Windows.


On Mon, Jul 22, 2013 at 3:43 PM, <mailto:ifum...@gmail.com>> wrote:


I have gui that provides extra functionality when required but 
installed as service so a reboot doesn’t affect operation.


*From:*ozdotnet-boun...@ozdotnet.com
<mailto:ozdotnet-boun...@ozdotnet.com>
[mailto:ozdotnet-boun...@ozdotnet.com
<mailto:ozdotnet-boun...@ozdotnet.com>] *On Behalf Of *Tom Rutter
*Sent:* Monday, 22 July 2013 3:26 PM


*To:* ozDotNet
*Subject:* Re: Winforms\WIndows Service

Yeh I maintained an app back in the day that did this for
debugging purposes. Just had 2 code paths. Don't really need it
though. I can't think of a reason you would need this off the top
of my head.

On Mon, Jul 22, 2013 at 10:13 AM, mailto:ifum...@gmail.com>> wrote:

I found some code a while back that allowed me to have an
application that could run as a service or a  winform
interface…anyone done this before?

Anthony






Re: Commercial Source Code Licence

2013-04-18 Thread Ben Scott
I release my oss projects as CC BY-SA 3.0 
(http://creativecommons.org/licenses/by-sa/3.0/) which is a really easy 
licence that allows commercial use and modification. IANAL but my 
understanding is that there is no requirement to actually release or 
open source any commercial modifications.



On 19/04/2013 10:33 AM, Corneliu I. Tusnea wrote:

Hi,

I have for our app few PHP plugins that we distribute that work in 
combination with our application.
I need to add some licence information to these plugins but I'm not 
sure what would be a valid licence to allow users to change it if they 
need to make it work with our service but not redistribute it or use 
it for any other purposes/apps.


The GPL/MIT/.. they all seem driven towards open-source ...

Regards,
Corneliu.




Re: Skywards (Emirates) sent me my password back in clear text

2013-04-04 Thread Ben Scott

  
  
NetRegistry does the same. At least you
  have to sign in to the reseller account first but after that,
  clear text all the way.
  
  
  
  On 4/04/2013 6:09 PM, Bec Carter wrote:

Just realised the web hoster I use does the same (ahem
  studiocoast)..they even display it in cleartext on the admin
  control panel page upon login. Never thought they'd do that so
  didn't notice just til now
  
  
On Tue, Mar 26, 2013 at 9:42 PM, Corneliu I. Tusnea 
wrote:

  This is one of those "OMG, there are still
websites keeping passwords in clear text" moments but
Skywards happily sent me back my password in clear text.


Anyone knows anyone in Skywards that I can get their
  a*** kicked for this?


http://tinypic.com/r/10ds11y/6






  

Regards,
Corneliu.


  

  
  


  



RE: ASP.NET app for different devices

2013-03-15 Thread Ben Scott
I would start with twitter bootstrap. It is trivial to build a responsive
interface and styling past tue default is pretty simple too.

Sent from my Windows Phone
--
From: Arjang Assadi
Sent: 16/03/2013 10:30 AM
To: ozDotNet
Subject: Re: ASP.NET app for different devices

Modernizer, jquery , jquery mobile to star with.
Brows stack over flow for more recent additions, almost every day there is
a new framework coming out these a days. Depending on your needs signal or
not. Most likely you won't be detecting browsers and rendering html
accordingly, that is the old way of doing things. You would be detecting
capabilities and working accordingly, kind of like programming purely with
interfaces. The html will be almost constant for all devices and browsers
but the java script library would do the rest on client, how ever that is
when minification needs to kicks in, having said that one might settle for
the minimum look instead and go for simple but fast loading interface.


On 16 March 2013 09:50, Greg Keogh  wrote:

> Folks, I might have to write an ASP.NET app that looks pleasant on
> different devices such as Desktop, pad and phone. I will have to reliably
> detect the browsing device and render different html, but I've not needed
> to do this before. I'll bet someone in here has done this, and if so, can
> you give me a potted summary of what the tricks are (in the hope you can
> help me avoid hours of searching and experimental suffering). I'll start
> running some searches anyway.
>
> Thanks,
> Greg K
>


Re: does anyone know a good technique to keep track of your braces in C#?

2013-02-13 Thread Ben Scott
Katherine, from what I understand you are vision-impaired? I can understand
that braces would quickly become a problem for you. Maybe you could look
into a language like F# which uses tabs for nesting rather than braces.
There would be a learning curve but that may be worthwhile in the long
term. Other alternatives are Ruby and Coffeescript - Coffeescript may be a
good start as you may be able to leverage that in to developing
Javascript-based Windows 8 apps.

Other than that I would recommend just making sure each brace is on a new
line so that you can see the nesting. It is tempting to cram as much on
each line but in the long run spreading it out makes it much easier to
maintain. Also use a brace whenever you can, so no shortcuts like:

if (something) Foo();

Instead always do:

if (something)
{
Foo();
}



On Thu, Feb 14, 2013 at 9:42 AM, Craig van Nieuwkerk wrote:

> Sounds like you have too much nesting. If you have more than a couple of
> levels maybe try separating it out into new methods. Hard to tell without
> seeing the code.
>
>
> On Thu, Feb 14, 2013 at 10:37 AM, Katherine Moss <
> katherine.m...@gordon.edu> wrote:
>
>> Hello all,
>> Does anyone know any methods I could use when practicing programming in
>> C# (I'm kind of just learning, so it can get annoying sometimes), to keep
>> my braces straight?  I will be writing something simple, and then before I
>> know it, I'll have fifty errors show up all because of one brace not closed
>> or two braces in the wrong place.  Very annoying when fifty errors come up
>> because of a single problem.  And not only in keeping track of braces, I'm
>> also confused as to what goes in between braces since C# gets layered
>> sometimes in terms of code blocks.  Books demonstrate examples well,
>> however, they do not do a very good job telling you where braces go to
>> begin with and why.  Responses would be great on this.  Thanks.
>>
>>
>


Re: SPAM-LOW Re: WCF service best practises

2013-02-04 Thread Ben Scott
I had the idea that `CreateInstanceAndUnwrap` and `MarshalByRef` used
remoting under the covers, any marshalled objects needed to stick to what
remoting supports. _Huge_ gotchas in those murky waters...



On Tue, Feb 5, 2013 at 1:31 PM, Paul Glavich wrote:

> You can get away without directly using remoting if you want appDomain
> isolation. In our app, we have a threadpool and an appDomain pool. Some
> items get shunted off to threads to do some work, some off to separate
> appDomains for the isolation you mentioned. You can use the AppDomain
> object itself, then use the ‘CreateInstanceAndUnwrap’ method to create an
> instance of a ‘MarshalByRef’ object, then execute methods off that.
>
> ** **
>
> When all is done, use the AppDomain.Unload method to get rid of it. And
> no, just going across appDomains, I would not use the mentioned
> technologies (WebApi etc..) as you would be seriously wasting time with
> unnecessary network calls, serialisation/de serialisation etc….
>
> ** **
>
> **-  **Glav
>
> ** **
>
> ** **
>
> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Ben Scott
> *Sent:* Tuesday, 5 February 2013 12:02 PM
>
> *To:* ozDotNet
> *Subject:* Re: SPAM-LOW Re: WCF service best practises
>
> ** **
>
> In the MarkPad Code52 project I was using remoting to implement appdomains
> for plugins, so that plugins couldn't crash the editor. It didn't work,
> probably due to my inexperience, but it seemed like remoting is still the
> status quo for appdomains. I don't see why you would try to do that over
> something like webapi, NancyFx or even SignalR for cross machine comms.
>
>
> 
>
> On Tue, Feb 5, 2013 at 8:53 AM, Paul Glavich 
> wrote:
>
> Nope. Remoting is a way to marshal objects across a boundary whether that
> be appDomain (2 separate appDomains on the same machine) or a network
> boundary (machine 1 to machine 2). It looks and operates very much like
> DCOM if that helps, in that it appears that you have a reference to the
> same object on either end. Security wise it is not so strong but it works
> well and security can be implemented via it channel sink mechanism. It goes
> way back to .Net 1 and is embedded in the core framework. Back in .Net 1
> days it was either ASMX web services or remoting to get across machines. As
> already surmised, it is not promoted as a communications or messaging
> strategy since it is proprietary and quite low level from a framework
> perspective.
>
>  
>
> System.Net.EnterpriseServices is kind of a COM+/DCOM wrapper for .Net and
> allowed things like easily exposing .Net components via COM+/DCOM (as a
> ServicedComponent) through the component services manager (although you
> don’t have to do this) for use by .Net and non .Net clients alike
> (primarily VB 6, C/C++ etc…). I can’t say I have used this namespace in a
> while though so memory is a little rusty. The component services manager
> also made it easier to manage transaction scopes for components and monitor
> their use, in particular distributed transactions. The component services
> manager is actually quite powerful. You had a bunch of attributes in the
> namespace which allowed participation in DTC trx negotiation. There is more
> which I am sure others can highlight for you.
>
>  
>
>  
>
> -  Glav
>
>  
>
>  
>
>  
>
> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Katherine Moss
> *Sent:* Monday, 4 February 2013 5:11 PM
> *To:* ozDotNet
> *Subject:* RE: SPAM-LOW Re: WCF service best practises
>
>  
>
> Now, remind me.  Is System.Net.EnterpriseServices the same as
> System.NET.Remoting?  
>
>  
>
> *From:* ozdotnet-boun...@ozdotnet.com [
> mailto:ozdotnet-boun...@ozdotnet.com ] *On
> Behalf Of *Greg Keogh
> *Sent:* Sunday, February 03, 2013 5:21 PM
> *To:* ozDotNet
> *Subject:* Re: SPAM-LOW Re: WCF service best practises
>
>  
>
> Apparently the .NET remoting documentation has been removed and you have
> to hunt around in the archives for it now (I haven't looked myself), so
> that's probably a hint about being out-of-date. However, I have a
> sentimental feeling for remoting as we have an intensely used client-server
> app out there that will have its 10th birthday later this year, so by the
> date you can tell it started in Framework 1.0 with Remoting. A newer app
> from last year uses WCF and despite the extra work it gives us no
> particular advantage and it works just the same. If don't need all the
> hyped flexibility and generalisation t

Re: SPAM-LOW Re: WCF service best practises

2013-02-04 Thread Ben Scott
In the MarkPad Code52 project I was using remoting to implement appdomains
for plugins, so that plugins couldn't crash the editor. It didn't work,
probably due to my inexperience, but it seemed like remoting is still the
status quo for appdomains. I don't see why you would try to do that over
something like webapi, NancyFx or even SignalR for cross machine comms.



On Tue, Feb 5, 2013 at 8:53 AM, Paul Glavich wrote:

> Nope. Remoting is a way to marshal objects across a boundary whether that
> be appDomain (2 separate appDomains on the same machine) or a network
> boundary (machine 1 to machine 2). It looks and operates very much like
> DCOM if that helps, in that it appears that you have a reference to the
> same object on either end. Security wise it is not so strong but it works
> well and security can be implemented via it channel sink mechanism. It goes
> way back to .Net 1 and is embedded in the core framework. Back in .Net 1
> days it was either ASMX web services or remoting to get across machines. As
> already surmised, it is not promoted as a communications or messaging
> strategy since it is proprietary and quite low level from a framework
> perspective.
>
> ** **
>
> System.Net.EnterpriseServices is kind of a COM+/DCOM wrapper for .Net and
> allowed things like easily exposing .Net components via COM+/DCOM (as a
> ServicedComponent) through the component services manager (although you
> don’t have to do this) for use by .Net and non .Net clients alike
> (primarily VB 6, C/C++ etc…). I can’t say I have used this namespace in a
> while though so memory is a little rusty. The component services manager
> also made it easier to manage transaction scopes for components and monitor
> their use, in particular distributed transactions. The component services
> manager is actually quite powerful. You had a bunch of attributes in the
> namespace which allowed participation in DTC trx negotiation. There is more
> which I am sure others can highlight for you.
>
> ** **
>
> ** **
>
> **-  **Glav
>
> ** **
>
> ** **
>
> ** **
>
> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Katherine Moss
> *Sent:* Monday, 4 February 2013 5:11 PM
> *To:* ozDotNet
> *Subject:* RE: SPAM-LOW Re: WCF service best practises
>
> ** **
>
> Now, remind me.  Is System.Net.EnterpriseServices the same as
> System.NET.Remoting?  
>
> ** **
>
> *From:* ozdotnet-boun...@ozdotnet.com [
> mailto:ozdotnet-boun...@ozdotnet.com ] *On
> Behalf Of *Greg Keogh
> *Sent:* Sunday, February 03, 2013 5:21 PM
> *To:* ozDotNet
> *Subject:* Re: SPAM-LOW Re: WCF service best practises
>
> ** **
>
> Apparently the .NET remoting documentation has been removed and you have
> to hunt around in the archives for it now (I haven't looked myself), so
> that's probably a hint about being out-of-date. However, I have a
> sentimental feeling for remoting as we have an intensely used client-server
> app out there that will have its 10th birthday later this year, so by the
> date you can tell it started in Framework 1.0 with Remoting. A newer app
> from last year uses WCF and despite the extra work it gives us no
> particular advantage and it works just the same. If don't need all the
> hyped flexibility and generalisation that WCF give you then it doesn't
> contribute much.
>
>  
>
> If you just want two .NET app ends to talk over tcp or pipe with minimal
> configuration or code bloat then remoting is still viable. I have a tiny
> utility project with minimal remoting server and client classes that I
> throw into a project if I quickly need two things to communicate. However,
> there is little need for it lately as loading stuff into an AppDomain and
> talking via a proxy is easier, and guess what ... it uses remoting
> internally to talk between AppDomains. So remoting isn't dead, it's just
> gone into hiding.
>
>  
>
> Greg
>


RE: Image Exif updating

2012-12-28 Thread Ben Scott
VS2010 pro runs fine under W8, side by side with VS2012 express at least

Sent from my Windows Phone
--
From: Greg Keogh
Sent: 29/12/2012 1:33 PM
To: ozDotNet
Subject: Re: Image Exif updating

Katherine, Ben,

I've never run an upgrade, I always fresh install. That's why an Xmas
"upgrade" takes so many days of sweat and swearing.

I'm pretty confident that all of the apps, kits and tools that I use will
run fine under Win8 (they seem okay in VMPlayer), except for the damned
nuisance of vdproj files not being supported under VS2012. I was going okay
with using WiX as a replacement, but I got stuck on two things: (1) IIS
setup (2) Custom dialogs. It will take many more hours of study and
experiments to overcome these issues.

Ian, I found lots of libraries for reading EXIF data but none for updating.
I can't remember being involved in a thread on this topic before. The code
I found that may do what I want using encoders is just too much bother for
my modest needs. I guess it's just another case of something that seems
superficially simple, really isn't.

Greg


Re: Image Exif updating

2012-12-28 Thread Ben Scott
Greg, I decided to risk an in-place upgrade from W7 to W8 and didn't have
any problems at all. VS2010, SQL Server Express, MySQL, PHP, Apache, Git,
chocolatey, Ruby, etc etc. Everything worked perfectly. My wireless network
settings were even kept. Mind. Blown.


On Fri, Dec 28, 2012 at 4:23 PM, Greg Keogh  wrote:

> Hi folks, just a heads-up I found during holiday coding.
>
> I have a SQLite+EF4+WPF app over thousands of family photos and images. As
> you'd expect, I extract the Exif data using PropertyItem collection and put
> it in the tables, so the DB simply acts like a huge index over the images.
> You can also add captions and comments to pictures, but they go into the
> table and not into the image itself.
>
> I thought I'd spend an hour or so updating the app so that the captions
> and comments text was stored in the Exif items in the images (just like
> ratings go into the ID3 tags in my mp3 files). It turns out it's not so
> simple. Hundreds of people have trivial sample code to extract the Exif
> items, but I can't easily find any samples of updating. I find that the
> PropertyItem class has no constructor, so I read people "steal" an existing
> one and update it, or clone it, and then I see complaints that this
> technique does and doesn't sometimes work. Then I see complaints that
> updating the Exif items and saving the image re-encodes the images,
> although some people claim to have workarounds for this. Finally I find
> some dense and unfamilar code that use BitmapEncoder classes that perhaps
> do what I need, but there are more arguments about if it works correctly.
>
> So afer a couple of hours of browsing hundreds of websites and code
> samples I decide that it's more suffering than I need during a holiday
> break. It would take more hours of test coding and suffering to find what
> actually works, so I officially decide "f**k it all".
>
> If someone has been through this before and knows of a magic trick for
> easily and reliably updating image Exif items without the danger of
> information loss due to re-encoding, then I'm all ears.
>
> Cheers,
> Greg
>
> P.S. Each Xmas break I usually perform a PC upgrade, but I'm still happy
> with my one year old donk and I couldn't face the estimated 5 x 15 hour
> days of work to migrate to Win8 on an SSD. I've got Win8 and VS2012 in a
> VMPlayer and I think I'll just leave it there for now. The cost and time of
> upgrading my primary Windows OS is bloating each year.
>


Re: Managing databases

2012-12-17 Thread Ben Scott
Just plain Ruby. I think I used RubyInstaller for Windows -
http://rubyinstaller.org/


On Tue, Dec 18, 2012 at 11:33 AM, Katherine Moss
wrote:

>  Is that written in IronRuby, by any chance?
>
> ** **
>
> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Ben Scott
> *Sent:* Monday, December 17, 2012 8:29 PM
> *To:* ozDotNet
> *Subject:* Re: Managing data
>
> ** **
>
> I have a similar system but I have a simple ruby script that applies
> migration scripts. I can run it against development databases and when I'm
> deploying a new version of the system I just run it against the production
> database. It includes a bootstrap migration to create the schema version
> table, and if the first migration is a dump of the existing schema and you
> insert the migration record on production you can create development
> databases totally in script. I've open sourced the script at
> https://github.com/swxben/Shu-Er/tree/master/ruby/database_migrations
>
>
> 
>
> On Tue, Dec 18, 2012 at 9:36 AM, Stuart Kinnear 
> wrote:
>
> I guess this is an age old problem, managing database changes such that
> they respect applications dependent on them.  We are bolting more
> applications to a couple of sql databases so the management exercise is
> becoming more complex, risky and expensive to maintain.
>
> ** **
>
> Currently we have a database version number, use schema naming for
> application specific views and procedures and have a folder of each change
> in sequential order that has to be applied to production.
>
> ** **
>
> Over the holiday break I thought I might research how we can improve our
> approach.  What systems have you or your organisations adopted  to keep it
> all under control , and are they successful? 
>
> ** **
>
> ** **
>
> --
>
> -
> Stuart Kinnear
> Mobile: 040 704 5686.   Office: 03 9589 6502
>
> SK Pro-Active! Pty Ltd
> acn. 81 072 778 262
> PO Box 6117 Cromer, Vic 3193. Australia
>
> Business software developers.
> SQL Server, Visual Basic, C# , Asp.Net, Microsoft Office.
>
> -
> 
>
> ** **
>


Re: Managing databases

2012-12-17 Thread Ben Scott
I have a similar system but I have a simple ruby script that applies
migration scripts. I can run it against development databases and when I'm
deploying a new version of the system I just run it against the production
database. It includes a bootstrap migration to create the schema version
table, and if the first migration is a dump of the existing schema and you
insert the migration record on production you can create development
databases totally in script. I've open sourced the script at
https://github.com/swxben/Shu-Er/tree/master/ruby/database_migrations



On Tue, Dec 18, 2012 at 9:36 AM, Stuart Kinnear wrote:

> I guess this is an age old problem, managing database changes such that
> they respect applications dependent on them.  We are bolting more
> applications to a couple of sql databases so the management exercise is
> becoming more complex, risky and expensive to maintain.
>
> Currently we have a database version number, use schema naming for
> application specific views and procedures and have a folder of each change
> in sequential order that has to be applied to production.
>
> Over the holiday break I thought I might research how we can improve our
> approach.  What systems have you or your organisations adopted  to keep it
> all under control , and are they successful?
>
>
> --
>
> -
> Stuart Kinnear
> Mobile: 040 704 5686.   Office: 03 9589 6502
>
> SK Pro-Active! Pty Ltd
> acn. 81 072 778 262
> PO Box 6117 Cromer, Vic 3193. Australia
>
> Business software developers.
> SQL Server, Visual Basic, C# , Asp.Net, Microsoft Office.
>
> -
>
>


Re: log4net sample

2012-03-18 Thread Ben Scott
Ok, so given a WinForms app, I have a 'myapp.log4net' file (
https://gist.github.com/2070790) which gets copied to the output directory.
This file contains an AdoNetAppender and an SmtpAppender. The database
table is included in the l4n documentation I believe. Note the  tag
at the end of the file, that would let you add and remove appenders easily
in the XML, but just don't forget it. Then when initialising the app (in
Main()) I have the following:

var log = LogManager.GetLogger(typeof(MainForm));
XmlConfigurator.Configure(new FileInfo("myapp.log4net"));

`log` is then added to the IoC container and used through the app. I used
the same method for a couple of Windows services and ASP.NET (including
MVC) sites (in Global or MvcApplication's Application_Start() method),
although I used the following initialisation code one site:

var log = LogManager.GetLogger("MyWeb");// MyWeb is the
namespace, typeof(Global)
XmlConfigurator.Configure(new
FileInfo(Server.MapPath("~/myweb.log4net")));

I don't know if that variation was required, or was just the first thing I
tried that worked.

WCF services hosted in IIS seem to be different, the discrete `xx.log4net`
configuration file didn't work due to something to do with the service not
being able to find the file. The XML contained in the .log4net file (ie
..) has to be copied verbatim into the web.config file
within the main  tag, and the log4net section declared in
the configSections tag:

  

  

Then the initialisation code has to go in a ServiceHostFactory
implementation's CreateServiceHost() method for the WCF service - IIS
hosted WCF services don't have a clear lifecycle like ASP.NET afaik. The
init code is:

XmlConfigurator.Configure();
var log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// not sure why typeof(MyHostFactory) wouldn't have worked.

This method can also be used with ASP.NET to avoid having a seperate
.log4net file.

Ben



On Sun, Mar 18, 2012 at 6:34 PM, Greg Keogh  wrote:

> Does anyone here use log4net? I used it several years ago but found it to
> be huge overkill because all I ever wanted to do was write everything to
> rolling files. I eventually wrote my own lightweight ‘RollingFile’ class
> and have used it for years. Now my logging needs have become a bit more
> complicated and I see that the latest log4net has expanded greatly to have
> all sorts of fancy appenders and filters. I quite like the idea that I can
> send severe error messages via email and boring stuff to a database (or
> lots of other interesting combinations like UDP and the event log).
>
> ** **
>
> I’ve spent some spare time over the last few days trying to get the
> simplest example of writing to the TraceAppender or ConsoleAppender, but no
> matter what I do with config files and code I get no output. I have pasted
> lines out of dozens of examples and web searched until my eyes bleed
> without hope. Stepping deep inside tells me that the library “is not
> configured” and it does nothing.
>
> ** **
>
> Could any kind person give me a minimal example of some code and a config
> file that writes “Hello” to a TraceAppender so it appears in the output
> window of VS2010? I am utterly stumped and at wits end.
>
> ** **
>
> Thanks, Greg
>


Re: log4net sample

2012-03-18 Thread Ben Scott
You're probably right, in my experience log4net silently fails if there is 
anything wrong with the configuration. I don't have anything at hand but I have 
configurations for email and database appenders, I think both in XML and code, 
that I'll pass in later.

Sent from my iPod

On 18/03/2012, at 6:34 PM, "Greg Keogh"  wrote:

> Does anyone here use log4net? I used it several years ago but found it to be 
> huge overkill because all I ever wanted to do was write everything to rolling 
> files. I eventually wrote my own lightweight ‘RollingFile’ class and have 
> used it for years. Now my logging needs have become a bit more complicated 
> and I see that the latest log4net has expanded greatly to have all sorts of 
> fancy appenders and filters. I quite like the idea that I can send severe 
> error messages via email and boring stuff to a database (or lots of other 
> interesting combinations like UDP and the event log).
>  
> I’ve spent some spare time over the last few days trying to get the simplest 
> example of writing to the TraceAppender or ConsoleAppender, but no matter 
> what I do with config files and code I get no output. I have pasted lines out 
> of dozens of examples and web searched until my eyes bleed without hope. 
> Stepping deep inside tells me that the library “is not configured” and it 
> does nothing.
>  
> Could any kind person give me a minimal example of some code and a config 
> file that writes “Hello” to a TraceAppender so it appears in the output 
> window of VS2010? I am utterly stumped and at wits end.
>  
> Thanks, Greg


Re: Learning LINQ - update

2012-03-15 Thread Ben Scott
I don't know GridView very well (or LINQ to SQL), but to rule out deferred
execution being the problem you could change "GridViewStaff.DataSource =
stafflist;" to "GridViewStaff.DataSource = stafflist.ToList();".

Calling ToList() will execute the query and returns an IList<> instead of
IEnumerable<> (which is what your query will be).



On Fri, Mar 16, 2012 at 4:49 PM, Peter Maddin wrote:

> I just threw together a quick console application using the same code
>
> ** **
>
> static void Main(string[] args)
>
> {
>
> 
>
> var conn = ConfigurationManager.ConnectionStrings[
> "PathWestStaffConnectionString"].ConnectionString;
>
> 
>
> var staffDetails = new StaffDataContext(conn);
>
> 
>
> Console.WriteLine("Testing");
>
> 
>
> //This works
>
> var stafflist =
>
> from staff in staffDetails.Staffs
>
> orderby staff.Last_Name
>
> select staff;
>
> ** **
>
> ** **
>
>  so does this.
>
> //var stafflist =
>
> //from staff in staffDetails.GetTable()
>
> //orderby staff.Last_Name
>
> //select staff;
>
> 
>
> foreach (var x in stafflist)
>
> {
>
> var y = x.Last_Name + " : " + x.First_Name;
>
> Console.WriteLine(y);
>
> }
>
> }
>
> ** **
>
> I know that with LINQ you get deferred execution, but I am not getting
> anything in my GridView
>
> I must be doing something really dumb.
>
> ** **
>
> ** **
>
> *Regards Peter Maddin*
> *Applications Development Officer*
> *Path**West Laboratory Medicine WA*
> *Phone : +618 6396 4285 (Monday, Wednesday,Friday)*
>
> *Phone : +618 9346 4372 (Tuesday, Thursday)**
> Mobile: 0423 540 825*
> *E-Mail : petermad...@iinet.net.au; peter.mad...@health.wa.gov.au*
> *The contents of this e-mail transmission outside of the WAGHS network
> are intended solely for the named recipient's), may be confidential, and
> may be privileged or otherwise protected from disclosure in the public
> interest. The use, reproduction, disclosure or distribution of the contents
> of this e-mail transmission by any person other than the named recipient(s)
> is prohibited. If you are not a named recipient please notify the sender
> immediately**.*
>
>  
>
> ** **
>
> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *Peter Maddin
> *Sent:* Friday, 16 March 2012 2:18 PM
> *To:* ozdotnet@ozdotnet.com
> *Subject:* Learning LINQ
>
> ** **
>
> I have a new project so I would thought here is an opportunity to embrace
> LINQ, or in my case LINQ to SQL (at this stage).
>
> ** **
>
> I have a simple SQL Server database and I just want to get retrieve the
> records and bind it to a Web GridView – nothing flash.
>
> ** **
>
> I have tested this in LINQPad
>
> ** **
>
> string con = @"SQL Server Connection String Details goes here";
>
> ** **
>
> DataContext db = new DataContext(con);
>
> ** **
>
> ** **
>
>   var realstaff =
>
>   from staff in db.GetTable()
>
>  where staff.Active == true 
>
>  select staff;
>
>  
>
> realstaff.Dump();
>
> ** **
>
> This works fine.
>
> ** **
>
> In VS20910 in the load event for the GridView I have something similar
>
> ** **
>
> protected void GridViewStaff_Load(object sender, EventArgs e)
>
> {
>
>  
>
> if (connString != null)
>
> {
>
> Staff_Data = new 
> PathWestStaffDataContext(connString.ConnectionString);
>
>  
>
> //This does not work
>
> //var stafflist =
>
> //from staff in Staff_Data.Staffs
>
> //orderby staff.Last_Name
>
> //select staff;
>
>  
>
> // Neither does this.
>
> var stafflist =
>
> from staff in Staff_Data.GetTable()
>
> orderby staff.Last_Name
>
> select staff;
>
>  
>
>  
>
> GridViewStaff.DataSource = stafflist;
>
> GridViewStaff.DataBind();
>
> }
>
> }
>
> ** **
>
> I get no errors but all I get is the Title of The GridView and nothing
> else.
>
> ** **
>
> I would have thought the DataBind() method call would have caused the
> query to execute.
>
> ** **
>
> I am a complete newbie to this.
>
> Can anyone please tell me what I am doing that is wrong.
>
> ** **
>
> *Regards Peter Maddin*
> *Applications Development Officer*
> *Path**West Laboratory Medicine WA*
> *Phone : +618 6396 4285 (Monday, Wednesday,Friday)*
>
> *Phone