Category Archives: Solution

Filter WPF TreeView using ICollectionView in MVVM Pattern

Background:

A customer achieved a WPF TreeView with HierarchicalDataTemplate, there have a group of CheckBoxs (Green, Yellow & Red) and being checked:
treeview1

We can see that each item has a Circle with different color(Green, Yellow & Red). Now, he needs to accomplish filtering the TreeViewItem by color when check/uncheck CheckBox controls.

Reference:

In the above article, author used the ICollectionView interface to filter multiple level. This interface gives us the flexibility to Filter a collection even without touching the contents of the data source.

Implementation:

This project has two Models->

Class Model:

public class Class
{
         private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string imagePath;

        public string ImagePath
        {
            get { return imagePath; }
            set { imagePath = value; }
        }

        private ObservableCollection<Student> students;

        public ObservableCollection<Student> Students
        {
            get
            {
                if (students == null)
                {
                    students = new ObservableCollection<Student>();
                }

                return students;
            }
            set { students = value; }
        }

        public Class()
        { 

        }

        public Class(string name)
        {
            this.name = name;
        }

        public Class(string name, string imagePath)
        {
            this.name = name;
            this.imagePath = imagePath;
        }
}

Student Model:

public class Student
{
         private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string imagePath;

        public string ImagePath
        {
            get { return imagePath; }
            set { imagePath = value; }
        }

        private string toolTip;

        public string ToolTip
        {
            get { return toolTip; }
            set { toolTip = value; }
        }

        public Student()
        {

        }

        public Student(string name, string imagePath)
        {
            this.name = name;
            this.toolTip = name;
            this.imagePath = imagePath;
        }
}

To trigger the filtering function, we need to have three properties in ViewModel: IsDisplayGreen, IsDisplayRed and IsDisplayYellow. These three Properties are bound to the IsChecked property of the CheckBox.

<CheckBox Content="Green" Margin="2" IsChecked="{Binding Path=IsDisplayGreen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Content="Yellow" Margin="2" IsChecked="{Binding Path=IsDisplayYellow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            <CheckBox Content="Red" Margin="2" IsChecked="{Binding Path=IsDisplayRed, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

The filtering implementation:

private void FilterFunction()
{
            ICollectionView classesDataSourceView =
                    CollectionViewSource.GetDefaultView(ClassList);
                classesDataSourceView.Filter = (classModel =>
                {
                    ICollectionView studentsDataSourceView =
                        CollectionViewSource.GetDefaultView(
                            ((Class)classModel).Students);

                    if (_isDisplayGreen == false && _isDisplayYellow == false && _isDisplayRed==false)
                        studentsDataSourceView.Filter =
                        (studentModel =>false);
                    if (_isDisplayGreen == true && _isDisplayYellow == true && _isDisplayRed == true)
                        studentsDataSourceView.Filter =
                        (studentModel => true);

                    if (_isDisplayGreen == false && _isDisplayYellow == true && _isDisplayRed == false)
                        studentsDataSourceView.Filter =
                        (studentModel =>
                            ((Student)studentModel).ImagePath.
                                               Equals("../Images/Yellow-icon.png"));
                    if (_isDisplayGreen == true && _isDisplayYellow == false && _isDisplayRed == false)
                        studentsDataSourceView.Filter =
                        (studentModel =>
                            ((Student)studentModel).ImagePath.
                                               Equals("../Images/Green-icon.png"));
                    if (_isDisplayGreen == false && _isDisplayYellow == false && _isDisplayRed == true)
                        studentsDataSourceView.Filter =
                        (studentModel =>
                            ((Student)studentModel).ImagePath.
                                               Equals("../Images/Red-icon.png"));
                    if (_isDisplayGreen == true && _isDisplayYellow == false && _isDisplayRed == true)
                        studentsDataSourceView.Filter =
                        (studentModel =>
                            ((Student)studentModel).ImagePath.
                                               Equals("../Images/Red-icon.png") 
                                               || ((Student)studentModel).ImagePath.
                                               Equals("../Images/Green-icon.png"));
                    if (_isDisplayGreen == false && _isDisplayYellow == true && _isDisplayRed == true)
                        studentsDataSourceView.Filter =
                        (studentModel =>
                            ((Student)studentModel).ImagePath.
                                               Equals("../Images/Red-icon.png")
                                               || ((Student)studentModel).ImagePath.
                                               Equals("../Images/Yellow-icon.png"));
                    if (_isDisplayGreen == true && _isDisplayYellow == true && _isDisplayRed == false)
                        studentsDataSourceView.Filter =
                        (studentModel =>
                            ((Student)studentModel).ImagePath.
                                               Equals("../Images/Yellow-icon.png")
                                               || ((Student)studentModel).ImagePath.
                                               Equals("../Images/Green-icon.png"));

                    return !studentsDataSourceView.IsEmpty;
                });
}

Properties:

private bool _isDisplayGreen = true;
private bool _isDisplayRed = true;
private bool _isDisplayYellow = true;

public bool IsDisplayGreen
{
            get { return _isDisplayGreen; }
            set
            {
                _isDisplayGreen = value;
                FilterFunction();
                OnPropertyChanged("IsDisplayRed");
                OnPropertyChanged("IsDisplayGreen");
                OnPropertyChanged("IsDisplayYellow");
            }
}

public bool IsDisplayRed
{
            get { return _isDisplayRed; }
            set
            {
                _isDisplayRed = value;
                FilterFunction();
                OnPropertyChanged("IsDisplayRed");
                OnPropertyChanged("IsDisplayGreen");
                OnPropertyChanged("IsDisplayYellow");
            }
}

public bool IsDisplayYellow
{
            get { return _isDisplayYellow; }
            set
            {
                _isDisplayYellow = value;
                FilterFunction();
                OnPropertyChanged("IsDisplayRed");
                OnPropertyChanged("IsDisplayGreen");
                OnPropertyChanged("IsDisplayYellow");
            }
}

Of course, the ViewModel need to be inherited from PropertyChangedBase class:

public class PropertyChangedBase : INotifyPropertyChanged
{
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                handler(this, e);
            }
        }
}

