Exemple #1
0
        public Tree(string apiKey)
        {
            Endpoint = new Endpoint(new ApiKey(apiKey));
            Helper = new DynamicHelper(Endpoint);
            List = new DynamicList(Endpoint);
            Campaign = new DynamicCampaign(Endpoint);
            Template = new DynamicTemplate(Endpoint);

            _executor = new RequestExecutor(Endpoint.Uri);
        }
        public static PreCondition CreatePreCondition(dynamic model, OutboundRulesSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            if (string.IsNullOrEmpty(DynamicHelper.Value(model.name)))
            {
                throw new ApiArgumentException("name");
            }

            var precondition = section.PreConditions.CreateElement();

            SetPreCondition(model, precondition, section);

            return(precondition);
        }
        public static TagsElement CreateCustomTags(dynamic model, OutboundRulesSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            if (string.IsNullOrEmpty(DynamicHelper.Value(model.name)))
            {
                throw new ApiArgumentException("name");
            }

            TagsElement tags = section.Tags.CreateElement();

            SetCustomTags(model, tags, section);

            return(tags);
        }
Exemple #4
0
        public static bool CreateAppPool(HttpClient client, string testPool, out string id)
        {
            id = null;

            HttpContent         content  = new StringContent(TEST_APP_POOL, Encoding.UTF8, "application/json");
            HttpResponseMessage response = client.PostAsync(APP_POOLS_URL, content).Result;

            if (!Globals.Success(response))
            {
                return(false);
            }

            dynamic appPool = JsonConvert.DeserializeObject <JObject>(response.Content.ReadAsStringAsync().Result);

            id = DynamicHelper.Value(appPool.id);

            return(true);
        }
        public static MimeMap UpdateMimeMap(dynamic model, MimeMap mimeMap, StaticContentSection section)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (mimeMap == null)
            {
                throw new ArgumentNullException(nameof(mimeMap));
            }

            if (string.IsNullOrEmpty(mimeMap.FileExtension))
            {
                throw new ArgumentNullException("mimeMap.FileExtension");
            }

            string fileExtension = DynamicHelper.Value(model.file_extension);
            string mimeType      = DynamicHelper.Value(model.mime_type);

            if (!string.IsNullOrEmpty(fileExtension))
            {
                fileExtension = fileExtension.StartsWith(".") ? fileExtension : "." + fileExtension;

                if (!fileExtension.Equals(mimeMap.FileExtension, StringComparison.OrdinalIgnoreCase) &&
                    section.MimeMaps.Any(m => fileExtension.Equals(m.FileExtension, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new AlreadyExistsException("file_extension");
                }
            }

            try {
                mimeMap.FileExtension = fileExtension ?? mimeMap.FileExtension;
                mimeMap.MimeType      = mimeType ?? mimeMap.MimeType;
            }
            catch (FileLoadException e) {
                throw new LockedException(MimeTypesGlobals.StaticContentSectionName, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            return(mimeMap);
        }
Exemple #6
0
        public object Post([FromBody] dynamic model)
        {
            QueryStringRule    queryString = null;
            Site               site        = null;
            RequestFilteringId reqId       = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_filtering == null)
            {
                throw new ApiArgumentException("request_filtering");
            }
            if (!(model.request_filtering is JObject))
            {
                throw new ApiArgumentException("request_filtering");
            }
            string reqUuid = DynamicHelper.Value(model.request_filtering.id);

            if (reqUuid == null)
            {
                throw new ApiArgumentException("request_filtering.id");
            }

            reqId = new RequestFilteringId(reqUuid);

            site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value);

            string configPath = ManagementUnit.ResolveConfigScope(model);
            RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath);

            queryString = QueryStringsHelper.CreateQueryString(model);

            QueryStringsHelper.AddQueryString(queryString, section);

            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic qs = QueryStringsHelper.ToJsonModel(queryString, site, reqId.Path);

            return(Created(QueryStringsHelper.GetLocation(qs.id), qs));
        }
        public static void UpdateFeatureSettings(dynamic model, StaticContentSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (section == null)
            {
                throw new ArgumentException("section");
            }

            if (model.client_cache != null)
            {
                dynamic cache = model.client_cache;

                DynamicHelper.If((object)cache.max_age, 0, (long)TimeSpan.MaxValue.TotalMinutes, v => section.ClientCache.CacheControlMaxAge = TimeSpan.FromMinutes(v));
                DynamicHelper.If((object)cache.control_mode, v => section.ClientCache.CacheControlMode     = JsonToCacheControlMode(v));
                DynamicHelper.If((object)cache.control_custom, v => section.ClientCache.CacheControlCustom = v);
                DynamicHelper.If <bool>((object)cache.set_e_tag, v => section.ClientCache.SetETag          = v);
                DynamicHelper.If((object)cache.http_expires, v => {
                    DateTime httpExpires;
                    if (!DateTime.TryParseExact(v, "r", CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out httpExpires))
                    {
                        throw new ApiArgumentException("http_expires");
                    }

                    section.ClientCache.HttpExpires = httpExpires;
                });
            }

            DynamicHelper.If((object)model.default_doc_footer, v => section.DefaultDocFooter = v);
            DynamicHelper.If <bool>((object)model.is_doc_footer_file_name, v => {
                if (section.IsDocFooterFileName != v)
                {
                    section.IsDocFooterFileName = v;
                }
            });
            DynamicHelper.If <bool>((object)model.enable_doc_footer, v => section.EnableDocFooter = v);

            if (model.metadata != null)
            {
                DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
            }
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            // Set settings
            Site site = SiteHelper.UpdateSite(new SiteId(id).Id, model);

            if (site == null)
            {
                return(NotFound());
            }

            // Start/Stop
            if (model.status != null)
            {
                Status status = DynamicHelper.To <Status>(model.status);
                try {
                    switch (status)
                    {
                    case Status.Stopped:
                        site.Stop();
                        break;

                    case Status.Started:
                        site.Start();
                        break;
                    }
                }
                catch (COMException e) {
                    // If site is fresh and status is still unknown then COMException will be thrown when manipulating status
                    throw new ApiException("Error setting site status", e);
                }
                catch (ServerManagerException e) {
                    throw new ApiException(e.Message, e);
                }
            }

            // Update changes
            ManagementUnit.Current.Commit();

            // Refresh data
            site = ManagementUnit.ServerManager.Sites[site.Name];

            return(SiteHelper.ToJsonModel(site, Context.Request.GetFields()));
        }
        public object Post(dynamic model)
        {
            TraceRule            rule  = null;
            Site                 site  = null;
            HttpRequestTracingId hrtId = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_tracing == null)
            {
                throw new ApiArgumentException("request_tracing");
            }
            if (!(model.request_tracing is JObject))
            {
                throw new ApiArgumentException("request_tracing", ApiArgumentException.EXPECTED_OBJECT);
            }
            string hrtUuid = DynamicHelper.Value(model.request_tracing.id);

            if (hrtUuid == null)
            {
                throw new ApiArgumentException("request_tracing.id");
            }

            hrtId = new HttpRequestTracingId(hrtUuid);

            site = hrtId.SiteId == null ? null : SiteHelper.GetSite(hrtId.SiteId.Value);

            string configPath = ManagementUnit.ResolveConfigScope(model);

            rule = RulesHelper.CreateRule(model, site, hrtId.Path, configPath);

            var section = Helper.GetTraceFailedRequestsSection(site, hrtId.Path, configPath);

            RulesHelper.AddRule(rule, section);

            ManagementUnit.Current.Commit();

            dynamic r = RulesHelper.ToJsonModel(rule, site, hrtId.Path);

            return(Created(RulesHelper.GetLocation(r.id), r));
        }
