28 January 2015

Parse News RSS 2.0 image in C#

If you want to parse News RSS 2.0 image from link, for example > http://codecanyon.net/page/file_updates/#rss

The following code can be used to match all img src in the source text and to populate list with value of src attribute.

private static IEnumerable<string> GetImagesInHTMLString(string htmlString)
        {
            var images = new List<string>();
            const string pattern = Imgpattern;
            var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection matches = rgx.Matches(htmlString);

            for (int i = 0, l = matches.Count; i < l; i++)
            {
                if (matches[i].Value.Contains(".jpg") || matches[i].Value.Contains(".png"))
                {
                    var ms = Regex.Matches(matches[i].Value, Urlpattern);
                    if (ms.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(ms[0].Value))
                            images.Add(ms[0].Value.Replace("\"", string.Empty));
                    }
                }
            }

            return images;
        }

Decompiled C# Library : AppStudio.Common.dll

Wonderfull Microsoft Windows AppStudio on adress http://appstudio.windows.com generate Universal Applications for Windows Phone and Windows Store in C# - online.

Downloaded generated source code use closed library AppStudio.Common.dll, which breaks further portability.

Fortunately, the only items being used from this library are the BindableBase, BindableSchemaBase, and IDataSource. 

So I recreated these files in the directly, removing the AppStudio.Common.dll reference entirely from both the  Windows projects.

Here’s the code for the BindableBase:

using System;
using System.Collectionus.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace SoftLabPro.Data
{ public abstract class BindableBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected BindableBase()
    {
    }
    public virtual void Initialize(IDictionary<string, string> parameters)
    {
    }
    protected void OnPropertyChanged(string propertyName = null)
    {
        PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if (propertyChanged != null)
        {
            try
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
            catch
            {
            }
        }
    }
    protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
    {
        if (object.Equals((T)storage, value))
        {
            return false;
        }
        storage = value;
        this.OnPropertyChanged(propertyName);
        return true;
    }
}
}

Here is BindableSchemaBase:

using System;
using System.Runtime.CompilerServices;
using System.Text;

namespace SoftLabPro.Data
{ public abstract class BindableSchemaBase : BindableBase
{
    public BindableSchemaBase()
    {
        this.Id = Guid.NewGuid().ToString();
    }
    public abstract string GetValue(string propertyName);
    public virtual string GetValues(params string[] propertyNames)
    {
        StringBuilder builder = new StringBuilder();
        foreach (string str in propertyNames)
        {
            builder.AppendLine((this.GetValue(str) ?? string.Empty).ToString());
        }
        return builder.ToString();
    }
    public abstract string DefaultContent { get; }
    public abstract string DefaultImageUrl { get; }
    public abstract string DefaultSummary { get; }
    public abstract string DefaultTitle { get; }
    public string Id { get; set; }
}
}


And finally IDataSource:

using System.Collections.Generic;

using System.Threading.Tasks;

namespace SoftLabPro.Data

{
    public interface IDataSource<T> where T : BindableSchemaBase

{
    Task<IEnumerable<T>> LoadData();
    Task<IEnumerable<T>> Refresh();
}

}

27 January 2015

Parse Google News RSS image in C#

If you want to parse Google News RSS image from link, for example > http://news.google.com/news?hl=us&q=android&output=rss

The following code can be used to match all img src in the source text and to populate list with value of src attribute.

private static IEnumerable<string> GetImagesInGoogleNewsString(string htmlString)
        {
            List<string> imgSrcs = new List<string>();
            //const string pattern = Imgpattern;
            //var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            var imgSrcMatches = System.Text.RegularExpressions.Regex.Matches(htmlString, string.Format(@"<\s*img\s*src\s*=\s*{0}\s*([^{0}]+)\s*{0}", "\""),
               RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | 
               RegexOptions.Multiline);

            foreach (Match match in imgSrcMatches)
                imgSrcs.Add("http:" + match.Groups[1].Value);

            return imgSrcs;
        }