Screenshot:
WpfTVHierarchicalDataTemplateFilter

Download Sample: WpfTVHierarchicalDataTemplateFilter

How to accomplish Drag and Drop WPF TreeViewItem

Someone wants to accomplish drag and drop TreeViewItem in the WPF application, the data is loaded from a XML file and save back to it.

Firstly, we need to accomplish the first requirement-loading data from xaml file and display them in the WPF TreeView control.

XML file:

<?xml version="1.0" encoding="utf-8"?>
<Collection>
  <item Name="Jimmy">
    <Name>Jimmy Chen</Name>
    <Age>25</Age>
    <Gender>Male</Gender>
    <Icon>jimmy.png</Icon>
  </item>
  <item Name="James">
    <Name>James Hoffman</Name>
    <Age>23</Age>
    <Gender>Male</Gender>
    <Icon>james.png</Icon>
  </item>
  <item Name="Franklin">
    <Name>Franklin Chen</Name>
    <Age>22</Age>
    <Gender>Male</Gender>
    <Icon>franklin.png</Icon>
  </item>
</Collection>

Now, we need to load XML data to a ObservableCollection<T> instance:
Family & FamilyMember class:

public class Family : INotifyPropertyChanged
{
        public Family()
        {
            this.Children = new ObservableCollection<FamilyMember>();
        }
        private int _myage;

        public int myAge
        {
            get { return _myage; }
            set
            {
                if (_myage != value)
                {
                    _myage = value;
                    OnPropertyChanged("Age");
                }
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;


        protected void OnPropertyChanged(string p_strPropertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p_strPropertyName));
        }
        public string myName { get; set; }
        public string myGender { get; set; }
        public string myImg { get; set; }

        public ObservableCollection<FamilyMember> Children { get; set; }
}

public class FamilyMember
{
        public string Name { get; set; }
        public string Age { get; set; }
        public string Img { get; set; }
}

Loading Data:

public ObservableCollection<Family> MyData { get; set; }

