Happy stress free coding

Jul 17, 2013

DependencyProperties that stopped working

DependencyProperties stopped working when moving to Windows Store.

Suppose you have something like this:

 

    public DateTime StopTime
    {
      set { SetValue(GanttUserControl.StopTimeProperty, value); }
      get { return (DateTime)GetValue(GanttUserControl.StopTimeProperty); }
    }
    public static DependencyProperty StopTimeProperty = DependencyProperty.Register("StopTime", typeof(DateTime), 
                typeof(GanttUserControl), new PropertyMetadata(
                   new PropertyChangedCallback(GanttUserControl.StopTimeChanged)));

    private static void StopTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
      REALLY IMPORTANT THAT THIS CODE RUNS WHENEVER THE PROPERTY IS CHANGED
    }

And you use it in windows WPF, Silverlight, or on Windows Phone 7 and it works just fine.

Then you want to compile this for use with Windows Store and it stopped working. At least the StopTimeChanged is not called anymore! What can be the cause?

Well it turns out that the available overloads for PropertyMetadata has changed from this:

public PropertyMetadata(PropertyChangedCallback propertyChangedCallback);
public PropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback);

to this:

public PropertyMetadata(object defaultValue);
public PropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback);

This means that the compiler now assumes that your onchange-delegate is the initial value for the property and that you no longer want a onchange-delegate.

Sneaky!

 

Mar 24, 2013

What if

“Excessive specialisation leads too many scientists to see nothing outside their own field. Today, too few keep their critical faculty intact or avoid a blind adherance to dogma. It is clear that science today is a trade; only a minority of those who live by science has the true scientific mind in which facts alone matter.”

Jan 24, 2013

If you have a sp url , how do you know what is sites,subsites and directories?

…short answer seems to be : you don’t

Longer answer:

Split the url up in parts, try the url piece by piece until you know what is what…

private void ResolveUrlStringToServiceReferenceAndListNameAndDocName(string s, out string serviceadress, out string listname, out string docname)
 {
   serviceadress = "";
   listname = "";
   docname = "";
   string[] ss = s.Split('/');
   if (ss.Length < 4)
     return;
   string sitesandsubsites = "";
   string list = "";
   string server = ss[0] + "//" + ss[2];
   for (int i = 3; i < ss.Length - 1; i++)
   {
     string sitepart = ss[i];
     list = ss[i + 1].Replace("%20", " ");
     sitesandsubsites += "/" + sitepart;
     SharepointListReference.ListsSoapClient listProxy = new SharepointListReference.ListsSoapClient();
     listProxy.Endpoint.Address = new System.ServiceModel.EndpointAddress(server + sitesandsubsites + "/_vti_bin/lists.asmx");
     try
     {
       listProxy.GetList(list);
       serviceadress = listProxy.Endpoint.Address.Uri.AbsoluteUri;
       listname = list;
       listProxy.Close();
       docname = ss[ss.Length - 1].Replace("%20", " ");
       return;
     }
     catch
     {
       // continue
     }
   }
 }

ULS-Logger

To view Sharepoint logs

Use ULS Viewer, find it under c:\SharepointInstallMedia\Tools

Start it, then attach ULS under file menu

Jan 8, 2013

command line arguments will not be passed to the executable

---------------------------
Microsoft Visual Studio
---------------------------
The current project settings specify that the project will be debugged with specific security permissions.  In this mode, command line arguments will not be passed to the executable.  Do you want to continue debugging anyway?
---------------------------

When that happens – solve it like this:

image

Then switch back to fulltrust…

Aug 24, 2012

Note to self–dynamic styles in wpf

Do not do like this:

Something.Background=this.Resources["ButtonBackGray"] as Brush;

…because the style will not update when changed

Do like this:

Something.SetResourceReference(Grid.BackgroundProperty, "ButtonBackGray"); ;

Mar 17, 2012

MySql–notes

mysql> create database test7000mysql;

mysql>grant usage on *.* to hasse@localhost identified by 'none';

mysql> grant all privileges on test7000mysql.* to hasse@localhost ;

 

 

Connection string:

Server=localhost;Database=test7000mysql;Uid=hasse;Pwd=none;

 

mysql>use test7000mysql;

mysql>select * from class1;