Exemplo n.º 1
0
 public MemoryTripleStore()
 {
     itsNamedResources      = new Hashtable(3000);
     itsResourceDenotations = new Hashtable(3000);
     itsStatementHandler    = new StatementHandler(Add);
     itsResourceStatements  = new Hashtable(1000);
 }
Exemplo n.º 2
0
        public DatabaseTripleStore(string graphUri)
        {
            itsHashCode = graphUri.GetHashCode();

            itsStatementHandler = new StatementHandler(Add);

            //~ string connectionString = String.Format("server={0};user id={1}; password={2}; database={3}; pooling=true",
            //~ ConfigurationSettings.AppSettings["server"],
            //~ ConfigurationSettings.AppSettings["uid"],
            //~ ConfigurationSettings.AppSettings["pwd"],
            //~ ConfigurationSettings.AppSettings["database"]);

            string connectionString = ConfigurationSettings.AppSettings["connectionString"];

            //~ string connectionString = String.Format("Server={0};Uid={1};Pwd={2};Database={3}; pooling=true; resetpooledconnections=false",
            //~ ConfigurationSettings.AppSettings["server"],
            //~ ConfigurationSettings.AppSettings["uid"],
            //~ ConfigurationSettings.AppSettings["pwd"],
            //~ ConfigurationSettings.AppSettings["database"]);
            itsConn = new MySqlConnection(connectionString);
            itsConn.Open();

            PrepareStatements();

            EnsureGraphExistsInDb();
            itsWriteStrategy            = new BatchedWriteStrategy(this);
            itsWriteStrategy.Connection = itsConn;
        }
Exemplo n.º 3
0
 public void Clear()
 {
     itsNamedResources      = new Hashtable();
     itsResourceDenotations = new Hashtable();
     itsResourceStatements  = new Hashtable();
     itsStatementHandler    = new StatementHandler(Add);
 }
Exemplo n.º 4
0
        private async void publicButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            loadLabel.Visibility      = Visibility.Hidden;
            localButton.Visibility    = Visibility.Hidden;
            publicButton.Visibility   = Visibility.Hidden;
            loadLogsButton.Visibility = Visibility.Hidden;
            connectLabel.Visibility   = Visibility.Visible;

            await Task.Run(() =>
            {
                localVariables = new LocalVariables();
                communicator   = new TcpCommunicator(false, localVariables)
                {
                    NoDelay = true
                };
                communicator.Received += PacketReceived_Event;
                communicator.Sent     += PacketSent_Event;
                handler = new StatementHandler(communicator, localVariables);
                handler.StatementHandled += StatementHandled_Event;
            });

            communicator.Open();
            statusVal.Content      = "Connected";
            statusLocalIp.Content  = "Local IP: " + communicator.LocalIp;
            statusPublicIp.Content = "Public IP: " + communicator.PublicIp;
            statusPort.Content     = "Port: " + communicator.Port;

            TransitToMainGrid();
        }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);

            balanceView      = FindViewById <TextView>(Resource.Id.balanceView);
            transactionsView =
                FindViewById <ListView>(Resource.Id.transactionListView);
            deviceSpinner             = FindViewById <Spinner>(Resource.Id.deviceSpinner);
            transactionsRefreshLayout =
                FindViewById <SwipeRefreshLayout>(
                    Resource.Id.transactionRefreshLayout);

            transactionsRefreshLayout.SetOnRefreshListener(this);

            transactionAdaptor       = new TransactionAdaptor(this);
            transactionsView.Adapter = transactionAdaptor;

            deviceAdaptor               = new DeviceAdaptor(this);
            deviceSpinner.Adapter       = deviceAdaptor;
            deviceSpinner.Enabled       = false;
            deviceSpinner.ItemSelected += DeviceSelected;

            if (Account.IsBalanceSet)
            {
                balanceView.Text = Account.Balance.ToString();
            }

            statementHandler = new StatementHandler(this);
            UpdateStatement();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Parse the RDF using supplied TextReader and base URI
        /// </summary>
        public void Parse(TextReader reader, string baseUri)
        {
            Parser           parser             = itsParserFactory.MakeParser(new ResourceFactory(), new StatementFactory());
            StatementHandler handler            = new StatementHandler(Add);
            StatementHandler tripleStoreHandler = itsTripleStore.GetStatementHandler();

            parser.NewStatement += handler;
            parser.NewStatement += tripleStoreHandler;
            parser.Parse(reader, baseUri);
            parser.NewStatement -= handler;
            parser.NewStatement -= tripleStoreHandler;
        }
        public void Log(StatementHandler handler, StatementHandledEventArgs e)
        {
            StringBuilder sb = new StringBuilder(100);

            if (e.Successful)
            {
                sb.Append("Success. Result = ").Append(e.Result).Append(", calculated in ").Append(handler.ElapsedMs).Append(" ms.");
                if (e.Errors != null && e.Errors.Length > 0)
                {
                    sb.Append(" Warning(s): ");
                    foreach (var err in e.Errors)
                    {
                        sb.Append(err.Replace(Environment.NewLine, ", ")).Append("; ");
                    }
                    sb.Remove(sb.Length - 2, 2);
                }
            }
            else if (e.Cancelled)
            {
                sb.Append("Cancelled by the user after ").Append(handler.ElapsedMs).Append(" ms.");
            }
            else if (e.Nan)
            {
                sb.Append("Success. Result = NaN, calculated in ").Append(handler.ElapsedMs).Append(" ms.");
                if (e.Errors != null && e.Errors.Length > 0)
                {
                    sb.Append(" Warning(s): ");
                    foreach (var err in e.Errors)
                    {
                        sb.Append(err.Replace(Environment.NewLine, ", ")).Append("; ");
                    }
                    sb.Remove(sb.Length - 2, 2);
                }
            }
            else
            {
                sb.Append("Failure after ").Append(handler.ElapsedMs).Append(" ms.");
                if (e.Errors != null && e.Errors.Length > 0)
                {
                    sb.Append(" Reason(s): ");
                    foreach (var err in e.Errors)
                    {
                        sb.Append(err.Replace(Environment.NewLine, ", ")).Append("; ");
                    }
                    sb.Remove(sb.Length - 2, 2);
                }
            }

            AddDateTime();
            AddHost(handler.Communicator.LocalEndPoint);
            AddType("Statement Execution");
            AddContents(sb.ToString());
        }