public MainWindow()
{
            InitializeComponent();

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(System.IO.Directory.GetCurrentDirectory() + "//FamilyBook.xml");
            XmlNodeList nodeName = xmlDoc.GetElementsByTagName("Name");
            XmlNodeList nodeGender = xmlDoc.GetElementsByTagName("Gender");
            XmlNodeList nodeAge = xmlDoc.GetElementsByTagName("Age");
            XmlNodeList nodeImg = xmlDoc.GetElementsByTagName("Icon");
            XmlNodeList elemList = xmlDoc.GetElementsByTagName("item");
            MyData = new ObservableCollection<Family>();
            for (int i = 0; i < elemList.Count; i++)
            {
                MyData.Add(new Family()
                {
                    myName = nodeName[i].InnerText,
                    myGender = nodeGender[i].InnerText,
                    myAge = Convert.ToInt32(nodeAge[i].InnerText),

                    myImg = System.IO.Directory.GetCurrentDirectory() + "/favicon/" + nodeImg[i].InnerText

                });
            }

            this.DataContext = this;
}

To display data in WPF TreeView, we need to write HierarchicalDataTemplate and DataTemplate:

<TreeView HorizontalAlignment="Left" ItemsSource="{Binding MyData}"  x:Name="trvFamilies"  Background="{x:Null}" >
            <TreeView.Resources>

                <HierarchicalDataTemplate DataType="{x:Type local:Family}"  ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding myImg }" Margin="5,0,5,0" Height="18" Width="18" ></Image>
                        <TextBlock Text="{Binding Path=myName}" Width="167" Padding="0,3,0,0"   TextTrimming="CharacterEllipsis" ></TextBlock>
                        <Label Content="{Binding myAge}" Foreground="#FF515151" Width="39"  HorizontalContentAlignment="Right" Margin="0,0,12,0"></Label>

                    </StackPanel>
                </HierarchicalDataTemplate>
                <DataTemplate DataType="{x:Type local:FamilyMember}"  >
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding Img}" Margin="21,0,5,0" Height="18" Width="18" />
                        <TextBlock  x:Name="surl" Text="{Binding Name}" Width="158" TextTrimming="CharacterEllipsis" Padding="0,3,0,0"     />

                        <Label Content="{Binding Age}" Foreground="#FF515151"  Width="30"   HorizontalContentAlignment="Right"  Margin="0,0,12,0"/>

                    </StackPanel>
                </DataTemplate>
            </TreeView.Resources>
        </TreeView>

So far, the UI should be like this:
2014-09-02_210033

Now, we need to accomplish the most difficult part: Drag and drop TreeViewItem.

Anyway, here is an article on MSDN to talk about Drag and Drop Overview: http://msdn.microsoft.com/en-us/library/ms742859(v=vs.110).aspx

We need to set TreeView’s AllowDrop property to True first and handle the following events:

int flag = 0;
Point startPoint;
private void TV_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
            if (e.OriginalSource is TextBlock)
            {
                // Store the mouse position
                startPoint = e.GetPosition(null);
                flag = 1;
            }
}

private void trvFamilies_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
            flag = 0;
}

private void TV_MouseMove(object sender, MouseEventArgs e)
{
            if (flag == 1) //Begin Drag
            {
                // Get the current mouse position
                Point mousePos = e.GetPosition(null);
                Vector diff = startPoint - mousePos;

                if (e.LeftButton == MouseButtonState.Pressed &&
                    Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    // Get the dragged ListViewItem
                    TreeView treeView = sender as TreeView;
                    TreeViewItem treeViewItem =
                        FindAnchestor<TreeViewItem>((DependencyObject)e.OriginalSource);
                    if (treeViewItem != null)
                    {
                        // Find the data behind the ListViewItem
                        Family contact = (Family)treeView.ItemContainerGenerator.ItemFromContainer(treeViewItem);

                        // Initialize the drag & drop operation
                        DataObject dragData = new DataObject("myFormat", contact);
                        DragDrop.DoDragDrop(treeViewItem, dragData, DragDropEffects.Move);
                    }
                }
            }
}