Exemple #10
0
        public object Post([FromBody] dynamic model)
        {
            HiddenSegment      segment = null;
            Site               site    = null;
            RequestFilteringId reqId   = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_filtering == null)
            {
                throw new ApiArgumentException("request_filtering");
            }
            if (!(model.request_filtering is JObject))
            {
                throw new ApiArgumentException("request_filtering");
            }
            string reqUuid = DynamicHelper.Value(model.request_filtering.id);

            if (reqUuid == null)
            {
                throw new ApiArgumentException("request_filtering.id");
            }

            // Get the feature id
            reqId = new RequestFilteringId(reqUuid);

            site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value);

            string configPath = ManagementUnit.ResolveConfigScope(model);
            RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath);

            segment = HiddenSegmentsHelper.CreateSegment(model, section);

            HiddenSegmentsHelper.AddSegment(segment, section);

            ManagementUnit.Current.Commit();

            dynamic hidden_segment = HiddenSegmentsHelper.ToJsonModel(segment, site, reqId.Path);

            return(Created(HiddenSegmentsHelper.GetLocation(hidden_segment.id), hidden_segment));
        }
Exemple #11
0
        public static bool GetIsDynamicBound(this IEnumerable collection)
        {
            var enumerator = collection.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return(false);
            }

            var record = enumerator.Current;

            if (record != null)
            {
                var isDynamicBound = DynamicHelper.CheckIsDynamicObject(record.GetType());
                return(isDynamicBound);
            }

            return(false);
        }
