вівторок, 29 січня 2013 р.

function savePushURI($file,$uri)
{
 $fh = fopen($file,"r+");
 if ($fh) {
  echo "File $file found<br>\n";
  $xmls = "";
  while (!feof($fh)) {
    $buf=fgets($fh, 4096);
    $xmls = $xmls . $buf;
  }
  libxml_use_internal_errors(true);
  $sxe = simplexml_load_string($xmls);
  if ($sxe) {
     echo "File $file has right XML structure<br>\n\n";
     fclose ($file);
     $fh = fopen ($file,"w");
     if (!$fh) {
       echo "ERROR: can not open file $file for writing. Do nothing. <br>\n";
       return;
     }
     $channel = $sxe->addChild('channel');
     $channel->addChild('uri',$uri);
     $channel->addChild('count',"0");
     $channel->addChild('toast',"1");
     fwrite($fh, $sxe->asXML());
     fclose($fh);
     echo "New record to $file had added successfully<br>\n\n";
     return;
  } else {
     echo "File $file has wrong XML structure. Erasing and creating new one.<br>\n\n";
     foreach(libxml_get_errors() as $error) {
       echo "\t", $error->message;
     }
     fclose ($file);
     $fh = fopen ($file,"w");
     if (!$fh) {
       echo "ERROR: can not create file $file. Do nothing. <br>\n";
       return;
     }
  }
 } else   {
     echo "File $file not found, creating new one <br>\n\n";
     fclose ($file);
     $fh = fopen ($file,"w");
     if (!$fh) {
       echo "ERROR: can not create file $file. Do nothing. <br>\n";
       return;
     }
 }
$string = <<<XML
<channels>
 <channel>
  <uri></uri>
  <count></count>
  <toast></toast>
 </channel>
</channels>
XML;
 $sxe = new SimpleXMLElement($string);
 $sxe->channel[0]->uri = $uri;
 $sxe->channel[0]->count = "0";
 $sxe->channel[0]->toast = "1";
 fwrite($fh, $sxe->asXML());
 fclose($fh);
 echo "New file $file had created successfully<br>\n\n";
 return;
}

Building an Address Book with OpenLDAP
LDAP. Часть 1. Настройка отказоустойчивого LDAP сервера
SimpleXML
Проверка портов

вівторок, 22 січня 2013 р.

Поговорки, подслышанные в подкастах

 Не показывай дураку половину работы.

 Я не могу размазывать себя слишком тонким слоем.

 Сформулировать цель - половина работы. "Завтра женюсь на английской королеве". Теперь осталась вторая половина.

Фразы "нужно попробовать всё" и "один раз не 321" придумал один и тот же человек.

 Если ты хочешь пробиться, зачем пробиваться через толпу?


пʼятниця, 11 січня 2013 р.

Допилял странички детальной информации по выбранному хосту или сервису.
Теперь приступаю к пуш-уведомлениям.

четвер, 10 січня 2013 р.

Windows Phone 7 Pivot ListBox SelectionChanged

Ура. Поборол ложное срабатывание SelectionChanged в Pivot ListBox. Детали ниже:

Обработчик события нажития на ListBox:
        private void ServicesListBox_SelectionChanged (object sender, SelectionChangedEventArgs e)
        {
            if (!App.ViewModel.IsAllServicesLoaded)
            {
                this.ServicesListBox.SelectedIndex = -1;
                return;
            }
            if (ServicesListBox.SelectedItem != null)
            {
                Service selectedService = (Service)ServicesListBox.SelectedItem;
                string hostName = selectedService.HostName;
                string serviceDescription = selectedService.ServiceDescription;
                this.ServicesListBox.SelectedIndex = -1;
                NavigationService.Navigate(new Uri("/ServicePage.xaml?HostName="+hostName+"&ServiceDescription="+serviceDescription, UriKind.Relative));
            }
            else
            {
                return;
            }
        }

App.ViewModel.IsAllServicesLoaded - это true если завершилась загрузка и сериализация списка класса Service:


Сами вызовы суть тупо затычки с присваиваниями:
         public bool IsAllServicesLoaded
        {
            get;
            private set;
        }
        public void AllServicesLoaded()
        {
            this.IsAllServicesLoaded = true;
        }
        public void AllServicesLoaded_Disable()
        {
            this.IsAllServicesLoaded = false;
        }

Загрузка списка отправляется в фон:

        public void LoadServices()
        {
            AppSettings settings = new AppSettings();
            Uri uri = new Uri((string)settings.URLwpNagSetting + "?cmd=3"); // , UriKind.Relative);
            WebClient webClient = new WebClient();
            webClient.Credentials = new NetworkCredential((string)settings.UserNameSetting, (string)settings.UserPasswordSetting);
            webClient.DownloadStringCompleted += OnDownloadServicesCompleted;
            webClient.DownloadStringAsync(uri);
        }

По  окончинии загрузки 1) ставим false флагу для предотвращения срабатывания SelectionChanged 2) десериализуем для обновления привязки 3) врубаем true для флага и разрешаем таким образом обработку события SelectionChanged:
       void OnDownloadServicesCompleted(object sender, DownloadStringCompletedEventArgs args)
        {
            AllServicesLoaded_Disable();
            StringReader reader = new StringReader(args.Result);
            XmlSerializer xml = new XmlSerializer(typeof(ServiceBody));
            ServiceBody = xml.Deserialize(reader) as ServiceBody;
            AllServicesLoaded();         
        }

Помогла ссылка на stackoverflow:
http://stackoverflow.com/questions/7679586/listbox-selectionchanged-firing-when-setting-to-1-within-function-wp7

четвер, 3 січня 2013 р.

Разобрался с навигацией между страницами и передачей параметров выбора пункта списка.
Нарисовал классы и формы для отображения детальной информации по выбранному сервису или хосту.