// Helper to search up the VisualTree
private static T FindAnchestor<T>(DependencyObject current)
            where T : DependencyObject
{
            do
            {
                if (current is T)
                {
                    return (T)current;
                }
                current = VisualTreeHelper.GetParent(current);
            }
            while (current != null);
            return null;
}

private void FindDropTarget(TreeView tv, out TreeViewItem pItemNode, DragEventArgs pDragEventArgs)
{
            pItemNode = null;

            DependencyObject k = VisualTreeHelper.HitTest(tv, pDragEventArgs.GetPosition(tv)).VisualHit;

            while (k != null)
            {
                if (k is TreeViewItem)
                {
                    TreeViewItem treeNode = k as TreeViewItem;
                    if (treeNode.DataContext is Family)
                    {
                        pItemNode = treeNode;
                    }
                }
                else if (k == tv)
                {
                    Console.WriteLine("Found treeview instance");
                    return;
                }

                k = VisualTreeHelper.GetParent(k);
            }
}

private void trvFamilies_PreviewDragEnter(object sender, DragEventArgs e)
{
            if (!e.Data.GetDataPresent("myFormat") || sender == e.Source)
            {
                e.Effects = DragDropEffects.None;
            }
}

private void trvFamilies_PreviewDrop(object sender, DragEventArgs e)
{
            if (e.Data.GetDataPresent("myFormat"))
            {
                TreeViewItem itemNode;
                FindDropTarget((TreeView)sender, out itemNode, e);
                Family dropItem = (itemNode != null && itemNode.IsVisible ? itemNode.DataContext as Family : null);
                Family dragItem = e.Data.GetData("myFormat") as Family;
                if (dropItem != null)
                {
                    TreeView treeView = sender as TreeView;
                    Console.WriteLine("Index: " + (MyData.IndexOf(dropItem) + 1).ToString());
                    MyData.Remove(dragItem);
                    //MyData.Insert(MyData.IndexOf(dropItem) + 1, dragItem);
                    MyData.Insert(MyData.IndexOf(dropItem) >= 1 ? MyData.IndexOf(dropItem) : 0, dragItem);
                }
                flag = 0;//Release Drag Operation
            }
}

Screenshot(gif):
WpfTVDragDrop

Download Sample: WpfTVDragDrop

Desktop Application: Stack Exchange API – OAuth 2.0

Recently, we need to integrate Stack Exchange authentication to our Desktop Application. To obtain Access Token, someone tried to send web request to the specified url with parameters, but this didn’t work.

Ref to Stack Exchange API Authentication Document:

Desktop Applications

Desktop applications cannot participate directly in OAuth 2.0 flows, however the embeddable browser controls available in most frameworks make it possible to work around this limitation.

Desktop applications should use the implicit client-side flow, hosting the process within a browser control. For redirect_uri, a value of https://stackexchange.com/oauth/login_success should be used. Upon a successful authentication, access_token will be placed in the url hash as with a standard implicit authentication.

What’s the implicit client-side flow:

1. Open a new window at https://stackexchange.com/oauth/dialog, with these query string parameters

  • client_id
  • scope (details)
  • redirect_uri – must be under an apps registered domain
  • state – optional

2. The user approves your app
3. The user is redirected to redirect_uri, with these parameters in the hash

  • access_token
  • expires – optional, only if scope doesn’t contain no_expiry

After understanding the above flow, we’ll step through the flow with examples.

Firstly, we need to register for an app key: http://stackapps.com/apps/oauth/register

Secondly, by using the Client Id generated in the above step, the url with parameters will be like this:

https://stackexchange.com/oauth/dialog?client_id=<Your ClientID>&scope=no_expiry&redirect_uri=https://stackexchange.com/oauth/login_success

In this step, we could create a new window with WebBrowser control and navigate to the above url, but the default IE version was not the same as my OS(Win8.1 IE11), so I created a method to Fix this issue, used the FEATURE_BROWSER_EMULATION feature: http://msdn.microsoft.com/en-us/library/ie/ee330730(v=vs.85).aspx

