KushMishra 38 Senior Technical Lead

Drag me to hell

KushMishra 38 Senior Technical Lead

An Indian ;)

KushMishra 38 Senior Technical Lead

Yes and now I also agree to the statement after surfing many websites...!!!

KushMishra 38 Senior Technical Lead

Why So Serious...!!!

KushMishra 38 Senior Technical Lead

A Posting Pro ;)

KushMishra 38 Senior Technical Lead

Hi,

Thanks for replying....actually as per the requirement, I need to code into VB.Net however I am a C# developer so meanwhile I learn VB.Net and its syntax, I was thinking of a pure converter that could possibly help me till the time I finish learning VB.Net.

KushMishra 38 Senior Technical Lead

Hi, if you don't want to rely on the client that he/she doesn't disconnects during the upload, then possibly you may think of developing your own service that would re-run this app if even someone closes OR provide some access controls that would stop anyone except the Admin to disconnect from your application.

KushMishra 38 Senior Technical Lead

Instead of writing the following :-

void InitButtonActions() {
    parent.OpenButton.Click += new EventHandler(delegate { CurrentControl.Add(); }); 
}


public TutorialControl CurrentControl {
    get { return currentcontrol; }
    set {
        if (currentcontrol == value)
            return;
        currentcontrol = value;
    }
}

Try swapping both and write as :-

public TutorialControl CurrentControl {
    get { return currentcontrol; }
    set {
        if (currentcontrol == value)
            return;
        currentcontrol = value;
    }
}


void InitButtonActions() {
    parent.OpenButton.Click += new EventHandler(delegate { CurrentControl.Add(); }); 
}

It may help you because now the CurrentControl has been initialized and it may not throw any error if you do CurrentControl.Add()

KushMishra 38 Senior Technical Lead

OK great ! I got you guys...and for "diafol", I would say I completely agree with you :)

KushMishra 38 Senior Technical Lead

A guy

KushMishra 38 Senior Technical Lead

The Spiderwick Chronicles

KushMishra 38 Senior Technical Lead

Hi All,

I am starting this article so that we may share various motivational thoughts (your own creation will be great), poetry, short stories and all.
This goes my own created poetry for all you guys...

"Behind the great mountains, a Sun shines everyday,
making us to beleive there's still a new morning to bless us today.
As that we grow up each day, making hatred and spreading evil,
remember for someone will come and raise this in-devil.
Know what you do and beleive in what you are,
coz sometimes there's no turning back when you reach too far.
So lets become someone, someone we always wanted to be,
and then let go of this evil and make ourselves free".

Eagerly waiting for yours to come :)

KushMishra 38 Senior Technical Lead

Hi All,

I have been wondering about several ways to quickly gain reputation points.
I tried commenting and giving an "Up" to some of the posts, also tried paying forward my endorsements points to many people but somehow (don't know the reasons), my 8 reputation points became -2.
Also, I got "OP-Kudos" before this post but now I am not getting that one too.
Please suggest me how can I overcome this one.

Thanks a lot in advance :)

KushMishra 38 Senior Technical Lead

Hi, it seems like your CurrentControl is of type TutorialControl and then you are calling a method Add() from this class but we don't have any idea what is the error you are getting in CurrentControl.Add(); and moreover the members of that class are not visible here.
So, it would be better for us to help you out if could possibly paste your code and so that someone could take a closer look on the same.

aatish2327 commented: good suggestion +0
KushMishra 38 Senior Technical Lead

So, my whole code goes like following (but not sure still whether it is the correct approach or not and if not please do correct this one) :-

