JavaScript (IE) Puzzle
javascript puzzle link
javascript puzzle link
Windows Communication Foundation (WCF) Tcp.Net hosting program
HostProgram.exe dosyanızın yanında “dllpool” isimli bir klasör oluşturun.
(Create “dllpool” directory in HostProgram.exe current directory)
HostProgram.exe programınızı çalıştırdığınız zaman otomatik olarak “dllpool” klasöründeki
dosyaları bulunduğu klasöre kopyalar programı restart edip dll’i host eder.
(when starting HostProgram.exe automatic copy “dll” files in “dllpool” directory to HostProgram.exe file current directory and HostProgram.exe to be restart)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.Net;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Collections;
using System.Diagnostics;
namespace HostProgram
{
public class HostProgram
{
private ArrayList arys = new ArrayList();
private string path = “”;
public HostProgram()
{
try
{
Console.WriteLine(”Please wait… 8 seconds”);
Thread.Sleep(8000);
path = Environment.CurrentDirectory + “\\dllpool”;
copyFiles();
FileSystemWatcher watcher = new FileSystemWatcher(path);
watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
watcher.EnableRaisingEvents = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
void watcher_Deleted(object sender, FileSystemEventArgs e)
{
restart();
}
void watcher_Created(object sender, FileSystemEventArgs e)
{
restart();
}
void watcher_Changed(object sender, FileSystemEventArgs e)
{
restart();
}
void watcher_Renamed(object sender, RenamedEventArgs e)
{
restart();
}
public void restart()
{
ProcessStartInfo psi = new ProcessStartInfo(”HostProgram.exe”);
psi.WorkingDirectory = Environment.CurrentDirectory;
try
{
System.Diagnostics.Process.Start(psi);
Environment.Exit(0);
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}
}
public void copyFiles()
{
try
{
DirectoryInfo df = new DirectoryInfo(path);
FileInfo[] fi = df.GetFiles();
foreach (FileInfo f in fi)
{
FileInfo cpy = f.CopyTo(f.Directory.Parent.FullName + “\\” + f.Name, true);
startHost(cpy);
}
Console.WriteLine(”Services Started”);
}
catch (Exception ex)
{
Console.WriteLine(”ERROR : [" + ex.Message + "]“);
}
}
public void startHost(FileInfo fi)
{
try
{
Assembly assembly = Assembly.LoadFile(fi.FullName);
Console.WriteLine(”\nDLL Loaded : ” + assembly.GetName().Name);
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsClass)
{
bool status = false;
Type[] typesI = type.GetInterfaces();
foreach (Type typeI in typesI)
{
Attribute[] attrs = Attribute.GetCustomAttributes(typeI);
foreach (Attribute attr in attrs)
{
if (attr.GetType().Name.Equals(”ServiceContractAttribute”))
{
Uri[] uris = { new Uri(”http://localhost:8732/serdarturkel/” + type.Name) };
startServices(type, typeI, uris);
status = true;
break;
}
if (status) break;
}
if (status) break;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(”\n” + ex.Message + ” : Not loaded ” + fi.Name);
}
}
public void startServices(Type typ, Type endpoint, Uri[] uris)
{
try
{
Console.WriteLine(”Starting services ” + typ.Name + ” , please wait”);
ServiceHost host = new ServiceHost(typ, uris);
ServiceCredentials credentials = host.Credentials;
credentials.WindowsAuthentication.AllowAnonymousLogons = false;
credentials.UserNameAuthentication.UserNamePasswordValidationMode =
UserNamePasswordValidationMode.Windows;
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(behavior);
WSHttpBinding binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
binding.Security.Mode = SecurityMode.Message;
host.AddServiceEndpoint(endpoint, binding, uris[0]);
using (ServiceHost serviceHost = new ServiceHost(typ))
{
host.Open();
Console.WriteLine(”The service is ready : ” + typ.Name + ” / ” + endpoint);
}
}
catch (Exception e)
{
Console.WriteLine(”not started services : ” + typ.Name + ” / ” + e.Message);
}
}
static void Main(string[] args)
{
new HostProgram();
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
namespace XMLSerialize
{
public class XMLSerialize
{
public static void Main(String[] args)
{
Personal person = new Personal();
person.PersonalID = “1″;
person.PersonalName = “serdar türkel”;
person.Age = 27;
try
{
XMLSerialize xs = new XMLSerialize();
string rest = xs.SerializeObject(person);
Console.WriteLine(rest);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
public String SerializeObject(Object serializeObject)
{
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(Personal));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, serializeObject);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
string xmlSerializedString = UTF8ByteArrayToString(memoryStream.ToArray());
return xmlSerializedString;
}
public Object DeserializeObject(String xmlSerializedString)
{
XmlSerializer xs = new XmlSerializer(typeof(Personal));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(xmlSerializedString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return xs.Deserialize(memoryStream);
}
private String UTF8ByteArrayToString(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedString = encoding.GetString(characters);
return constructedString;
}
private Byte[] StringToUTF8ByteArray(String xmlSerializedString)
{
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(xmlSerializedString);
return byteArray;
}
}
[XmlRootAttribute(ElementName = "Personal", IsNullable = false)]
public class Personal
{
[XmlAttribute(AttributeName = "PersonalID")]
public string PersonalID
{
get;
set;
}
[XmlElement(ElementName = "PersonalName")]
public String PersonalName
{
get;
set;
}
[XmlElement(ElementName = "Age")]
public int Age
{
get;
set;
}
}
}
Java XML Serialization için bir örnek
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name=”XmlClass“)
public class XmlClass {
@XmlElement(name=”XmlNode“)
public String XmlNode=”xml node“;
public SubNode SubNodeObject=new SubNode();
public static void main(String args[]){
try{
XmlClass serializer=new XmlClass();
JAXBContext context = JAXBContext.newInstance(serializer.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter xmlInfo=new StringWriter();
marshaller.marshal(serializer,xmlInfo);
System.out.println(xmlInfo);
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
@XmlRootElement(name=”SubXmlClass“)
public class SubNode{
@XmlElement(name=”SubXmlNode“)
public String XmlNode=”sub xml node“;
}
Kod çıktısı
<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>
<XmlClass>
<XmlNode>xml node</XmlNode>
<SubNodeObject>
<SubXmlNode>sub xml node</SubXmlNode>
</SubNodeObject>
</XmlClass>
Eğer hata mesajı alırsanız LİNK dosyayı indirip projenize referans ediniz.
C# ile Linq where ifadesinin kullanımı
kisiler isimli string dizideki elemanlardan içinde “u” harfi geçenlerin listelenmesini sağlar.
string[] kisiler = { “serdar”, “sibel”, “galip”, “uğur”, “banu”, “dilek” };
var kisi = from secili in kisiler where secili.Contains(”u”) select secili;
foreach (var seciliKisi in kisi)
Console.WriteLine(seciliKisi);
C# 3.0 ile gelen var tanımlayıcısının kullanımı
var sayi=10; (sayi değişkeni sayısal bir veri tuttuğu için sayısal bir değişken olarak kullanılır)
var metin=”serdar türkel”; ( metin değişkenine metinsel bir değer atandığı için metin değişkeni bir karakter dizisi olarak kullanılır )
var değişkeni ile değişkenlerin veri tipleri yürütme zamanında (runtime) belirlenir.
var kisi = new { Ad = “serdar”, Soyad = “türkel” }; (kisi sınıfsal bir veri türü olarak belirlenir. “ad”, “soyad” ise bu sınıfa ait özellikleri göstermektedir.)
C# İle döviz kurlarını çekmek,
Konsol uygulamasıdır.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml;
using System.IO;
namespace Kurlar
{
class Program
{
static void Main(string[] args)
{
WebRequest wrequest = HttpWebRequest.Create(”http://www.tcmb.gov.tr/kurlar/today.xml”);
WebResponse wresponse = wrequest.GetResponse();
Stream stream = wresponse.GetResponseStream();
StreamReader srd = new StreamReader(stream);
string xmlDetail = srd.ReadToEnd();
srd.Close();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlDetail);
XmlElement element = doc.DocumentElement;
XmlAttributeCollection rootAtt = element.Attributes;
Console.WriteLine(element.Name);
foreach (XmlAttribute attr in rootAtt)
{
Console.WriteLine(attr.Name + ” : ” + attr.Value);
}
XmlNodeList nodelist = element.ChildNodes;
foreach (XmlNode node in nodelist)
{
XmlAttributeCollection collectionatt = node.Attributes;
foreach (XmlAttribute attr in collectionatt)
{
Console.WriteLine(” “+attr.Name + ” : ” + attr.Value);
}
XmlNodeList subNodelist = node.ChildNodes;
foreach (XmlNode subnode in subNodelist)
{
XmlAttributeCollection subcollectionatt = subnode.Attributes;
foreach (XmlAttribute subattr in subcollectionatt)
{
Console.WriteLine(subattr.Name + ” : ” + subattr.Value);
}
Console.WriteLine(” ” + subnode.Name + ” : ” + subnode.InnerText);
}
}
}
}
}
Dinamik JTable
| Access ve SQL server üzerinden sorgu ile çağrılan sonuçları uygun jtable içerisine döşeyen kod… |
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.util.*;
import java.sql.*;
public class modelTable extends JFrame{
private String connectSQLServer=”jdbc:odbc:Driver={SQL Server};Server=Host;Database=example;Uid=username;Pwd=password;”;
private String connectAccess=”jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\\db1.mdb;Uid=;Pwd=;”;
private String SQL=”select * from table1″;
public modelTable(String title,int w,int h){
super(title);
this.setSize(w,h);
Toolkit tk=this.getToolkit();
Dimension dim=tk.getScreenSize();
int x=(dim.width-w)/2;
int y=(dim.height-h)/2;
this.setLocation(x,y);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
try {
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con=connectDB(connectAccess);
Statement st=con.createStatement();
ResultSet rest=st.executeQuery(SQL);
DefaultTableModel model=createModel(rest);
JTable table=createTable(model);
JScrollPane jsp=new JScrollPane(table);
this.add(jsp);
}
catch (Exception ex) {
JOptionPane op=new JOptionPane();
op.showMessageDialog(this,ex.getMessage());
}
}
public Connection connectDB(String driver) throws SQLException{
Connection con=DriverManager.getConnection(driver);
return con;
}
public DefaultTableModel createModel(ResultSet rest) throws SQLException{
DefaultTableModel dtm=new DefaultTableModel();
ResultSetMetaData rsmd=rest.getMetaData();
for(int i=1;i<=rsmd.getColumnCount();i++){
dtm.addColumn(rsmd.getColumnName(i));
}
Vector rows;
while(rest.next()){
rows=new Vector();
for(int j=1;j<=rsmd.getColumnCount();j++){
rows.addElement(rest.getString(j));
}
dtm.addRow(rows);
}
return dtm;
}
public JTable createTable(DefaultTableModel dm){
JTable table=new JTable(dm);
return table;
}
public static void main(String args[]){
JFrame.setDefaultLookAndFeelDecorated(true);
modelTable mt=new modelTable(”SQL verilerini JTable\’a aktarma”,400,400);
mt.setVisible(true);
}
}
Öncelikle forms.java dosyası
/** * @(#)Chatin.java * * JFC Aplication * * @Serdar TÜRKEL * @version 1.00 20/10/2006 */ package chatin; |
Yukarıdaki kodu derlemeden önce aşağıdaki kodu derleyin
[ Chatin.java ]
| /** * @(#)Chatin.java * * JFC Aplication * * @Serdar TÜRKEL * @version 1.00 06/10/2006 */ package chatin; addIPList.put(nickFriendTxt.getText(),IP); } } } } } } JScrollPane jspMessageArea=new JScrollPane(messageArea); JScrollPane jspResponseOrRequestMessageArea=new JScrollPane(responseOrRequestMessageArea); sendButton=new JButton(”SEND”); JButton kaldir=new JButton(”SEÇİLİ KİŞİYİ LİSTEDEN KALDIRMAK İÇİN TIKLAYIN”); this.add(sendButton); return bar; JButton start=new JButton(”Start”); addIP=new JButton(”ADD IP & NICK”); IPAdressTxt=new JTextField(); nickAdressTxt=new JTextField(); nickFriendTxt=new JTextField(); JLabel IPLabel=new JLabel(” IP :”); JLabel nickLabel=new JLabel(” NICK :”); JLabel friendName=new JLabel(” Friend :”); dg.add(nickFriendTxt); return dg; // } } } } } //process |
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Aug | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||