private void IEbrowserFix()
{
            try
            {
                Microsoft.Win32.RegistryKey regDM = Registry.CurrentUser;
                string KeyPath = "SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION";

                regDM = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(KeyPath, false);
                if (regDM == null)
                {
                    regDM = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(KeyPath);
                }

                object Sleutel = null;
                if ((regDM != null))
                {
                    string location = System.Environment.GetCommandLineArgs()[0];
                    string appName = System.IO.Path.GetFileName(location);

                    Sleutel = regDM.GetValue(appName);
                    if (Sleutel == null)
                    {
                        //Sleutel onbekend
                        regDM = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(KeyPath, true);
                        Sleutel = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(KeyPath, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);

                        //What OS are we using
                        Version OsVersion = System.Environment.OSVersion.Version;

                        if (OsVersion.Major == 6 & OsVersion.Minor == 1)
                        {
                            //WIN 7
                            ((RegistryKey)Sleutel).SetValue(appName, 9000, Microsoft.Win32.RegistryValueKind.DWord);
                        }
                        else if (OsVersion.Major == 6 & OsVersion.Minor == 2)
                        {
                            //WIN 8
                            ((RegistryKey)Sleutel).SetValue(appName, 10000, Microsoft.Win32.RegistryValueKind.DWord);
                        }
                        else if (OsVersion.Major == 6 & OsVersion.Minor == 3)
                        {
                            <strong>//WIN 8.1</strong>
<strong>                            ((RegistryKey)Sleutel).SetValue(appName, 11001, Microsoft.Win32.RegistryValueKind.DWord);</strong>
                        }
                        else if (OsVersion.Major == 5 & OsVersion.Minor == 1)
                        {
                            //WIN xp
                            ((RegistryKey)Sleutel).SetValue(appName, 8000, Microsoft.Win32.RegistryValueKind.DWord);
                        }

                        ((RegistryKey)Sleutel).Close();
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
}

RedirectForm.cs:

public partial class RedirectForm : Form
{
        public RedirectForm()
        {
            InitializeComponent();
        }
        public string Token
        {
            get;
            set;
        }

        public RedirectForm(string url)
        {
            InitializeComponent();

            webBrowser1.Navigate(url);
        }

        private void RedirectForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            NameValueCollection urlParameters = HttpUtility.ParseQueryString(webBrowser1.Url.ToString());

            // extract the access token from the url.
            string accessToken = urlParameters["https://stackexchange.com/oauth/login_success#access_token"];
            if(accessToken!=null)
            {
                //MessageBox.Show(accessToken);
                this.Token = accessToken;
            }
        }

        private void IEbrowserFix()
        {
            //...Omitted...
        }

        private void RedirectForm_Load(object sender, EventArgs e)
        {
            IEbrowserFix();
        }
}

MainFrom.cs:

private void button1_Click(object sender, EventArgs e)
{
            string url2 = "https://stackexchange.com/oauth/dialog?client_id="+txtClientID.Text+"&scope=no_expiry&redirect_uri=https://stackexchange.com/oauth/login_success";

            using( RedirectForm rf =new RedirectForm(url2))
            {
                DialogResult result=rf.ShowDialog();
                if(result == DialogResult.Cancel)
                {
                    txtToken.Text = rf.Token;
                }
            }
}

Screenshot:

Auth1

Obtained Access Token:

Auth2

Pro*C 环境配置(RedHat +Oracle 10g)


Redhat+Oracle 10g环境搭建完毕后,终端中输入命令 proc
如果有如下错误提示:

[oracle@oracleserver ~]$ proc
proc: error while loading shared libraries: libclntsh.so.10.1: cannot open shared object file: No such file or directory

可以直接在用户配置文件 .bash_profile 中添加:

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

输入以下命令生效:

source .bash_profile

———————————————————-
编译.pc程序文件时,如果提示这样的错误:

Pro*C/C++: Release 10.2.0.1.0 - Production on Tue May 21 15:50:48 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

System default option values taken from: /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg

Error at line 34, column 11 in file /usr/include/stdio.h
# include 
..........1
PCC-S-02015, unable to open include file
Error at line 31, column 10 in file /usr/include/bits/types.h
#include 
.........1
PCC-S-02015, unable to open include file
Error at line 14, column 10 in file /usr/include/_G_config.h
#include 
.........1
PCC-S-02015, unable to open include file
Error at line 48, column 10 in file /usr/include/wchar.h
#include 
.........1
PCC-S-02015, unable to open include file
Error at line 48, column 10 in file /usr/include/wchar.h
#include 
.........1
PCC-S-02015, unable to open include file
Error at line 31, column 10 in file /usr/include/gconv.h
#include 
.........1
PCC-S-02015, unable to open include file
Syntax error at line 72, column 26, file /usr/include/gconv.h:
Error at line 72, column 26 in file /usr/include/gconv.h
                            unsigned char **, size_t *, int, int);
.........................1
PCC-S-02201, Encountered the symbol "size_t" when expecting one of the following
:

   ... auto, char, const, double, enum, float, int, long,
   ulong_varchar, OCIBFileLocator OCIBlobLocator,
   OCIClobLocator, OCIDateTime, OCIExtProcContext, OCIInterval,
   OCIRowid, OCIDate, OCINumber, OCIRaw, OCIString, register,
   short, signed, sql_context, sql_cursor, static, struct,
   union, unsigned, utext, uvarchar, varchar, void, volatile,
   a typedef name, exec oracle, exec oracle begin, exec,
   exec sql, exec sql begin, exec sql type, exec sql var,
The symbol "enum," was substituted for "size_t" to continue.

Syntax error at line 88, column 7, file /usr/include/gconv.h:
Error at line 88, column 7 in file /usr/include/gconv.h
                                  size_t *);
