Ads 468x60px

Wednesday, January 24, 2018

How to use Embedded Resources in .NET Applications


Today we are going to present how to use embedded files in Visual Studio.


  1. Add your file into your project by right click on the project icon, then click on Add => Add Existing Item.
  2. Go to file properties, and choose the option "Build Action" to "Embedded Resrouce"
  3. Copy the following function that retrieve resources as Stream:
    Public Function GetFileFromResource(ByVal FileName As String, ByVal ProjectName As String) As IO.Stream
    Dim assmbly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
    Dim stream As IO.Stream = assmbly.GetManifestResourceStream(ProjectName + "." + FileName )
     Return stream
    End Function
  4. Now you have a stream connection with the resource that you want to deal with.

Exampe:
If you have a sample project "TestProj" with the embedded resource file "Capture.PNG"
Then you call the function as : GetFileFromResource("Capture.PNG", "TestProj")

Wednesday, December 27, 2017

How to store .NET Project Options as XML in the Project's settings



  1. Right click on your project link, then click on "Properties"
  2. Navigate into "Settings" tab, then add a string parameter. i.e. "ProjectOptions"
  3. The idea is to store multiple Key/Value properties in a single variable using XML format.
  4. Use the function SetProjectOption to store options
        Public Sub SetProjectOption(ByRef ProjectOptions As String, ByVal Key As String, ByVal Value As String)
            Dim Options As Dictionary(Of String, String)
            Options = Me.GetDictoinary(ProjectOptions)
            If Options.ContainsKey(Key.ToLower) Then
                Options(Key) = Value
            Else
                Options.Add(Key.ToLower, Value)
            End If
     
            Me.storeDictionaryInString(Options, ProjectOptions)
     
        End Sub
  5.  Use the function GetProjectOption to get options values
        Public Function GetProjectOption(ByRef ProjectOptions As String, ByVal Key As String) As String
            Try
                Dim Options As Dictionary(Of String, String)
                Options = Me.GetDictoinary(ProjectOptions)
                Return Options(Key.ToLower)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
  6. Helper Function:
      Private Function storeDictionaryInString(ByRef dic As Dictionary(Of String, String), ByRef ProjectOption As String) As String
            Dim doc As New XmlDocument()
            doc.CreateXmlDeclaration("1.0", "utf-8", Nothing)
            doc.AppendChild(doc.CreateElement("AllSettings"))
            Dim root As XmlNode = doc.GetElementsByTagName("AllSettings")(0)
            For Each key As String In dic.Keys
                Dim e As XmlElement = doc.CreateElement(key)
                e.InnerText = dic(key)
                root.AppendChild(e)
            Next
            ProjectOption = doc.OuterXml
            Return doc.OuterXml
        End Function
     
        Private Function GetDictoinary(ByRef ProjectOption As String) As Dictionary(Of String, String)
            Try
                Dim doc As New XmlDocument()
                doc.LoadXml(ProjectOption)
                Dim dic As New Dictionary(Of String, String)
                Dim root As XmlNode = doc.GetElementsByTagName("AllSettings")(0)
                For Each n As XmlNode In root.ChildNodes
                    dic.Add(n.Name.ToLower, n.InnerText)
                Next
     
                Return dic
            Catch ex As Exception
                Return New Dictionary(Of String, String)
            End Try
         
        End Function
Example:
1. Store Options
        Me.SetProjectOption(My.Settings.ProjectOptions, "General.CompanyName", "ABC Company Inc")
        Me.SetProjectOption(My.Settings.ProjectOptions, "General.PurchasedDate", "27 Dec 2017")
        Me.SetProjectOption(My.Settings.ProjectOptions, "General.OFlAG", "True")

2. Read Options
        MsgBox(Me.GetProjectOption(My.Settings.ProjectOptions, "General.OFlAG"))
3. How options stored in the variable:
<?xml version="1.0" encoding="UTF-8"?> <AllSettings> <general.companyname>ABC Company Inc</general.companyname> <general.purchaseddate>27 Dec 2017</general.purchaseddate> <general.oflag>True</general.oflag> </AllSettings>

Thursday, August 24, 2017

How to make instructions video with Machine Voice and Hard-coded Subtitles