Exemple #12
0
        public static InboundRule CreateRule(dynamic model, InboundRulesSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            if (string.IsNullOrEmpty(DynamicHelper.Value(model.name)))
            {
                throw new ApiArgumentException("name");
            }

            if (string.IsNullOrEmpty(DynamicHelper.Value(model.pattern)))
            {
                throw new ApiArgumentException("pattern");
            }

            if (model.action == null)
            {
                throw new ApiArgumentException("action");
            }

            if (!(model.action is JObject))
            {
                throw new ApiArgumentException("action", ApiArgumentException.EXPECTED_OBJECT);
            }

            if (string.IsNullOrEmpty(DynamicHelper.Value(model.action.url)))
            {
                throw new ApiArgumentException("action.url");
            }

            var rule = (InboundRule)section.InboundRules.CreateElement();

            //
            // Defaults
            rule.PatternSyntax = PatternSyntax.ECMAScript;
            rule.Action.Type   = ActionType.Rewrite;

            SetRule(model, rule, section);

            return(rule);
        }
        public static GlobalModule UpdateGlobalModule(GlobalModule globalModule, dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (globalModule == null)
            {
                throw new ArgumentNullException("globalModule");
            }

            Configuration config = ManagementUnit.GetConfiguration(null, null);

            GlobalModulesCollection globalCollection = GetGlobalModulesCollection();
            ModuleCollection        serverCollection = GetModulesCollection(null, null);

            Module action = null;

            string image = DynamicHelper.Value(model.image);

            if (image != null)
            {
                AssertCanUseImage(ref image);
                globalModule.Image = image;
            }

            string preCondition = globalModule.PreCondition;

            BitnessUtility.AppendBitnessPreCondition(ref preCondition, image);
            globalModule.PreCondition = preCondition;

            // If the global module is present in the server modules list then we
            // update the precondition of that entry as well.
            if (ExistsModule(globalModule.Name, serverCollection, out action))
            {
                if (ConfigurationUtility.ShouldPersist(action.PreCondition, globalModule.PreCondition))
                {
                    action.PreCondition = globalModule.PreCondition;
                }
            }

            return(globalModule);
        }
Exemple #14
0
        public object Post(dynamic model)
        {
            TraceProviderDefinition provider = null;
            Site site = null;
            HttpRequestTracingId hrtId = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_tracing == null)
            {
                throw new ApiArgumentException("request_tracing");
            }
            if (!(model.request_tracing is JObject))
            {
                throw new ApiArgumentException("request_tracing", ApiArgumentException.EXPECTED_OBJECT);
            }
            string hrtUuid = DynamicHelper.Value(model.request_tracing.id);

            if (hrtUuid == null)
            {
                throw new ApiArgumentException("request_tracing.id");
            }

            hrtId = new HttpRequestTracingId(hrtUuid);

            site = hrtId.SiteId == null ? null : SiteHelper.GetSite(hrtId.SiteId.Value);

            string configPath = ManagementUnit.ResolveConfigScope(model);
            var    section    = Helper.GetTraceProviderDefinitionSection(site, hrtId.Path, configPath);

            provider = ProvidersHelper.CreateProvider(model, section);

            ProvidersHelper.AddProvider(provider, section);

            ManagementUnit.Current.Commit();

            dynamic p = ProvidersHelper.ToJsonModel(provider, site, hrtId.Path);

            return(Created(ProvidersHelper.GetLocation(p.id), p));
        }
        public object Post([FromBody] dynamic model)
        {
            HeaderLimit        headerLimit = null;
            Site               site        = null;
            RequestFilteringId reqId       = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.request_filtering == null)
            {
                throw new ApiArgumentException("request_filtering");
            }
            if (!(model.request_filtering is JObject))
            {
                throw new ApiArgumentException(String.Empty, "request_filtering");
            }
            string reqUuid = DynamicHelper.Value(model.request_filtering.id);

            if (reqUuid == null)
            {
                throw new ApiArgumentException("request_filtering.id");
            }

            reqId = new RequestFilteringId(reqUuid);

            site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value);

            string configPath = ManagementUnit.ResolveConfigScope(model);
            RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath);

            headerLimit = HeaderLimitsHelper.CreateHeaderLimit(model, section);

            HeaderLimitsHelper.AddHeaderLimit(headerLimit, section);

            ManagementUnit.Current.Commit();

            dynamic header_limit = HeaderLimitsHelper.ToJsonModel(headerLimit, site, reqId.Path);

            return(Created(HeaderLimitsHelper.GetLocation(header_limit.id), header_limit));
        }