Exemplo n.º 8
0
        private void Disconnect()
        {
            communicator.Received -= PacketReceived_Event;
            communicator.Sent     -= PacketSent_Event;
            localVariables         = null;
            communicator.Dispose();
            logger.LogClose(communicator);
            communicator = null;
            handler.Dispose();
            handler = null;

            varView.Items.Clear();
            varViewTitle.Content = "Local Variables (Count: 0):";
            exprBox.Text         = "";
            resultBox.Text       = "";
        }
Exemplo n.º 9
0
        private void localButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            localVariables = new LocalVariables();
            communicator   = new TcpCommunicator(localVariables)
            {
                NoDelay = true
            };
            communicator.Received += PacketReceived_Event;
            communicator.Sent     += PacketSent_Event;
            communicator.Open();
            handler = new StatementHandler(communicator, localVariables);
            handler.StatementHandled += StatementHandled_Event;

            statusVal.Content      = "Local";
            statusLocalIp.Content  = "Local IP: " + communicator.LocalIp;
            statusPublicIp.Content = "Public IP: N/A";
            statusPort.Content     = "Port: " + communicator.Port;

            TransitToMainGrid();
        }
Exemplo n.º 10
0
        /// <summary>
        /// A simple function that returns a user current balance
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var response = new SkillResponse
            {
                Response = new ResponseBody()
            };

            response.Response.ShouldEndSession = false;
            IOutputSpeech innerResponse = null;

            var log = context.Logger;

            log.LogLine($"Skill Request Object:");
            log.LogLine(JsonConvert.SerializeObject(input));

            var allResources = GetResources();
            var resource     = allResources.FirstOrDefault();

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                log.LogLine($"Default LaunchRequest made: 'Alexa, open Kerv");
                innerResponse = new PlainTextOutputSpeech();
                (innerResponse as PlainTextOutputSpeech).Text = resource.WelcomeMessage;
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)input.Request;

                switch (intentRequest.Intent.Name)
                {
                case "AMAZON.CancelIntent":
                    log.LogLine($"AMAZON.CancelIntent: send StopMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                    response.Response.ShouldEndSession            = true;
                    break;

                case "AMAZON.StopIntent":
                    log.LogLine($"AMAZON.StopIntent: send StopMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                    response.Response.ShouldEndSession            = true;
                    break;

                case "AMAZON.HelpIntent":
                    log.LogLine($"AMAZON.HelpIntent: send HelpMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.HelpMessage;
                    break;

                case "GetBalance":
                    log.LogLine($"GetBalance sent: send customer balance");
                    var loginRequest = new LoginHandler();
                    if (loginRequest.Login("*****@*****.**", "Saz97788_50", true).Result)
                    {
                        var statmentHandler = new StatementHandler(_loggedOutListener);
                        if (statmentHandler.RefreshStatement().Result)
                        {
                            innerResponse = new PlainTextOutputSpeech();
                            (innerResponse as PlainTextOutputSpeech).Text = statmentHandler.Balance.ToString();
                        }
                    }
                    break;

                default:
                    log.LogLine($"Unknown intent: " + intentRequest.Intent.Name);
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.HelpReprompt;
                    break;
                }
            }

            response.Response.OutputSpeech = innerResponse;
            response.Version = "1.0";
            log.LogLine($"Skill Response Object...");
            log.LogLine(JsonConvert.SerializeObject(response));
            return(response);
        }