16 January 2015

Android Splash Screen sizes

For drawable resolutions I found these most suitable :


Density

Resolution

Format

Color

ldpi

240x320

png

24bit

mdpi

320x480

png

24bit

hdpi

480x800

png

24bit

xdpi

720x1280

png

24bit

xxdpi

1080x1920

png

24bit

xxxdpi

?







05 January 2015

Making money with Android

Follow one developer's journey to making an income from Android apps. The goal: $1000 a month. 

23 September 2014

How To Recreate the Birthday and Anniversary reminders in the Outlook Calendar

Here is how to recreate the Birthday and Anniversary reminders in the Outlook Calendar. Put this macro code in Outlook MVA Editor (Alt-F11) and run.

Sub olRobot()
' Outlook VBA script by Sergii Vakula
' Auto generation the Birthdays and Anniversaries appointments of all Contact folders to a specific calendar
' Auto changing Contact's FileAs fields: FullName for humans, CompanyName for companies

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objItems As Outlook.Items
Dim obj As Object
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")

On Error Resume Next

' *****************************************************************************************************
' *** STAGE 1: Rebuilding Contact's Birthdays and Anniversaries to the main calendar, fixing FileAs ***
' *****************************************************************************************************

Dim Report As String
Dim mySession As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Set mySession = Application.Session

' Method 1: Ask for Contact folder
'MsgBox ("Select Contact folder by next step...")
'Call ContactsFolders(Session.PickFolder, Report)

' Method 2: Use default Contact folder and all subfolders
'Call ContactsFolders(objNS.GetDefaultFolder(olFolderContacts), Report)

' Method 3: Use all Contact folders
For Each myFolder In mySession.Folders
Call ContactsFolders(myFolder, Report)
Next

' ***************************************************************************************
' *** STAGE 2: Moving Birthdays and Anniversaries appointments to a specific calendar ***
' ***************************************************************************************

Dim objCalendar As Outlook.AppointmentItem
Dim objCalendarFolder As Outlook.MAPIFolder
Dim cAppt As AppointmentItem
Dim moveCal As AppointmentItem
Dim pattern As RecurrencePattern
Set objCalendarFolder = objNS.GetDefaultFolder(olFolderCalendar)
bodyMessage = "This is autocreated appointment"

' Method 1: Ask for specific calendar folder for birthdays and anniversaries
'MsgBox ("Select Birthdays and Anniversaries Calendar folder by next step...")
'Set newCalFolder = Session.PickFolder

' Method 2: Use pre-assigned calendar folder for birthdays and anniversaries
'Set newCalFolder = GetFolderPath("display name in folder listCalendarBirthdays and Anniversaries")
Set newCalFolder = GetFolderPath("\sv@pbxsphere.comCalendarBirthdays and Anniversaries")

For i = newCalFolder.Items.Count To 1 Step -1
Set obj = newCalFolder.Items(i)
If obj.Class = olAppointment And _
obj.GetRecurrencePattern.RecurrenceType = olRecursYearly And _
obj.AllDayEvent And _
obj.Body = bodyMessage Then
Set objCalendar = obj
objCalendar.Delete
End If
Err.Clear
Next

For i = objCalendarFolder.Items.Count To 1 Step -1
Set obj = objCalendarFolder.Items(i)
If obj.Class = olAppointment And _
obj.GetRecurrencePattern.RecurrenceType = olRecursYearly And _
obj.AllDayEvent And _
(Right(obj.Subject, 11) = "'s Birthday" Or Right(obj.Subject, 14) = "'s Anniversary" Or _
Right(obj.Subject, 13) = "???? ????????" Or Right(obj.Subject, 9) = "?????????") Then

Set objCalendar = obj
Set cAppt = Application.CreateItem(olAppointmentItem)