Exemple #16
0
        public static TraceProviderDefinition UpdateProvider(TraceProviderDefinition provider, dynamic model, TraceProviderDefinitionsSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            string name = DynamicHelper.Value(model.name);

            if (name != null &&
                !name.Equals(provider.Name) &&
                section.TraceProviderDefinitions.Any(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new AlreadyExistsException("name");
            }

            Guid guid;
            var  g = DynamicHelper.Value(model.guid);

            if (Guid.TryParse(g, out guid) &&
                !guid.Equals(provider.Guid) &&
                section.TraceProviderDefinitions.Any(prov => prov.Guid.Equals(guid)))
            {
                throw new AlreadyExistsException("guid");
            }

            try {
                SetProvider(provider, model);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            return(provider);
        }
Exemple #17
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            ModulesId modulesId = new ModulesId(id);

            Site site = modulesId.SiteId == null ? null : SiteHelper.GetSite(modulesId.SiteId.Value);

            if (modulesId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            ModuleHelper.EnsureValidScope(site, modulesId.Path);

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Check for config_scope
            string         configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            ModulesSection section    = ModuleHelper.GetModulesSection(site, modulesId.Path, configPath);

            try {
                DynamicHelper.If <bool>((object)model.run_all_managed_modules_for_all_requests, v => section.RunAllManagedModulesForAllRequests = v);

                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
                }
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            ManagementUnit.Current.Commit();

            return(ModuleHelper.ModuleFeatureToJsonModel(site, modulesId.Path));
        }
Exemple #18
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Decode default document id from uuid parameter
            DefaultDocumentId docId = new DefaultDocumentId(id);

            Site site = docId.SiteId == null ? null : SiteHelper.GetSite(docId.SiteId.Value);

            if (docId.SiteId != null && site == null)
            {
                // The document id specified a site but we couldn't find it,
                // therefore we can't get the settings for that site
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath);

            try {
                // Handle patching of any feature settings
                DynamicHelper.If <bool>((object)model.enabled, v => section.Enabled = v);

                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
                }
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            ManagementUnit.Current.Commit();

            return(DefaultDocumentHelper.ToJsonModel(site, docId.Path));
        }
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.static_content == null)
            {
                throw new ApiArgumentException("static_content");
            }
            if (!(model.static_content is JObject))
            {
                throw new ApiArgumentException("static_content");
            }
            string staticContentUuid = DynamicHelper.Value(model.static_content.id);

            if (staticContentUuid == null)
            {
                throw new ApiArgumentException("static_content.id");
            }

            // Get the feature id
            StaticContentId staticContentId = new StaticContentId(staticContentUuid);

            Site site = staticContentId.SiteId == null ? null : SiteHelper.GetSite(staticContentId.SiteId.Value);

            string configPath            = ManagementUnit.ResolveConfigScope(model);
            StaticContentSection section = StaticContentHelper.GetSection(site, staticContentId.Path, configPath);

            // Create mime map
            MimeMap mimeMap = MimeMapHelper.CreateMimeMap(model, section);

            // Add it to the config file
            MimeMapHelper.AddMimeMap(mimeMap, section);

            // Save changes
            ManagementUnit.Current.Commit();


            // Show new mime map
            return(MimeMapHelper.ToJsonModel(mimeMap, site, staticContentId.Path));
        }
        private void CustomDocumentListDisplayForm_Load(object sender, EventArgs e)
        {
            lblCannotSaveHint.Text = "";
            Text = "Configure Document Listing settings";
            tbDefaultGlobalFieldName.Text = Settings.Default.CustomDocumentDisplayIdentifier;

            gbCustom.Text = string.Format("Custom Document Listing settings for {0}/{1}", _databaseId, _documentCollectionId);

            _propertyKeysForDocument = DynamicHelper.GetPropertyKeysForDynamic(_firstDocument);
            foreach (var prop in _propertyKeysForDocument)
            {
                cbSortFields.Items.Add(prop);
            }

            _setting = _customDocumentListDisplayManager.FindCustomDocumentListDisplay(_hostName, _databaseId, _documentCollectionId);

            SetStatusForSettingFields(_setting != null);

            SetAllSettingFields();
        }