......1
PCC-S-02201, Encountered the symbol "size_t" when expecting one of the following
:

   ... auto, char, const, double, enum, float, int, long,
   ulong_varchar, OCIBFileLocator OCIBlobLocator,
   OCIClobLocator, OCIDateTime, OCIExtProcContext, OCIInterval,
   OCIRowid, OCIDate, OCINumber, OCIRaw, OCIString, register,
   short, signed, sql_context, sql_cursor, static, struct,
   union, unsigned, utext, uvarchar, varchar, void, volatile,
   a typedef name, exec oracle, exec oracle begin, exec,
   exec sql, exec sql begin, exec sql type, exec sql var,
The symbol "enum," was substituted for "size_t" to continue.

Syntax error at line 97, column 6, file /usr/include/gconv.h:
Error at line 97, column 6 in file /usr/include/gconv.h
                                        size_t *);
.....1
PCC-S-02201, Encountered the symbol "size_t" when expecting one of the following
:

   ... auto, char, const, double, enum, float, int, long,
   ulong_varchar, OCIBFileLocator OCIBlobLocator,
   OCIClobLocator, OCIDateTime, OCIExtProcContext, OCIInterval,
   OCIRowid, OCIDate, OCINumber, OCIRaw, OCIString, register,
   short, signed, sql_context, sql_cursor, static, struct,
   union, unsigned, utext, uvarchar, varchar, void, volatile,
   a typedef name, exec oracle, exec oracle begin, exec,
   exec sql, exec sql begin, exec sql type, exec sql var,
The symbol "enum," was substituted for "size_t" to continue.

Syntax error at line 106, column 3, file /usr/include/gconv.h:
Error at line 106, column 3 in file /usr/include/gconv.h
  __gconv_trans_fct __trans_fct;
..1
PCC-S-02201, Encountered the symbol "__gconv_trans_fct" when expecting one of th
e following:

   char, const, double, enum, float, int, long, ulong_varchar,
   OCIBFileLocator OCIBlobLocator, OCIClobLocator, OCIDateTime,
   OCIExtProcContext, OCIInterval, OCIRowid, OCIDate, OCINumber,
   OCIRaw, OCIString, short, signed, sql_context, sql_cursor,
   struct, union, unsigned, utext, uvarchar, varchar, void,
   volatile, a typedef name,

