Пример #1
0
        public sonesExampleClass(String[] myArgs)
        {
            if (myArgs.Count() > 0)
            {
                foreach (String parameter in myArgs)
                {
                    if (parameter.ToUpper() == "--Q")
                        quiet = true;
                }
            }

            #region Init NotificationDispatcher
            var _NotificationSettings = new NotificationSettings()
            {
                StartDispatcher = false,
                StartBrigde = false
            };

            var _NotificationDispatcher = new NotificationDispatcher(UUID.NewUUID, _NotificationSettings);

            #endregion

            #region Create or open GraphDS

            var _GraphDSSharp = new GraphDSSharp()
            {
                DatabaseName = "sonesExample",
                Username = "******",
                Password = "******",
                NotificationSettings = _NotificationSettings,
                NotificationDispatcher = _NotificationDispatcher,
            };

            // Create a InMemory data storage
            _GraphDSSharp.CreateDatabase(true);

            #endregion

            #region Create GraphDB types

            _GraphDSSharp.CreateTypes(CheckResult, typeof(Document), typeof(Author), typeof(Tag));

            #endregion

            #region Create a document upload directory

            _GraphDSSharp.CreateDirectoryObject(new ObjectLocation("Uploads"));

            #endregion

            #region Insert some data

            _GraphDSSharp.Query("INSERT INTO Tag VALUES (Name = 'good')", CheckResult);
            _GraphDSSharp.Query("INSERT INTO Tag VALUES (Name = 'funny')", CheckResult);
            _GraphDSSharp.Query("INSERT INTO Tag VALUES (Name = 'science fiction')", CheckResult);

            _GraphDSSharp.Query("INSERT INTO Author VALUES (Name = 'Holger', EMail = '*****@*****.**')", CheckResult);
            _GraphDSSharp.Query("INSERT INTO Author VALUES (Name = 'Achim',  EMail = '*****@*****.**')", CheckResult);

            #endregion

            #region Start REST, WebDAV and WebAdmin services, send GraphDS notification

            var _HttpSecurity = new HTTPSecurity()
            {
                CredentialType = HttpClientCredentialType.Basic,
                UserNamePasswordValidator = new PassValidator()
            };

            // Start a REST service on localhost port 9975
            var _RESTService      = _GraphDSSharp.StartREST(IPAddress.Any, 9975, _HttpSecurity);

            // Start a WebDAV service on localhost port 9978
            var _WebDAVService    = _GraphDSSharp.StartWebDAV(IPAddress.Any, 9978, _HttpSecurity);

            // Send GraphDS notification
            _NotificationDispatcher.SendNotification(typeof(NGraphDSReady),
                    new NGraphDSReady.Arguments() { Message = "sonesExample up'n'ready!" },
                    NotificationPriority.Normal,
                    true);

            #endregion

            #region Some helping lines...
            if (!quiet)
            {
                Console.WriteLine();
                Console.WriteLine("This small example demonstrates how to start a sones GraphDB");
                Console.WriteLine("Instance and it's several services:");
                Console.WriteLine("   * If you want to suppress console output add --Q as a");
                Console.WriteLine("     parameter.");
                Console.WriteLine("   * REST Service is started at http://localhost:9975");
                Console.WriteLine("      * access it directly like in this example: ");
                Console.WriteLine("           http://localhost:9975/gql?DESCRIBE%20TYPES");
                Console.WriteLine("      * if you want JSON Output add ACCEPT: application/json ");
                Console.WriteLine("        to the client request header (or application/xml or");
                Console.WriteLine("        application/text)");
                Console.WriteLine("   * we recommend to use the AJAX WebShell. ");
                Console.WriteLine("        Browse to http://localhost:9975/WebShell and use");
                Console.WriteLine("        the username \"test\" and password \"test\"");
                Console.WriteLine("   * Additionally a WebDAV service is started on port 9978.");
                Console.WriteLine();
            }
            #endregion

            #region Start the GraphDS command line interface

            if (!quiet)
                _GraphDSSharp.OpenCLI();
            else
                while (true)
                {
                    Thread.Sleep(1000);
                }

            #endregion

            #region Shutdown

            _GraphDSSharp.Shutdown();

            #endregion
        }