Ejemplo n.º 1
0
        private string GetEnvironment(DataFlowContext context, Dictionary <string, object> properties,
                                      ValueSelector field,
                                      int index)
        {
            string value;

            switch (field.Expression?.ToUpper())
            {
            case Const.EnvironmentNames.EntityIndex:
            {
                value = index.ToString();
                break;
            }

            case Const.EnvironmentNames.Guid:
            {
                value = Guid.NewGuid().ToString();
                break;
            }

            case Const.EnvironmentNames.Date:
            case Const.EnvironmentNames.Today:
            {
                value = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd");
                break;
            }

            case Const.EnvironmentNames.Datetime:
            case Const.EnvironmentNames.Now:
            {
                value = DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss");
                break;
            }

            case Const.EnvironmentNames.Month:
            {
                value = DateTimeHelper.FirstDayOfMonth.ToString("yyyy-MM-dd");
                break;
            }

            case Const.EnvironmentNames.Monday:
            {
                value = DateTimeHelper.Monday.ToString("yyyy-MM-dd");
                break;
            }

            case Const.EnvironmentNames.SpiderId:
            {
                value = context.Request.Owner;
                break;
            }

            case Const.EnvironmentNames.RequestHash:
            {
                value = context.Request.Hash;
                break;
            }

            default:
            {
                value = string.IsNullOrWhiteSpace(field.Expression) ? null :
                        properties.ContainsKey(field.Expression) ? properties[field.Expression]?.ToString() : null;
                break;
            }
            }

            return(value);
        }
Ejemplo n.º 2
0
        private string GetEnvironment(DataContext context, Dictionary <string, object> properties, ValueSelector field,
                                      int index)
        {
            string value;

            switch (field.Expression)
            {
            case "ENTITY_INDEX":
            {
                value = index.ToString();
                break;
            }

            case "GUID":
            {
                value = Guid.NewGuid().ToString();
                break;
            }

            case "DATE":
            case "TODAY":
            {
                value = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd");
                break;
            }

            case "DATETIME":
            case "NOW":
            {
                value = DateTimeOffset.Now.ToString("yyyy-MM-dd HH:mm:ss");
                break;
            }

            case "MONTH":
            {
                value = DateTime2.FirstDayOfMonth.ToString("yyyy-MM-dd");
                break;
            }

            case "MONDAY":
            {
                value = DateTime2.Monday.ToString("yyyy-MM-dd");
                break;
            }

            case "SPIDER_ID":
            {
                value = context.Request.Owner;
                break;
            }

            case "REQUEST_HASH":
            {
                value = context.Request.Hash;
                break;
            }

            default:
            {
                value = properties.ContainsKey(field.Expression) ? properties[field.Expression].ToString() : null;
                break;
            }
            }

            return(value);
        }