Public Class DataGridExtenders
    Public Shared ReadOnly IsAutoScrollProperty As DependencyProperty = DependencyProperty.RegisterAttached("IsAutoScroll", GetType(Boolean), GetType(DataGridExtenders), New UIPropertyMetadata(False, Sub(a As DataGrid, b As DependencyPropertyChangedEventArgs) OnIsAutoScrollChanged(a, b)))
    Public Shared Function GetIsAutoScroll(ByVal obj As DependencyObject) As Boolean
        Return CBool(obj.GetValue(IsAutoScrollProperty))
    End Function

    Public Shared Sub SetIsAutoScroll(ByVal obj As DependencyObject, ByVal value As Boolean)
        obj.SetValue(IsAutoScrollProperty, value)
    End Sub

    Public Shared Sub OnIsAutoScrollChanged(ByVal o As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim grid = TryCast(o, DataGrid)
        If grid Is Nothing Then
            Return
        End If

        Dim autoScroller = New EventHandler(Sub(sender, e1)
                                                If grid.SelectedItem Is Nothing Then
                                                    Return
                                                End If
                                                grid.UpdateLayout()
                                                grid.ScrollIntoView(grid.SelectedItem)

                                            End Sub)



        If CBool(e.NewValue) Then
            AddHandler grid.Items.CurrentChanged, Function() autoScroller
        Else
            RemoveHandler grid.Items.CurrentChanged, Function() autoScroller
        End If
    End Sub

End Class
aatish2327 commented: good code format +0
KushMishra 38 Senior Technical Lead

Solved this one also by having :-

Public Shared ReadOnly IsAutoScrollProperty As DependencyProperty = DependencyProperty.RegisterAttached("IsAutoScroll", GetType(Boolean), GetType(DataGridExtenders), New UIPropertyMetadata(False, Sub(a As DataGrid, b As DependencyPropertyChangedEventArgs) OnIsAutoScrollChanged(a, b)))

Thanks to all anyways for at least going through this one :)

aatish2327 commented: good try +0
KushMishra 38 Senior Technical Lead

I don't think there's a way as there are no replies but anyways I solved this by changing the background of the rows and alternating rows of the datagrid I am populating data into from one of my Frame's pages which I am calling :)

aatish2327 commented: good try +0
KushMishra 38 Senior Technical Lead

I solved this one also by applying the following code :-

 AddHandler grid.Items.CurrentChanged, Function() autoScroller

But I am not sure if it would work or not.
Anyways, I have another problem now...

Public Shared ReadOnly IsAutoScrollProperty As DependencyProperty = DependencyProperty.RegisterAttached("IsAutoScroll", GetType(Boolean), GetType(DataGridExtenders), New UIPropertyMetadata(False, OnIsAutoScrollChanged()))



 Public Shared Sub OnIsAutoScrollChanged(ByVal o As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim grid = TryCast(o, DataGrid)
        If grid Is Nothing Then
            Return
        End If

        Dim autoScroller = New EventHandler(Function(sender, e1)
                                                If grid.SelectedItem Is Nothing Then
                                                    Return Nothing
                                                End If
                                                grid.UpdateLayout()
                                                grid.ScrollIntoView(grid.SelectedItem)

                                            End Function)



        If CBool(e.NewValue) Then
            AddHandler grid.Items.CurrentChanged, Function() autoScroller
        Else
            RemoveHandler grid.Items.CurrentChanged, Function() autoScroller
        End If
    End Sub

But in "New UIPropertyMetadata(False, OnIsAutoScrollChanged())", its showing some error as "Argument not specified for parameter 'o' of 'Public Shared Sub OnIsAutoScrollChanged(o As System.Windows.DependencyObject, e As System.Windows.DependencyPropertyChangedEventArgs)'".

Could some one please help me with this ???

aatish2327 commented: nice job done +0
KushMishra 38 Senior Technical Lead

I think there are none as of now :)

aatish2327 commented: good thread +0
KushMishra 38 Senior Technical Lead

Hi,

Check if your partition is password protected (like Bitlocker Encryption etc.)

aatish2327 commented: nice attempt to solve the question +0
KushMishra 38 Senior Technical Lead

Hi,

There may be different problems that cause the issue you are facing.

  1. May be a video graphics driver update affected this(Generally happens with Windows 8). If this is the case, a system restore will do (given at the last of this post).
  2. System crash due to some reasons.
  3. Any other reasons (multiple reasons).

Try to press the windows button with 'R' key, if it opens run command, good for you else, try pressing Ctrl+Alt+Delete and in the task manager, go to new task and type in "explorer.exe", if that doesn't work, try again and this time type in "C:"

Just follow these steps :-

Start->All Programs->Accessories->System Tools->System Restore->Select a Date/Time->Confirm->Just wait and let the system reboot automatically

If still nothing works, you may format your windows drive and before that make sure you have got the backup of important files/folders, if any, on that particular drive.

aatish2327 commented: nice attempt to solve the question +0
KushMishra 38 Senior Technical Lead

Hi, I am not sure but probably a software called "Crawler" may fix your issue.
This crawler is used by many websites also like Google etc.
May be it would be of some help to you as well.

aatish2327 commented: nice attempt to solve the question +0
KushMishra 38 Senior Technical Lead

Hello All,

