Exemple #1
0
        public virtual Task AddURLToClientAsync(string uRL, Guid clientId)
        {
            if (clientId == Guid.Empty)
            {
                throw new ArgumentNullException("clientId");
            }

            if (uRL == "")
            {
                throw new ArgumentNullException("uRL");
            }

            Client _client = FindByURL(uRL).Result;

            if (_client == null)
            {
                return(Task.Factory.StartNew(() =>
                {
                    ClientURL _uRL = new ClientURL();
                    _uRL.Id = Guid.NewGuid();
                    _uRL.ClientId = clientId;
                    _uRL.URL = uRL;
                    using (IDbConnection connection = CurrentContext.OpenConnection())
                        connection.Execute("insert into auth_ClientURLs(Id, ClientId, URL) values(@Id, @ClientId, @URL)", new { Id = _uRL.Id, ClientId = _uRL.ClientId, URL = _uRL.URL });
                }));
            }
            else
            {
                throw new Exception("URL already assigned to " + _client.ClientName);
            }
        }
Exemple #2
0
        private void contextClick_Url(object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;

            if (item == null)
            {
                return;
            }
            ClientTweet tweet = selectTweet;

            if (tweet == null)
            {
                return;
            }

            for (int i = 0; i < tweet.listUrl.Count; i++)
            {
                ClientURL url = item.Tag as ClientURL;
                if (url == null)
                {
                    continue;
                }
                if (tweet.listUrl[i].expanded_url == url.expanded_url)
                {
                    System.Diagnostics.Process.Start(tweet.listUrl[i].expanded_url);
                    TweetInstence.AddTweet(eTweetPanel.eOpen, tweet);
                    break;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Populates the SinkURL and BaseSinkURL properties.
        /// If the $PortRange macro is defined, a port is selected, and the macro is expanded.
        /// </summary>
        /// <remarks>
        /// does not expand $InterfaceAddress for the BaseSinkURL property
        /// </remarks>
        /// <param name="configSinkAddress">the sink address for this source, from the configuration file</param>
        /// <param name="interfaceAddress">The interface address that the graph is/will be opened on</param>
        /// <param name="protocol">protocol that will be used</param>
        protected void BuildClientURL(SinkProtocolType protocol)
        {
            this.SinkProtocolType = protocol;
            if (SourceConfig.SinkAddress == null)
            {
                if (SourceConfig.SinkAddress != null)
                {
                    ClientURL = SourceConfig.SinkAddress;
                }
                else
                {
                    throw new Exception("No ClientURL or SinkAddress defined for Source " + SourceConfig.SourceName);
                }
            }
            else
            {
                ClientURL = SourceConfig.SinkAddress;
            }
            BaseClientURL = ClientURL;

            if (ClientURL.Contains(InterfaceAddressMacro))
            {
                ClientURL = ExpandInterfaceAddressMacro(ClientURL, OpenGraphRequest.InterfaceAddress);
            }
            if (ClientURL.Contains(PortRangeMacro))
            {
                List <int> allocedPorts = GetAllocatedPorts();

                int    pos             = ClientURL.LastIndexOf(PortRangeMacro);
                string prefix          = ClientURL.Substring(0, pos);
                string suffix          = ClientURL.Substring(pos);
                int    rangeNumbersPos = suffix.LastIndexOf(@"(") + 1;
                if (rangeNumbersPos > 0)
                {
                    int      rangeNumbersLength = suffix.Length - rangeNumbersPos - 1;
                    string   rangeNumbers       = suffix.Substring(rangeNumbersPos, rangeNumbersLength);
                    string[] parts    = rangeNumbers.Split(new char[] { '-' });
                    int      portLow  = Convert.ToInt32(parts[0]);
                    int      portHigh = Convert.ToInt32(parts[1]);
                    int      testPort = 0;
                    for (testPort = portLow; testPort <= portHigh; testPort++)
                    {
                        if ((!allocedPorts.Contains(testPort)) && IsPortAvailable(protocol, OpenGraphRequest.InterfaceAddress, testPort))
                        {
                            break;
                        }
                    }
                    if (testPort <= portHigh)
                    {
                        AppLogger.Message(String.Format("PortRange specified ({0},{1}) -- first available port was {2}", portLow, portHigh, testPort));
                        ClientURL = prefix + testPort.ToString();

                        BaseClientURL = BaseClientURL.Substring(0, BaseClientURL.LastIndexOf(@"$PortRange")) + testPort.ToString();
                    }
                    else
                    {
                        throw new Exception(String.Format("No ports for protocol \"{0}\" available between {1} and {2}!", protocol, portLow, portHigh));
                    }
                }
            }
            AppLogger.Message(String.Format("   BaseClientURL = {0}   ClientURL = {1}", BaseClientURL, ClientURL));
        }