Error at line 53, column 11 in file /usr/include/libio.h
# include 
..........1
PCC-S-02015, unable to open include file
Error at line 33, column 10 in file /usr/include/string.h
#include 
.........1
PCC-S-02015, unable to open include file
Syntax error at line 0, column 0, file Desktop/test.pc:
Error at line 0, column 0 in file Desktop/test.pc
PCC-S-02201, Encountered the symbol "" when expecting one of the following:

   ; : an identifier, end-exec, random_terminal

Error at line 0, column 0 in file Desktop/test.pc
PCC-F-02102, Fatal error while doing C preprocessing

说明在 pcscfg.cfg 中系统头文件的位置不正确,需要重新设置:
查看pcscfg.cfg文件:

$[oracle@oracleserver ~]$ cat /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg
sys_include=(/ade/aime_rdbms_9819/oracle/precomp/public,/usr/include,/usr/lib/gcc-lib/i486-suse-linux/2.95.3/include,/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/include,/usr/lib/gcc-lib/i386-redhat-linux7/2.96/include)
ltype=short

查找头文件 stddef.h 位置:

[root@oracleserver ~]# find / -name "stddef.h" -print
/usr/include/xulrunner-sdk-1.9/system_wrappers/stddef.h
/usr/include/linux/stddef.h
/usr/lib/bcc/include/stddef.h
/usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h
/usr/lib/gcc/i386-redhat-linux/4.1.1/include/stddef.h
/usr/lib/syslinux/com32/include/bitsize/stddef.h
/usr/lib/syslinux/com32/include/stddef.h
/usr/src/kernels/2.6.18-194.el5-i686/include/linux/stddef.h

比较发现,pcscfg.cfg中的/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/include/usr/lib/gcc-lib/i386-redhat-linux7/2.96/include路径均无效,与实际系统中的路径不符,修改为/usr/lib/gcc/i386-redhat-linux/4.1.1/include/usr/lib/gcc/i386-redhat-linux/3.4.6/include 即可:

$ cat /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg
sys_include=(/ade/aime_rdbms_9819/oracle/precomp/public,/usr/include,/usr/lib/gcc-lib/i486-suse-linux/2.95.3/include,/usr/lib/gcc/i386-redhat-linux/4.1.1/include,/usr/lib/gcc/i386-redhat-linux/3.4.6/include)
ltype=short

写个简单的程序测试下:

$ proc test.pc
Pro*C/C++: Release 10.2.0.1.0 - Production on Tue May 21 16:07:16 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

System default option values taken from: /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg

转载请注明:Open Source Planet » Pro*C 环境配置(RedHat +Oracle 10g)

树莓派摄像头开卖

最新官方消息,树莓派的摄像头已经可以购买了,可以在 RS Components 或者 Premier Farnell/Element14 上订购。
摄像效果见下图:

以下是官方对于如何装载摄像头做的视频和图文教程,简单翻译了下:

1. 开启摄像头支持
开机后登录,默认用户是 pi,默认密码为 raspberry。在终端输入以下命令升级固件到最新版本:

sudo apt-get update

sudo apt-get upgrade

输入以下命令进入配置管理:

sudo raspi-config

浏览至 camera ,选择 enable

2.如何使用树莓派摄像头软件
raspivid 是一个命令行应用,它可以捕捉视频,而 raspistill 可以帮助你捕捉图片。
-o 或 –output 指定输出文件名, -t 或 –timeout 指定播放预览的时间,以毫秒为单位。要注意的是,默认设置为5秒,且 raspistill 将会捕捉预览期间的最后一帧
-d 或 –demo 会运行demo演示,循环播放各种图像效果。

3.示例命令
以jpeg格式捕捉图像:

raspistill -o image.jpg

以h264格式捕捉5秒视频 format:

raspivid -o video.h264

捕捉10秒视频:

raspivid -o video.h264 -t 10000

在demo模式捕捉10秒视频:

raspivid -o video.h264 -t 10000 -d

查看 raspivid 或者 raspistill 的选项,你可以输入:

raspivid | less
raspistill | less

使用方向键滚动,输入q推出。

更多文档见:Extended documentation

我们建议您修改SSH密码,防止未授权的访问

转载请注明:Open Source Planet » 树莓派摄像头开卖