I am populating my frame from different pages and showing the output as a grid.
Following is my xaml code :-

<Frame x:Name="mainFrame" Grid.Row="1" JournalOwnership="UsesParentJournal" />

and xaml.cs :-

mainFrame.Source = New Uri("Views/ProductsPage.xaml", UriKind.Relative);

But I want to change the selected/unselected (focused/non-focused) row colors in this frame and I am not able to do that.
Could someone please help me with the same ?

Thanks a ton in advance :)

aatish2327 commented: new concept +0
KushMishra 38 Senior Technical Lead

Hey, I replaced Function(p) with Sub(p) and that solved my problem.
Ok now another one...

Dim autoScroller = New EventHandler(Function(sender, e1)
                                                If grid.SelectedItem Is Nothing Then
                                                    Return Nothing
                                                End If
                                                grid.UpdateLayout()
                                                grid.ScrollIntoView(grid.SelectedItem)

                                            End Function)

        If CBool(e.NewValue) Then
            AddHandler grid.Items.CurrentChanged, AddressOf autoScroller
        Else
            RemoveHandler grid.Items.CurrentChanged, AddressOf autoScroller
        End If

In "AddressOf autoscroller", I am getting an error saying "Error 1 'AddressOf' operand must be the name of a method (without parentheses)."

Could anyone please help me with this ?

aatish2327 commented: nice try +0
KushMishra 38 Senior Technical Lead

I already tried the same and in

FindItem(SearchType.ForwardSkipCurrent)

its showing "Expression does not produce a value"

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hi all,

I did the above thing on my own using the following :-

AddHandler CollectionView.CollectionChanged, AddressOf RebuildSearchIndex

However, I am still struggling with the following code in c# and want the same functionality in VB/VB.Net :-

NextCommand = new DelegateCommand(
                p => FindItem(SearchType.ForwardSkipCurrent), 
                x => !String.IsNullOrEmpty(SearchTerm) && !NoResults);

Could someone please help me with the same.
Thanks a ton in advance :)

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hi all,

I am a naive programmer to VB and VB.Net, I have mostly used C# and now I am stuck at a simple point as follows :-

CollectionView.CollectionChanged += Function(sender, e) RebuildSearchIndex()

I don't have any idea how to replace "+=" as its showing some error.
Requesting you all if anyone could please suggest me the correct syntax of the above code.

Earlier (before converting my C# code to VB.Net), it was in C# as follows :-

CollectionView.CollectionChanged += (sender, e) => RebuildSearchIndex();

Thanks a lot in advance :)

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

I mean to say that when at times I try converting my code from C# to VB, it sometimes throw some errors like "Class 'XXX' must implement 'Function XXX(abc,pqr,...)' for interface 'XX.XX.XX'".
For example you may refer to my latest article as follows (which has been solved by deleting the existing code and letting Visual Studio itself implement those functions/methods) :-
C# to VB.Net Errors

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

I mean that when something that I convert through an online converter from C# to VB and then copy directly that particular code to Visual Studio, it sometimes shows some errors and need to rewrite the code again.
For example you may refer to my latest thread as follows:-
Click Here

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hey it solved my problem man...I did not think of deleting the code and letting the VS IDE generate for me but I wonder why it causes such problems even though I had the similar implementaion.
Anyways thanks a lot and if you have aqnswer to this one also please let me know...Appreciate ur help...thanks a ton :)

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hello All,

I just wrote some code in C# and tried converting to VB.Net.
I am getting 3 kinds of errors in my code :-

  1. Class 'XXX' must implement 'Function XXX(abc,pqr,...)' for interface 'XX.XX.XX'.
  2. 'RaiseEvent' definition missing for event 'XXX'.
  3. 'XXX(abc,pqr,...)' is an event and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

For first point, I am bit confused as I have already implemented all the Interface members into my class and even though the compiler is telling me that I must implement the same.
For example :-

Public Class MyConverter
    Implements IValueConverter
    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object
        If value IsNot Nothing AndAlso TypeOf value Is Message Then
            Return True
        End If
        Return False
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object
        Return Nothing
    End Function
End Class

shows the following error :-

Class 'MyConverter' must implement 'Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object' for interface 'System.Windows.Data.IValueConverter'.

Please help me with this.
Thanks to all.

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hello All,

I went through many websites and did not find any converter that could purely convert C# syntax to VB syntax.
However there are many converters available on the Internet but personally I don't think they are pure converters.
Requesting all to please suggest some online tools/converters to achieve this functionality.