Exemple #21
0
 protected internal override object ConvertBinding(Type type)
 {
     if (type.IsSubclassOf(typeof(Delegate)))
     {
         return(Capstones.LuaLib.CapsLuaDelegateGenerator.CreateDelegate(type, this));
     }
     if (type == typeof(bool))
     {
         if (L != IntPtr.Zero && Refid != 0)
         {
             L.getref(Refid);
             bool rv = !L.isnoneornil(-1) && !(L.isboolean(-1) && !L.toboolean(-1));
             L.pop(1);
             return(rv);
         }
         return(false);
     }
     DynamicHelper.LogInfo("__convert(" + type.ToString() + ") meta-method Not Implemented.");
     return(null);
 }
Exemple #22
0
 public override object[] Call(params object[] args)
 {
     if (L != IntPtr.Zero)
     {
         if (Refid != 0)
         {
             L.getref(Refid);
             return(L.PushArgsAndCall(args));
         }
         else
         {
             DynamicHelper.LogInfo("luafunc : null ref");
         }
     }
     else
     {
         DynamicHelper.LogInfo("luafunc : null state.");
     }
     return(null);
 }
        public static HiddenSegment CreateSegment(dynamic model, RequestFilteringSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            string segmentName = DynamicHelper.Value(model.segment);

            if (string.IsNullOrEmpty(segmentName))
            {
                throw new ApiArgumentException("segment");
            }

            HiddenSegment segment = section.HiddenSegments.CreateElement();

            segment.Segment = segmentName;

            return(segment);
        }
Exemple #24
0
        public static TraceRule CreateRule(dynamic model, Site site, string path, string configPath = null)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            if (string.IsNullOrEmpty(DynamicHelper.Value(model.path)))
            {
                throw new ApiArgumentException("path");
            }

            var section = Helper.GetTraceFailedRequestsSection(site, path, configPath);

            var rule = section.TraceRules.CreateElement();

            SetRule(rule, model, site, path);

            return(rule);
        }
Exemple #25
0
        private void TransformAppSettings()
        {
            string filePath = Path.Combine(_basePath, APPSETTINGS_NAME);

            try {
                dynamic configObject = JsonConvert.DeserializeObject(File.ReadAllText(filePath));
                string  id           = DynamicHelper.Value(configObject.host_id);

                if (string.IsNullOrEmpty(id))
                {
                    id = configObject.host_id = Guid.NewGuid().ToString();
                }

                File.WriteAllText(filePath, JsonConvert.SerializeObject(configObject, Formatting.Indented));
            }
            catch (Exception e) {
                Log.Fatal(e, "");
                throw;
            }
        }
        public static Rule CreateRule(dynamic model, AuthorizationSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RuleAccessType?accessType = DynamicHelper.To <RuleAccessType>(model.access_type);

            if (accessType == null)
            {
                throw new ApiArgumentException("access_type");
            }

            Rule rule = section.Rules.CreateElement();

            SetRule(rule, model);

            return(rule);
        }
Exemple #27
0
 public override object[] Call(params object[] args)
 {
     if (L != IntPtr.Zero)
     {
         if (L.isfunction(StackPos))
         {
             L.pushvalue(StackPos);
             return(L.PushArgsAndCall(args));
         }
         else
         {
             DynamicHelper.LogInfo("luafunc : the index is not a func.");
         }
     }
     else
     {
         DynamicHelper.LogInfo("luafunc : null state.");
     }
     return(null);
 }