With cAppt
.Subject = objCalendar.Subject
.Start = objCalendar.Start
.Duration = objCalendar.Duration
.AllDayEvent = True
.Body = bodyMessage
.ReminderSet = False
.BusyStatus = olFree
End With

Set pattern = cAppt.GetRecurrencePattern
pattern.RecurrenceType = olRecursYearly
cAppt.Save

objCalendar.Delete

Set moveCal = cAppt.Move(newCalFolder)
'moveCal.Categories = "moved"
moveCal.Save

End If
Err.Clear
Next

Set objOL = Nothing
Set objNS = Nothing
Set obj = Nothing
Set objContact = Nothing
Set objItems = Nothing
Set objCalendar = Nothing
Set objCalendarFolder = Nothing
Set cAppt = Nothing
Set moveCal = Nothing
Set pattern = Nothing
Set mySession = Nothing
Set myFolder = Nothing

MsgBox ("Completed!" & vbCrLf & vbCrLf & "All Contact's FileAs were fixed." & vbCrLf & "All Birthdays and Anniversaries appointments were re-created." & vbCrLf & vbCrLf & "Contact folders that been processed:" & vbCrLf & Report & vbCrLf & "Calendar for Birhdays and Anniversaries:" & vbCrLf & newCalFolder.FolderPath & vbCrLf & vbCrLf & "Have a nice day!")

End Sub

Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
FoldersArray = Split(FolderPath, "")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function

Private Sub ContactsFolders(CurrentFolder As Outlook.Folder, Report As String)
Dim objItems As Outlook.Items
Dim obj As Object
Dim objContact As Outlook.ContactItem
Dim strFileAs As String
Dim SubFolder As Outlook.Folder
Dim SubFolders As Outlook.Folders
Set SubFolders = CurrentFolder.Folders
If CurrentFolder.DefaultItemType = 2 Then
Report = Report & CurrentFolder.FolderPath & vbCrLf
Set objItems = CurrentFolder.Items
For Each obj In objItems
If obj.Class = olContact Then
Set objContact = obj

With objContact
.Display

If .FullName = "" Then
strFileAs = .CompanyName
Else
strFileAs = .FullName
End If

.FileAs = strFileAs

mybirthday = .Birthday
myanniversary = .Anniversary
.Birthday = Now
.Anniversary = Now
.Birthday = mybirthday
.Anniversary = myanniversary

.Save
.Close 0
End With

End If
Err.Clear
Next

End If

For Each SubFolder In SubFolders
Call ContactsFolders(SubFolder, Report)
Next

Set SubFolder = Nothing
Set SubFolders = Nothing

End Sub


07 September 2014

29 July 2014

How to disable Frame Rate Counter in Windows 8 Applications

To disable Frame Rate Counter in Windows 8 Applications there should enter next line in MainPage.xaml.cs on public MainPage() method :

public MainPage()
        {
            this.InitializeComponent();
            Application.Current.DebugSettings.EnableFrameRateCounter = false;
         }


23 July 2014

Windows Phone 8 and SQLite deploy to device error

On the Build tab, you’ll see Conditional compilation symbols under the General header, containing a default value of SILVERLIGHT;WINDOWS_PHONE on a Windows Phone app project. Change the value to SILVERLIGHT;WINDOWS_PHONE;USE_WP8_NATIVE_SQLITE and save the project file.

22 April 2014

MS Windows 8.1 : Add shortcut to This PC Explorer sidebar

I'm going to share a very small and easy trick which can be used to add any desired shortcut, file or folder in This PC Explorer sidebar in MS Windows 8.1.

Type following string in RUN (Win+R) or start menu search box and press Enter:
%AppData%\Microsoft\Windows\Network Shortcuts
It'll open "Network Shortcuts" folder.
You can also directly open the same folder by typing Network Shortcuts in Explorer addressbar and press Enter.
Now what you have to do is simply create shortcut to the desired folder and PASTE it in this "Network Shortcuts" folder. You can also paste file shortcuts or simply move the original file in this folder.