Thanks a lot in advance :)

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hi,

May be a better approach would be you use try-catch-finally blocks.
In the constructor/page load event you may call the open connection and in the end under finally block you close your connection.

aatish2327 commented: good question +0
KushMishra 38 Senior Technical Lead

Hi,

I would suggest if you could check your "where" clause as sometimes it may be giving you the last element as you are saying. May be that wwould helo and more over you have starred the items contained in that particular attribute and its hard to sya which part would be inappropriate.

KushMishra 38 Senior Technical Lead

Hi,

Try using some approach like ItemArray["LOCID"] and try to match it with the ComboBoxItem in your control.

KushMishra 38 Senior Technical Lead

Thanks a lot, I will surely try this one out and let you know :)

KushMishra 38 Senior Technical Lead

Hi,

I did wrote mySql.close(); in the finally block and also removed the if condition. But somehow, it also doesn't work.
Could you please give some code to do this that can possibly help me out of this situation ?

KushMishra 38 Senior Technical Lead

I understand that this is a fine code however I wanted to keep the connection open always so that no time out exists.
I did this way :-

if (mySqlCon.State == ConnectionState.Closed)
{
   mySqlCon.Open();
}

MySqlCommand mySqlCommand = mySqlCon.CreateCommand();
mySqlCommand.CommandTimeout = 0;

And this is also working fine but thanks a lot for your suggestions too, they may be useful for future :)

KushMishra 38 Senior Technical Lead

I tried the first solution by using the following :-

if (mySqlCon.State == ConnectionState.Closed)
{
   mySqlCon.Open();
}

I think that would work. Please correct if wrong :)

KushMishra 38 Senior Technical Lead

Hi,

I am facing some problems.

I am writing the output and exceptions to a log file as OpenPOP in text format. My service is running fine however after 1 or 1.6 hours, it displayed an exception in the log file as

"11/7/2013 2:48:55 PM Connect(): No such host is known
11/7/2013 2:48:55 PM The server could not be found. POP3 Retrieval"

and I guess that may be due to the connection timeout as I am using MySql as the backend to store the new emails data and I think the connection got expired, so my question is that how can I set its timeout for infinite time or till the time the system is ON as I want this service all time running in the background and interact with the Database.

Would using the following be a solution :-

if (mySqlCon.ConnectionTimeout == -1)
{
   mySqlCon.Open();
}
mySqlCon.Open();
MySqlCommand mySqlCommand = mySqlCon.CreateCommand();
mySqlCommand.CommandTimeout = 0;

Also, what about System.Timers.Timer as I have managed to do the same by using the following :-

protected override void OnStart(string[] args)
        {
            myTimer = new System.Timers.Timer(300000);
            myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
            myTimer.Enabled = true;
            myTimer.AutoReset = true;
            myTimer.Start();
        }

Would I be facing any issues when using this instead of System.Threading.Timer and also what is the difference between the two ?

KushMishra 38 Senior Technical Lead

Hi,

I have managed to get the entries written to the database and then I will fetch that data in my WPF application.
Its working perfectly fine however I just wanted to know how can I achieve the functionality of writing to the database in my service at a regular interval say every 5 minutes ? (may be a timer functionality)

Thanks a lot for your help.

KushMishra 38 Senior Technical Lead

Hi, I wrote the logic in my service to get the status (succedeed or failed) of new emails in a string variable as emailStatus and now I added this service project into my solution containing a wpf project.
I built the whole solution, installed this service using installutil.exe myservicename.exe and it was there in services.msc and I started that service.
But now my question is that since this service is now running in the background, how can I have that variable's (emailStatus) value at run time in my WPF application ?

KushMishra 38 Senior Technical Lead

Thanks a lot Ketsuekiame.
I really appreciate your response and the time you have given to this article.
I will surely try to follow the approaches you have suggested and will let you know if I face any issues in between.
Thanks again :)

KushMishra 38 Senior Technical Lead

Thanks for your response to this.

  1. However, firstly, I am asked to use the windows services only instead of WCF as per the requirement so unfortunately even if I intend to go with your sugesstions, I cannot go with them.
  2. Secondly, even if I remove the message box showing number of emails, my question is how can I return those numbers to another WPF application showing number of emails say in a textblock or something.
  3. I want this service running on the user's machine who will install my software i.e., my WPF application so I don't think using special folders would create a problem (if so, please correct me).
  4. As the number of emails would increase the Database (DB) size would also increase so, I don't think that maintaining such a huge DB and extending it as per the increasing number of emails is a good idea (well, for that only I was searching alternatives).
  5. I am not attempting to show UI from service but I want to get the data from the service/DB to the UI and show it to the user.

