コード例 #1
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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: HakanL/Auto-Deployment
        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);
            }
        }
コード例 #3
0
ファイル: Alex_Old.cs プロジェクト: risavkarna/Sally
 /// <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);
     }
 }
コード例 #4
0
ファイル: Alex.cs プロジェクト: risavkarna/Sally
        /// <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;

            }
        }