Beispiel #1
0
 public BayeuxClientState(BayeuxClient bayeuxClient, State type, IDictionary <String, Object> handshakeFields,
                          IDictionary <String, Object> advice, ClientTransport transport, String clientId, long backoff)
 {
     this.bayeuxClient    = bayeuxClient;
     this.type            = type;
     this.handshakeFields = handshakeFields;
     this.advice          = advice;
     this.transport       = transport;
     this.clientId        = clientId;
     this.backoff         = backoff;
 }
Beispiel #2
0
        public NotifyClient(string cometURL, string channelId)
        {
            this.channelId = channelId;
            if (!this.channelId.StartsWith("/"))
                this.channelId = "/" + this.channelId;

            var transports = new List<ClientTransport>();
            transports.Add(new LongPollingTransport(null));

            client = new BayeuxClient(cometURL, transports);

            client.getChannel(Channel_Fields.META + "/**")
                .addListener(this);

            callEventChannel = client.getChannel(this.channelId);
        }
Beispiel #3
0
 public HandshakeTransportListener(BayeuxClient bayeuxClient)
     : base(bayeuxClient)
 {
 }
Beispiel #4
0
        public static void Main(string[] args)
        {
            try
            {
                var arguments = new CommandLine.Utility.Arguments(args, true);

                string cometUrl = arguments.GetValueOrDefault("cometurl", "http://comet.apphb.com/comet.axd");

                string channel = arguments.GetValueOrDefault("channel");
                if (!channel.StartsWith("/"))
                    channel = "/" + channel;

                if (string.IsNullOrEmpty(channel))
                    throw new ArgumentException("Missing channel");

                var transports = new List<ClientTransport>();
                transports.Add(new LongPollingTransport(null));

                var client = new BayeuxClient(cometUrl, transports);

                client.getChannel(Channel_Fields.META + "/**")
                    .addListener(new MetaListener());

                client.handshake();
                client.waitFor(10000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });
                if (!client.Connected)
                {
                    throw new InvalidOperationException("Failed to connect to comet server");
                }

                computerStatus = new Dictionary<string, bool?>(StringComparer.OrdinalIgnoreCase);

                bool listen = false;
                HashSet<string> waitForCompletion = null;
                int waitTimeoutSeconds = 30;

                StringBuilder jsonData = new StringBuilder();
                foreach (var kvp in arguments)
                {
                    switch (kvp.Key)
                    {
                        case "channel":
                        case "cometurl":
                            // Ignore
                            break;

                        case "listen":
                            listen = true;
                            break;
                        case "wait":
                            waitForCompletion = new HashSet<string>();
                            foreach (var server in kvp.Value.Split(','))
                                waitForCompletion.Add(server.Trim());
                            break;
                        case "waitsec":
                            waitTimeoutSeconds = int.Parse(kvp.Value);
                            break;
                        default:
                            Console.WriteLine(string.Format("Sending notify for data: {0}={1}", kvp.Key, kvp.Value));
                            if (jsonData.Length > 0)
                                jsonData.Append(',');
                            jsonData.AppendFormat("\"{0}\":\"{1}\"", kvp.Key, kvp.Value);
                            break;
                    }
                }

                var chn = client.getChannel(channel);

                var msgListener = new MsgListener();
                msgListener.StatusReceived += new EventHandler<StatusEventArgs>(MsgListener_StatusReceived);
                if (listen || waitForCompletion != null)
                {
                    chn.subscribe(msgListener);
                }

                client.waitForEmptySendQueue(1000);

                if (jsonData.Length > 0)
                {
                    chn.publish('{' + jsonData.ToString() + '}');
                    Console.WriteLine("Sending data: " + jsonData.ToString());
                }

                bool? overallResult = null;
                if (waitForCompletion != null)
                {
                    lastStatus = DateTime.Now;

                    while ((DateTime.Now - lastStatus).TotalSeconds <= waitTimeoutSeconds)
                    {
                        // Check if all servers have reported in
                        int failed = 0;
                        int succeeded = 0;
                        foreach (var server in waitForCompletion)
                        {
                            bool? status;
                            if (computerStatus.TryGetValue(server, out status))
                            {
                                if (status.HasValue)
                                {
                                    if (status.Value)
                                        succeeded++;
                                    else
                                        failed++;
                                }
                            }
                        }

                        if (failed + succeeded == waitForCompletion.Count)
                        {
                            // Done
                            overallResult = failed == 0;
                            break;
                        }

                        System.Threading.Thread.Sleep(100);
                    }

                    chn.unsubscribe(msgListener);
                }

                if (listen)
                {
                    Console.WriteLine("Hit <enter> to exit");
                    Console.ReadLine();

                    chn.unsubscribe(msgListener);
                }

                Console.WriteLine("Waiting for queue to be sent");
                client.waitForEmptySendQueue(1000);

                Console.WriteLine("Disconnecting");
                client.disconnect();
                client.waitFor(2000, new List<BayeuxClient.State>() { BayeuxClient.State.DISCONNECTED });

                if (waitForCompletion != null)
                {
                    foreach (var server in waitForCompletion)
                    {
                        bool? status;
                        computerStatus.TryGetValue(server, out status);

                        if (!status.HasValue)
                            Console.WriteLine(string.Format("{0} - no response", server));
                        else if(status.Value)
                            Console.WriteLine(string.Format("{0} - successful", server));
                        else
                            Console.WriteLine(string.Format("{0} - failure", server));
                    }

                    if (!overallResult.HasValue)
                    {
                        Console.WriteLine("Time out");
                        Environment.Exit(1);
                    }
                    else
                    {
                        if (overallResult.Value)
                        {
                            Console.WriteLine("Successful!");
                            Environment.Exit(0);
                        }
                        else
                        {
                            Console.WriteLine("Failure");
                            Environment.Exit(200);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
                Environment.Exit(255);
            }
        }
Beispiel #5
0
 public BayeuxClientChannel(BayeuxClient bayeuxClient, ChannelId channelId)
     : base(channelId)
 {
     this.bayeuxClient = bayeuxClient;
 }
Beispiel #6
0
 public HandshakeTransportListener(BayeuxClient bayeuxClient)
     : base(bayeuxClient)
 {
 }
Beispiel #7
0
 public DisconnectedState(BayeuxClient bayeuxClient, ClientTransport transport)
     : base(bayeuxClient, State.DISCONNECTED, null, null, transport, null, 0)
 {
 }
Beispiel #8
0
 public ConnectedState(BayeuxClient bayeuxClient, IDictionary <String, Object> handshakeFields, IDictionary <String, Object> advice, ClientTransport transport, String clientId)
     : base(bayeuxClient, State.CONNECTED, handshakeFields, advice, transport, clientId, 0)
 {
 }
Beispiel #9
0
 public DisconnectingState(BayeuxClient bayeuxClient, ClientTransport transport, String clientId)
     : base(bayeuxClient, State.DISCONNECTING, null, null, transport, clientId, 0)
 {
 }
Beispiel #10
0
 public DisconnectedState(BayeuxClient bayeuxClient, ClientTransport transport)
     : base(bayeuxClient, State.DISCONNECTED, null, null, transport, null, 0)
 {
 }
Beispiel #11
0
 public HandshakingState(BayeuxClient bayeuxClient, IDictionary <String, Object> handshakeFields, ClientTransport transport)
     : base(bayeuxClient, State.HANDSHAKING, handshakeFields, null, transport, null, 0)
 {
 }
Beispiel #12
0
 public DisconnectingState(BayeuxClient bayeuxClient, ClientTransport transport, String clientId)
     : base(bayeuxClient, State.DISCONNECTING, null, null, transport, clientId, 0)
 {
 }
Beispiel #13
0
 public PublishTransportListener(BayeuxClient bayeuxClient)
 {
     this.bayeuxClient = bayeuxClient;
 }
Beispiel #14
0
 public UnconnectedState(BayeuxClient bayeuxClient, IDictionary<String, Object> handshakeFields, IDictionary<String, Object> advice, ClientTransport transport, String clientId, long backoff)
     : base(bayeuxClient, State.UNCONNECTED, handshakeFields, advice, transport, clientId, backoff)
 {
 }
Beispiel #15
0
 public ConnectedState(BayeuxClient bayeuxClient, IDictionary<String, Object> handshakeFields, IDictionary<String, Object> advice, ClientTransport transport, String clientId)
     : base(bayeuxClient, State.CONNECTED, handshakeFields, advice, transport, clientId, 0)
 {
 }
Beispiel #16
0
 public RehandshakingState(BayeuxClient bayeuxClient, IDictionary<String, Object> handshakeFields, ClientTransport transport, long backoff)
     : base(bayeuxClient, State.REHANDSHAKING, handshakeFields, null, transport, null, backoff)
 {
 }
Beispiel #17
0
 public HandshakingState(BayeuxClient bayeuxClient, IDictionary<String, Object> handshakeFields, ClientTransport transport)
     : base(bayeuxClient, State.HANDSHAKING, handshakeFields, null, transport, null, 0)
 {
 }
Beispiel #18
0
 public AbortedState(BayeuxClient bayeuxClient, ClientTransport transport)
     : base(bayeuxClient, transport)
 {
 }
Beispiel #19
0
 public AbortedState(BayeuxClient bayeuxClient, ClientTransport transport)
     : base(bayeuxClient, transport)
 {
 }
Beispiel #20
0
 public DisconnectTransportListener(BayeuxClient bayeuxClient)
     : base(bayeuxClient)
 {
 }
Beispiel #21
0
 public RehandshakingState(BayeuxClient bayeuxClient, IDictionary <String, Object> handshakeFields, ClientTransport transport, long backoff)
     : base(bayeuxClient, State.REHANDSHAKING, handshakeFields, null, transport, null, backoff)
 {
 }
Beispiel #22
0
 public BayeuxClientChannel(BayeuxClient bayeuxClient, ChannelId channelId)
     : base(channelId)
 {
     this.bayeuxClient = bayeuxClient;
 }
Beispiel #23
0
 public UnconnectedState(BayeuxClient bayeuxClient, IDictionary <String, Object> handshakeFields, IDictionary <String, Object> advice, ClientTransport transport, String clientId, long backoff)
     : base(bayeuxClient, State.UNCONNECTED, handshakeFields, advice, transport, clientId, backoff)
 {
 }
Beispiel #24
0
 public BayeuxClientState(BayeuxClient bayeuxClient, State type, IDictionary<String, Object> handshakeFields,
         IDictionary<String, Object> advice, ClientTransport transport, String clientId, long backoff)
 {
     this.bayeuxClient = bayeuxClient;
     this.type = type;
     this.handshakeFields = handshakeFields;
     this.advice = advice;
     this.transport = transport;
     this.clientId = clientId;
     this.backoff = backoff;
 }
Beispiel #25
0
 public PublishTransportListener(BayeuxClient bayeuxClient)
 {
     this.bayeuxClient = bayeuxClient;
 }
Beispiel #26
0
        /// <summary>
        /// Start Sally
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            /*
             *     We don't really have settings for Java and Jar in this case.
             *     if (!File.Exists(Properties.Settings.Default.Java) || !File.Exists(Properties.Settings.Default.Jar))
                   return;
             */
            activeDocuments.Add(css.CurrentWorkBook);
            //CurrentSpreadSheet.CurrentWorkBooks.Add(currentSpreadSheet.CurrentWorkBook);

            string semanticData = getSemanticData(); //add/remove string "old" from the parameter to use old/not use old format

            try
            {

                string fileName = getFileName();
                if (connected)
                {
                    WhoAmI whoami = WhoAmI.CreateBuilder().SetClientType(WhoAmI.Types.ClientType.Alex).SetDocumentType(WhoAmI.Types.DocType.Spreadsheet).SetEnvironmentType(WhoAmI.Types.EnvironmentType.Desktop).Build();
                    sendMessage("/service/alex/register", whoami);
                    sendMessage("/service/alex/semanticData", AlexData.CreateBuilder().SetData(semanticData).SetFileName(fileName).Build());
                }
                else
                {
                    String url = "http://localhost:8181/cometd";
                    //String url = "http://localhost:8181/cometd";
                    Dictionary<string, object> options = new Dictionary<string, object>();
                    List<Cometd.Client.Transport.ClientTransport> transport = new List<Cometd.Client.Transport.ClientTransport> { new LongPollingTransport(options) };
                    client = new BayeuxClient(url, transport);
                    client.getChannel("/**").addListener(new MessageLogger());
                    client.handshake();
                    client.getChannel("/service/**").addListener(new MessageParser());
                    client.getChannel("/do/**").addListener(new MessageParser());
                    client.getChannel("/get/**").addListener(new MessageParser());

                    //TODO
                    // Talk to Constantin about this.
                    client.waitFor(1500, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });
                    System.Threading.Thread.Sleep(5000);
                    SetFocusToExcel();
                    WhoAmI whoami = WhoAmI.CreateBuilder().SetClientType(WhoAmI.Types.ClientType.Alex).SetDocumentType(WhoAmI.Types.DocType.Spreadsheet).SetEnvironmentType(WhoAmI.Types.EnvironmentType.Desktop).Build();
                    sendMessage("/service/alex/register", whoami);
                    sendMessage("/service/alex/semanticdata", AlexData.CreateBuilder().SetData(semanticData).SetFileName(fileName).Build()); /// /service/sissi/loadSemanticData
                    connected = (client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED }) == BayeuxClient.State.CONNECTED);
                }
                if (connected)
                {
                    //Enable stop button and context menu items. disable start button.
                    button1.Enabled = false;
                    button2.Enabled = true;
                    UpdateState(AlexState.CONNECTED);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please save the document to use Sally.\n");
                Globals.ThisAddIn.Application.StatusBar = "Details for Alex's dev: " + ex.Message;

            }
        }