Exemple #28
0
        /// <summary>
        /// Gets the list ids query condition.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <param name="entityIds">The entity ids.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="param">The parameter.</param>
        /// <param name="alias">The alias.</param>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        public string GetListIdsQueryCondition <K>(IList <K> entityIds, string parameters, object param, string alias, string field) where K : struct
        {
            var ids = entityIds.ToList();

            var condition = new StringBuilder();

            condition.Append(ConditionStartBracketTemplate);

            if (ids.Count < DbConstants.MaxParametersPerCommand)
            {
                while (ids.Any())
                {
                    DynamicHelper.SetProperty(
                        param,
                        String.Concat(parameters, ids.Count),
                        ids.Take(DbConstants.MaxParametersPerCommand).ToList());

                    condition.Append(String.Format(ConditionInTemplate, alias, field, "@" + String.Concat(parameters, ids.Count)));
                    ids.RemoveRange(
                        0,
                        ids.Count > DbConstants.MaxParametersPerCommand ? DbConstants.MaxParametersPerCommand : ids.Count);
                    if (ids.Any())
                    {
                        condition.Append(ConditionPartialOrTemplate);
                    }
                }
                condition.Append(ConditionEndBracketTemplate);
                return(condition.ToString());
            }

            for (var i = 0; i < ids.Count; i++)
            {
                condition.Append(i == 0
                    ? String.Format(ConditionSelectInTableTemplate, ids[i])
                    : String.Format(ConditionStartSelectInTableTemplate, ids[i]));
            }
            condition.Append(String.Format(ConditionEndSelectInTableTemplate, parameters));
            condition.Append(ConditionEndBracketTemplate);

            return(String.Format(ConditionInQueryTemplate, alias, field, condition));
        }
Exemple #29
0
        public static TraceProviderDefinition CreateProvider(dynamic model, TraceProviderDefinitionsSection section)
        {
            //
            // model
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            //
            // name
            string name = DynamicHelper.Value(model.name);

            if (string.IsNullOrEmpty(name))
            {
                throw new ApiArgumentException("name");
            }

            //
            // guid
            Guid   guid;
            string g = DynamicHelper.Value(model.guid);

            if (!Guid.TryParse(g, out guid))
            {
                throw new ApiArgumentException("guid");
            }

            //
            // areas
            if (model.areas == null)
            {
                throw new ApiArgumentException("areas");
            }

            var provider = section.TraceProviderDefinitions.CreateElement();

            SetProvider(provider, model);

            return(provider);
        }
Exemple #30
0
        private static void SetProvider(TraceProviderDefinition provider, dynamic model)
        {
            DynamicHelper.If((object)model.name, v => provider.Name = v);
            DynamicHelper.If((object)model.guid, v => {
                Guid guid;
                if (!Guid.TryParse(v, out guid))
                {
                    throw new ApiArgumentException("guid");
                }

                provider.Guid = guid;
            });

            if (model.areas != null)
            {
                if (!(model.areas is JArray))
                {
                    throw new ApiArgumentException("areas", ApiArgumentException.EXPECTED_ARRAY);
                }

                IEnumerable <dynamic> areas = model.areas;
                provider.Areas.Clear();
                long uniqueFlag = 1;

                foreach (var area in areas)
                {
                    string a = DynamicHelper.Value(area);

                    if (a == null)
                    {
                        throw new ApiArgumentException("areas");
                    }

                    var elem = provider.Areas.CreateElement();
                    elem.Name   = a;
                    elem.Value  = uniqueFlag;
                    uniqueFlag *= 2;
                    provider.Areas.Add(elem);
                }
            }
        }
Exemple #31
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.http_response_headers == null)
            {
                throw new ApiArgumentException("http_response_headers");
            }
            if (!(model.http_response_headers is JObject))
            {
                throw new ApiArgumentException("http_response_headers");
            }

            string uuid = DynamicHelper.Value(model.http_response_headers.id);

            if (uuid == null)
            {
                throw new ApiArgumentException("http_response_headers.id");
            }

            HttpResponseHeadersId id = new HttpResponseHeadersId(uuid);

            Site site = id.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value);

            string configPath           = ManagementUnit.ResolveConfigScope(model);
            HttpProtocolSection section = HttpResponseHeadersHelper.GetSection(site, id.Path, configPath);

            NameValueConfigurationElement header = CustomHeadersHelper.Create(model, section);

            CustomHeadersHelper.Add(header, section);

            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic ch = CustomHeadersHelper.ToJsonModel(header, site, id.Path);

            return(Created(CustomHeadersHelper.GetLocation(ch.id), ch));
        }
Exemple #32
0
 internal DynamicDictionaryMetaObject(
     Expression parameter,
     DynamicHelper value)
     : base(parameter, BindingRestrictions.Empty, value)
 {
 }