I appreciate your replies however request you to kindly understand that I am not very much familier with these services concepts and also will appreciate that if possible, please update my code so that it would be understandable to me.

KushMishra 38 Senior Technical Lead

Hi, thanks a lot for this and here's my code now :-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using OpenPop.Mime;
using OpenPop.Mime.Header;
using OpenPop.Pop3;
using OpenPop.Pop3.Exceptions;
using OpenPop.Common.Logging;
using Message = OpenPop.Mime.Message;
using System.IO;
using System.Windows.Forms;

namespace EmailReceivingService
{
    public partial class KMEmailService : ServiceBase
    {
        private readonly Dictionary<int, Message> messages = new Dictionary<int, Message>();
        private readonly Pop3Client pop3Client;
        private string popServerText;
        private string portText;
        private string loginText;
        private string passwordText;
        private TreeView listMessages;
        private TreeView listAttachments;

        public KMEmailService()
        {
            InitializeComponent();
            System.Diagnostics.Debugger.Break();
            this.listMessages = new System.Windows.Forms.TreeView();
            this.listAttachments = new System.Windows.Forms.TreeView();

            // This is how you would override the default logger type
            // Here we want to log to a file
            DefaultLogger.SetLog(new FileLogger());

            // Enable file logging and include verbose information
            FileLogger.Enabled = true;
            FileLogger.Verbose = true;

            pop3Client = new Pop3Client();

            // This is only for faster debugging purposes
            // We will try to load in default values for the hostname, port, ssl, username and password from a file
            string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string file = Path.Combine(myDocs, "OpenPopLogin.txt");
            if (File.Exists(file))
            {
                using (StreamReader reader = new StreamReader(File.OpenRead(file)))
                {
                    // This describes how the OpenPOPLogin.txt file should look like
                    popServerText = reader.ReadLine(); // Hostname
                    portText = reader.ReadLine(); // Port
                    loginText = reader.ReadLine(); // Username
                    passwordText = reader.ReadLine(); // Password
                }
            }
            ReceiveEmails();
        }

        protected override void OnStart(string[] args)
        {

        }

        private void ReceiveEmails()
        {
            try
            {
                if (pop3Client.Connected)
                    pop3Client.Disconnect();
                pop3Client.Connect(popServerText, int.Parse(portText), false);
                pop3Client.Authenticate(loginText, passwordText);
                int count = pop3Client.GetMessageCount();
                messages.Clear(); …
KushMishra 38 Senior Technical Lead

Hi thanks for the response but I'm not sure how to use this code in a new Windows Service as I have very less or no idea about creating windows services.
So, I request if you could please guide and help me at adding this existing code in a windows service and start it in the background like windows processes and lastly I need to show the results generated by this service in my WPF application.
Please help me with the same.
Thanks a lot.

KushMishra 38 Senior Technical Lead

Hi,

Thanks for your response and I have implemented OpenPOP methodology however it is developed in windows forms and I thought of some windows service to achieve this.
Not too sure how to convert this class library to windows service and also, I am completely a newbie to WCF and windows services and as of now not able to understand why do I need WCF when I can do the same thing using windows services.
Could you please help me with this as I am stuck as if I'm in some deadlock mode.
Any help is much appreciated. Thanks a lot for your time and replies.

KushMishra 38 Senior Technical Lead

Thanks to both of you for you replies.

Hi Ketsuekiame, could you please ellaborate by giving some live example ?

Hi deceptikon, is the OpenPOP meant to download the emails and has the services that run in the background also ?

KushMishra 38 Senior Technical Lead

Hello All,

I need to develope an application to receive POP3 emails automatically at regular intervals.
I am totally a newbie to this one and need your kind help.
The application should fetch emails using some service that would run in the background.
So basically I need 2 things (I suppose) :-

  1. A windows service that would run in the background to fetch POP3 emails at regular interval.
  2. An application that would show the new emails (along with the old ones of course) that may come through the windows service.

Any suggestion on this please so that I may kick start it ?
Thanks a lot in advance.

KushMishra 38 Senior Technical Lead

Hey I did this one on my own...anyways thanks for your reply, much appreciate that :)