In this blog, we are going to learn how to make a video with machine voice commentary and hard-coded subtitles.


  1. Get the video you want to start with, if you plan to make a video related to something in your PC,  you can record your screen using IceCream Screen Recorder.
    You can record up to 5 minutes, but continue reading you would know how to record more than that by merging files together.

  2. The next idea is to get advantage of [Text to Speech] technique to make an MP3 file, that we are going to use later in our video. There are a few websites and applications that does this
    1. From Text to Speech Site [George's voice is the best]
    2. Sound of Text Site: they use the Google Translate voice. You can only convert up to 100 letters.

  3. It's time now to manipulate our video, cut some audio or video parts, bring different portions together, and so on.
    1. The best choice to do such things is Windows Movie Maker.

    2. OpenShot Video Editor is an alternative to Windows Movie Maker, but it's a hassle since it keeps hanging and freezing. But both almost have the same functionalities.
      Note: There are plenty of Youtube video tutorials on both Windows Movie Maker and Open Shot.
  4. we need to create a subtitle (.SRT) text file to the video. Subtitle Edit is an open source software application that does this.
    1. Just import the video file: the application doesn't support certian video formats, so you need to install their codecs.
      The system gives you a message what video codec packages you have to install, so don't worry, i.e. LAVFilters Package.

  5. The last step we need to do is to burn/hardcore subtitles inside the video itself, because not all media players support displaying subtitles. Specially if you want to embed the video in your website, email, etc.
    we have two applications to achieve this
    1. FormatFachtory.

    2. HandBrake.

Thursday, August 10, 2017

SubMerge - Learn Language by Merging Subtitles

Create Daily Backup - Using Windows Tasks

In this lesson we are going to learn how can we create automatic backups for our files, specially those files that change on daily basis.


  1. Install WinRar in your machine.

    it provides a command line tool (rar.exe) in which we can compress files from the Command Line Prompt.
  2. Open a new empty text file [via notepad], and save it with extension (.bat) on your disk.
  3. Fill the file with the following command.
    [rar.exe location] a -ep1 -r [Compressed File Location] [Your Project Folder]
    1. As Example, suppose I have a project on my local machine at [C:\MyProject], and I want to write the command above, of course I will add the date attached to my project name to make sure it has a unique name, then the command would be like:
       "C:\Program Files\WinRAR\Rar.exe" a -ep1 -r MyProject_%date:~-4%%date:~4,2%%date:~7,2%_0%time:~1,1%%time:~3,2%%time:~6,2%.rar "C:\MyProject"
  4. Open Windows Task Scheduler
     

  5.  Click on "Create Basic Task..." from the right upper menu

Monday, December 1, 2014

Reading Comprehension : Going to a Concert Part 1

Going to a Concert Part 1

I heard on the radio this morning that my favorite band was going to be in concert here next month. I was so excited. The first thing I did was to call my friend Ben who is also a big fan of the band. Not only was the band playing in town, they were going to play at a bar called the Whiskey. The Whiskey is known as a small, intimate venue so we’d be able to get close to the band. It's not a big amphitheater where you can't even see the band from the nosebleed section. This would be the ultimate concert experience if only we can get tickets.
  • band: a group of musicians, especially a group that plays popular music.
    • the band was playing old beatles songs.
    • I joined the band 5 years ago.
  • concert: a performance given by musicians or singers.
    • a rock concert.
    • a concert of french choral music.
  • venue: a place where an organized meeting or concert takes place.
    • the first thing to do is book a venue.
    • the band will play (to perform) as many venues as possible.
  • amphitheater: a large circular building with no roof and with many rows of seats.
  • nosebleed: if you have a nosebleed, blood starts flowing from your nose. BUT here it means Seats in a theater, usually for a live show of some sort, that are so high and far away from the stage that you get a "nosebleed" from the high altitude.
  • ultimate: the main and the most important.
    • complete disarmament was the ultimate goal of the conference.

I was sure that the tickets would sell out fast when they went on sale on Saturday morning. So, Ben and I decided to camp out in front of the box office on Friday night. That way, when the box office opened on Saturday morning, we would definitely get tickets. We grabbed a bite to eat on Friday night, then we got dressed in our warmest clothes and took our sleeping bags to the ticket office. This was around 8pm. When we got there, I couldn't believe it! There were already about 15 people in line! And, I was sure we'd be the first ones. Oh well.
  • to sell out: if a shop sells out of something, it sells all it has that there is no available.
    • I went to get some bread. but the shop had sold out.  
    • In a hot day, we can sell out all of icecream in one hour.
  • went on sale: when something is on sale, then it is available for people to buy it.
    • [go on sale price] for people available at a price that is less than the usual (normal) price
    • [on sale] tickets for the performance are on sale at the post office.
  • camp out: to sleep outdoors, usually in a tent.
    • what he liked best about scouting was camping out.
  • box office: the place in a theatre, or cinema where tickets are sold.
    • collect  your tickets at the post office.
  • grab a bite to eat: to get something to eat, or to get food that can be eaten quickly.
    • I need a few minutes to grab a bite to eat. I am always trying to get a bite between meetings.

Saturday, September 27, 2014

Reading Comprehension : StereoTypes

A stereotype is a fixed idea that people have about what specific social groups or individuals are like, especially an idea that is wrong. Other terms that are associated with the term stereotype are prejudice and cliche. The term has a Greek origin: stereos means solid or firm and typos mean blow, impression, engraved or mark. The term was first used in the printing business. The first modern English use of the term was in 1850, meaning "image perpetuated without change."
  1. Stereotype: a belief or idea of what a particular type of person or thing is like.
  2. Prejudice:an unseasonable dislike and distrust of people who are different from you in some way, specially because of their race, sex, religion, etc...
  3. Cliche:a phrase or opinion that is overused and betrays a lack of original thought.
  4. Firm:a business concern, especially one involving a partnership of two or more people.
  5. Blow:an action or event that causes difficulty or sadness for someone
  6. Engraved:to carve (cut) words or designs on metal, wood, glasses, etc...
  7. Perpetuated: make something continue to exist for a long time.
Because stereotypes are standardized and simplified ideas of groups, based on some prejudices, they are not derived from objective facts, but rather subjective and often unverifiable ideas. As Sociologist Charles E. Hurst states* "One reason for stereotypes is the lack of personal, concrete familiarity that individuals have with persons in other racial or ethnic groups. Lack of familiarity encourages the lumping together of unknown individuals".
  • lumping : a small piece of something solid.
The existence of stereotypes may be explained by the need of groups of people to view themselves as more normal or more superior than other groups. Consequently, stereotypes may be used to justify ill-founded prejudices or ignorance and prevent people of stereotyped groups from entering or succeeding in various activities or fields. The stereotyping group is, generally, reluctant to reconsider their attitudes and behavior towards stereotyped group.
  • consequently: as a result (SYN: therefore)
  • reluctant: unwilling or hesitant.