Sunday, June 14, 2020

C# Interview questions

What is serialization?
When transport an object through a network, then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization.
Deserialization is the reverse process of creating an object from a stream of bytes.
Can we use "this" command within a static method?
We can't use 'This' in a static method because we can only use static variables/methods in a static method.
What is the difference between constants and read-only?
Constant variables are declared and initialized at compile time. The value can't be changed afterward. Read-only is used only when we want to assign the value at run time.
What are sealed classes ?
We create sealed classes when we want to restrict the class to be inherited. Sealed modifier used to prevent derivation from a class. If we forcefully specify a sealed class as base class, then a compile-time error occurs.
What is an object pool in .NET?
An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects.
Object Pooling allows objects to keep in the memory pool so the objects can be reused without recreating them.
Use the Factory pattern for this purpose. which will take care of the creation of objects.If there is any object available within the allowed limit, it will return the object, otherwise, a new object will be created and give you back.
What are delegates in C# and the uses of delegates?
Is an abstraction of one or more function pointers 
You can treat a function as data. 
It allow functions to be passed as parameters.
Why Do We Need Delegates?
Callback is to handle button-clicking.
is a solution for situations in which you want to pass methods around to other methods.
You do not know at compile time what this second method is. That information is available only at runtime, hence Delegates are the device to overcome such complications.
What is a Virtual Method in C#?
A virtual method is a method that can be redefined in derived classes. A virtual method has an implementation in a base class as well as derived the class.
The overriding method also provides more than one form for a method. Hence, it is also an example of polymorphism.



Monday, November 26, 2018

Redis Cache Test in Local Host

port : 6379
- In Local, for Redis, need to create a Redis Server to debug:
-Download server: https://github.com/MicrosoftArchive/redis/releases version 3.2.1
-Unzip on a directory  (for example C:\Program Files\RedisServer 5.0)
- cd C:\Program Files\RedisServer 5.0
- redis-server --service-install redis.windows-service.conf --loglevel verbose    ßinstall service
- redis-server --service-start  ß start Service
- redis-cli.exe ßrun client to check keys (get, set, delete)
-Change in app.config ip for Redis (msHost) with 127.0.0.1

Tuesday, October 9, 2018

Windows Form Application Publish OnceClick

Publish Folder Location : is the path (e.g. C:\Publish\App)
Installation Folder URL : is IIS (e.g. http:\\localhost\AppInstall)

E.g. http://localhost/AppInstall/publish.htm

Assembly Name Product Name can be make it to different application

Friday, June 29, 2018

Git & IONIC

git branch develop
git checkout develop //use
git commit -am "change channel"
git push ionic develop

git checkout master
git merge develop
git commit -am "merge conflict" // checkin local
git push origin // push to server
git push ionic master // push to server

git status

Friday, June 1, 2018

Dowload Attachment From Google Mail using IMAP


//POP is temporary only, so use IMAP better
//Nuget S22.IMAP

using (ImapClient client = new ImapClient("imap.gmail.com", 993, "Email", "App Password", AuthMethod.Login, true))
{
    IEnumerable<uint> uids = client.Search(
         SearchCondition.From("from@mail")
         .And(SearchCondition.SentSince(new DateTime(2018, 05, 01)))
          .And(SearchCondition.SentBefore(new DateTime(2018, 06, 01))), "Mail box Name");

    Console.WriteLine(uids.Count() + " Emails:");

    foreach (var uid in uids)
    {
        MailMessage message = client.GetMessage(uid,mailbox:"Mail box Name");

        Console.WriteLine(message.Subject);

        foreach (Attachment attachment in message.Attachments)
        {
            byte[] allBytes = new byte[attachment.ContentStream.Length];
            int bytesRead = attachment.ContentStream.Read(allBytes, 0, (int)attachment.ContentStream.Length);
            string destinationFile = @"C:\\myfile\\" + attachment.Name;
            BinaryWriter writer = new BinaryWriter(new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
            writer.Write(allBytes);
            writer.Close();
        }
   }
}

Wednesday, May 30, 2018

command not recognized

  1. Google the correct variable name and path
  2. set to environment variable
  3.  use ; to add on the value if variable name is same


Tuesday, May 29, 2018

dispatch.yaml

Override routing rules, to specific service.
  1. Create a dispatch.yaml
  2. Write Code
dispatch:
  - url: '*/favicon.ico'
    service: default
  - url: 'myurl.com/*'
    service: myservice
  1. cd dispatchfilepath
  2. gcloud config list (check is it in project ?)
  3. gcloud config set project [myproject] (if u not in project)
  4. gcloud app deploy dispatch.yaml