public WindowUsingItemsSourceProperty()
        {
            InitializeComponent();

            // when adding new items, you MUST implement the NewTabItem event to provide the object for the content of the tabitem,
            // otherwise an exception will be thrown
            tabControl.NewTabItem +=
                delegate(object sender, NewTabItemEventArgs e)
                {
                    // return a new MyObject to be used as the content of the new tabItem
                    MyObject myObject = new MyObject { Header = "Tab Item " + count, Value = count };
                    e.Content = myObject;
                    count++;
                };
        }
Ejemplo n.º 2
0
        static async Task MainAsync()
        {
            //AsyncContext.Run(() => ());

            // Create stores to keep objects.
            var system = Warehouse.New <MemoryStore>("system");
            var remote = Warehouse.New <MemoryStore>("remote");
            var mongo  = Warehouse.New <MongoDBStore>("db");

            // Open the warehouse
            var ok = await Warehouse.Open().Task;


            // Create new object if the store is empty
            if (mongo.Count == 0)
            {
                myObject = Warehouse.New <MyObject>("my", mongo, null,
                                                    new UserPermissionsManager(new Structure()
                {
                    ["demo@localhost"] = new Structure()
                    {
                        ["Subtract"] = new Structure {
                            ["Execute"] = "yes"
                        },
                        ["Stream"] = new Structure {
                            ["Execute"] = "yes"
                        },
                        ["_attach"]         = "yes",
                        ["_get_attributes"] = "yes",
                        ["_set_attributes"] = "yes",
                    }
                }));
            }
            else
            {
                Warehouse.Get("db/my").Then((o) => { myObject = (MyObject)o; });
            }

            // Create new distributed server object
            var iip = Warehouse.New <DistributedServer>("iip", system);

            // Set membership which handles authentication.
            iip.Membership = Warehouse.New <MyMembership>("ms", system);
            // Start the server on port 5000.
            iip.Start(new TCPSocket(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 5000)), 600000, 60000);


            // Create http server to handle IIP over Websockets
            var http = Warehouse.New <HTTPServer>("http", system);

            http.Start(new TCPSocket(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 5001)), 600000, 60000);

            // Create IIP over Websocket HTTP module and give it to HTTP server.
            var wsOverHttp = Warehouse.New <IIPoWS>("IIPoWS", system, http);



            Warehouse.StoreConnected += (store, name) =>
            {
                if (store.Instance.Parents.Contains(iip))
                {
                    store.Get("local/js").Then((r) =>
                    {
                        if (r != null)
                        {
                            dynamic d = r;
                            d.send("Welcome");
                        }
                    });
                }
            };


            // Start testing
            // TestClient();



            var running = true;

            while (running)
            {
                var cmd = Console.ReadLine();
                if (cmd.ToLower() == "exit")
                {
                    Warehouse.Close().Then((x) =>
                    {
                        if (!x)
                        {
                            Console.WriteLine("Failed to close the warehouse.");
                        }
                        else
                        {
                            Console.WriteLine("Successfully closed the warehouse.");
                        }

                        running = false;
                    });
                }
                else
                {
                    Console.WriteLine(myObject.Name + " " + myObject.Level);
                }
            }
        }