Beispiel #27
0
 public DisconnectTransportListener(BayeuxClient bayeuxClient)
     : base(bayeuxClient)
 {
 }
Beispiel #28
0
 /// <summary>
 /// Start Sally
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, RibbonControlEventArgs e)
 {
     /*
      *     We don't really have settings for Java and Jar in this case.
      *     if (!File.Exists(Properties.Settings.Default.Java) || !File.Exists(Properties.Settings.Default.Jar))
            return;
      */
     activeDocuments.Add(_book);
     try
     {
         string semanticData = getSemanticData();
         string fileName = getFileName();
         if (connected)
         {
             WhoAmI whoami = WhoAmI.CreateBuilder().SetClientType(WhoAmI.Types.ClientType.Alex_Old).SetDocumentType(WhoAmI.Types.DocType.Spreadsheet).SetEnvironmentType(WhoAmI.Types.EnvironmentType.Desktop).Build();
             sendMessage("/service/Alex_Old/register", whoami);
             sendMessage("/service/sissi/loadSemanticData", SemanticData.CreateBuilder().SetData(semanticData).SetFileName(fileName).Build());
         }
         else
         {
             String url = "http://localhost:8080/sally/cometd";
             //String url = "http://localhost:8080/cometd";
             Dictionary<string, object> options = new Dictionary<string, object>();
             List<Cometd.Client.Transport.ClientTransport> transport = new List<Cometd.Client.Transport.ClientTransport> { new LongPollingTransport(options) };
             client = new BayeuxClient(url, transport);
             client.getChannel("/**").addListener(new MessageLogger());
             client.handshake();
             client.getChannel("/**").addListener(new MessageParser());
             //TODO
             // Talk to Constantin about this.
             client.waitFor(1500, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });
             System.Threading.Thread.Sleep(5000);
             SetFocusToExcel();
             WhoAmI whoami = WhoAmI.CreateBuilder().SetClientType(WhoAmI.Types.ClientType.Alex_Old).SetDocumentType(WhoAmI.Types.DocType.Spreadsheet).SetEnvironmentType(WhoAmI.Types.EnvironmentType.Desktop).Build();
             sendMessage("/service/Alex_Old/register", whoami);
             sendMessage("/service/sissi/loadSemanticData", SemanticData.CreateBuilder().SetData(semanticData).SetFileName(fileName).Build());
             connected = (client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED }) == BayeuxClient.State.CONNECTED);
         }
         if (connected)
         {
             button1.Enabled = false;
             button2.Enabled = true;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("You must save the document before starting Sally\n" + ex.Message);
     }
 }