private void Validate()
        {
            string message = "";

            StringBuilder messageBuilder = new StringBuilder(100);
            string        huburl         = HubUrl.Trim();
            string        packagesRepo   = PackagesRepoUrl.Trim();

            if (string.IsNullOrEmpty(packagesRepo))
            {
                messageBuilder.AppendLine("PackagesRepoUrl is required");
            }

            if (String.IsNullOrEmpty(huburl))
            {
                List <string> operationList = new List <string>(3);
                if (DeployHubBdio || CreateHubReport || CheckPolicies)
                {
                    messageBuilder.Append("Cannot perform the following operations because hub_url is empty: ");
                }

                if (DeployHubBdio)
                {
                    operationList.Add("deploy BDIO");
                }

                if (CreateHubReport)
                {
                    operationList.Add("create risk report");
                }

                if (CheckPolicies)
                {
                    operationList.Add("check policies");
                }

                if (operationList.Count > 0)
                {
                    messageBuilder.AppendLine(String.Join(", ", operationList));
                }
            }

            message = messageBuilder.ToString();

            if (!String.IsNullOrEmpty(message))
            {
                throw new BlackDuckIntegrationException(message);
            }
        }
        public void Setup()
        {
            string projectDirectory = Directory.GetParent(ProjectPath).FullName;

            if (String.IsNullOrWhiteSpace(PackagesConfigPath))
            {
                PackagesConfigPath = CreateProjectPackageConfigPath(projectDirectory);
            }

            if (!String.IsNullOrWhiteSpace(HubUrl.Trim()))
            {
                // Estabilish authenticated connection
                HubServerConfig hubServerConfig = BuildHubServerConfig();
                RestConnection  restConnection  = new CredentialsResetConnection(hubServerConfig);
                Setup(restConnection);
            }

            if (String.IsNullOrWhiteSpace(OutputDirectory))
            {
                string currentDirectory = Directory.GetCurrentDirectory();
                OutputDirectory = $"{currentDirectory}{Path.DirectorySeparatorChar}{DEFAULT_OUTPUT_DIRECTORY}";
            }

            if (String.IsNullOrWhiteSpace(HubProjectName))
            {
                HubProjectName = Path.GetFileNameWithoutExtension(ProjectPath);
            }

            if (String.IsNullOrWhiteSpace(HubVersionName))
            {
                HubVersionName = GetProjectAssemblyVersion(projectDirectory);
            }

            // Set helper properties
            BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper();

            BdioId = bdioPropertyHelper.CreateBdioId(HubProjectName, HubVersionName);
        }
Exemplo n.º 3
0
        public ActionResult PushData(FormCollection collection)
        {
            HubUrl url = new HubUrl();

            url.InDate = DateTime.Now;

            Dictionary <string, string> dic = new Dictionary <string, string>();



            foreach (string key in collection.AllKeys)
            {
                dic[key] = HttpUtility.HtmlDecode(collection[key]);
            }

            dic["status"] = LogStatus.Hub.ToString("D");

            url.ProjectKey = dic["key"];
            url.Status     = dic["status"];
            url.Url        = dic.Keys.Contains("url") ? dic["url"] : "";


            string message = JsonConvert.SerializeObject(dic);

            url.Body = message;

            string  severity = "";
            LogType type     = (LogType)Enum.Parse(typeof(LogType), dic["type"]);

            switch (type)
            {
            case LogType.ExceptionLog:
                severity = "exception";
                break;

            case LogType.OperateLog:
                severity = "operate";
                break;

            case LogType.SystemLog:
                severity = "system";
                break;

            case LogType.Normal:
                severity = "normal";
                break;
            }

            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "direct_" + dic["key"].ToLower(),
                                            type: "direct");


                    var body = Encoding.UTF8.GetBytes(message);
                    channel.BasicPublish(exchange: "direct_" + dic["key"].ToLower(),
                                         routingKey: severity,
                                         basicProperties: null,
                                         body: body);
                }

            url.Type    = type.ToString();
            url.MQ      = severity;
            url.OutDate = DateTime.Now;

            InUrl.Add(url);



            return(new ContentResult()
            {
                Content = "success"
            });
        }