コード例 #1
0
        private static string GenerateBasicCreateSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, APIOperationTypes opType, AssociationInfo association, bool addFields)
        {
            string        json               = addFields ? GenerateJsonFromFields(selectedAttributes, opType) : "";
            StringBuilder jsonObject         = new StringBuilder();
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample create snippet using the POST operator. Use this snippet inside your record creation logic. Replace or modify the data object properties per your needs. Make sure that these properies are enabled for web api.*/");


            jsonObject.AppendLine("var dataObject={");
            jsonObject.AppendLine(json);
            jsonObject.AppendLine("};");


            snippetTextBuilder.AppendLine(jsonObject.ToString());


            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"POST\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tdata: JSON.stringify(dataObject),");
            snippetTextBuilder.AppendLine("\tsuccess: function(res, status, xhr) {");
            snippetTextBuilder.AppendLine("\t\t//print id of newly created entity record");
            snippetTextBuilder.AppendLine("\t\tconsole.log(\"entityID: \" + xhr.getResponseHeader(\"entityid\"))");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");


            return(snippetTextBuilder.ToString());
        }
コード例 #2
0
        private static string GenerateBasicUpdateSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, APIOperationTypes opType, AssociationInfo association, bool addFields)
        {
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample basic update snippet using the PATCH operator. You need to specify the ID of the record being updated and the JSON data object for the fields you want to update.*/");

            string        json       = addFields ? GenerateJsonFromFields(selectedAttributes, APIOperationTypes.BasicUpdate) : "";
            StringBuilder jsonObject = new StringBuilder();

            jsonObject.AppendLine("var dataObject={");
            jsonObject.AppendLine(json);
            jsonObject.AppendLine("};");


            snippetTextBuilder.AppendLine(jsonObject.ToString());


            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"PATCH\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "(00000000-0000-0000-0000-000000000000)\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tdata: JSON.stringify(dataObject),");
            snippetTextBuilder.AppendLine("\tsuccess: function(res) {");
            snippetTextBuilder.AppendLine("\t\tconsole.log(res)");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");


            return(snippetTextBuilder.ToString());
        }
コード例 #3
0
        public static string GenerateSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, APIOperationTypes opType, AssociationInfo association, bool addFields)
        {
            switch (opType)
            {
            case APIOperationTypes.BasicCreate:
                return(GenerateBasicCreateSnippet(selectedEntityInfo, selectedAttributes, opType, association, addFields));

            case APIOperationTypes.UpdateSingle:
                return(GenerateUpdateSingleSnippet(selectedEntityInfo, selectedAttributes, addFields));

            case APIOperationTypes.BasicUpdate:
                return(GenerateBasicUpdateSnippet(selectedEntityInfo, selectedAttributes, opType, association, addFields));

            case APIOperationTypes.BasicDelete:
                return(GenerateBasicDeleteSnippet(selectedEntityInfo, selectedAttributes));

            case APIOperationTypes.DeleteSingle:
                return(GenerateDeleteSingleSnippet(selectedEntityInfo, selectedAttributes, addFields));

            case APIOperationTypes.AssociateDisassociate:

                break;

            default:
                throw new NotImplementedException("This operation is not implemented yet");
            }

            return("");
        }
コード例 #4
0
        private void LoadAllEntities()
        {
            //clear previous lists
            Model?.ClearEntities();
            lstBxAllEntities.DataSource = Model.AllEntitiesList;
            txtAllEntitiesFilter.Text   = "";
            // load entity list
            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading Entities",
                Work    = (worker, args) =>
                {
                    RetrieveAllEntitiesRequest retrieveAllEntityRequest = new RetrieveAllEntitiesRequest
                    {
                        RetrieveAsIfPublished = true,
                        EntityFilters         = EntityFilters.Entity | EntityFilters.Relationships
                    };
                    RetrieveAllEntitiesResponse retrieveAllEntityResponse = (RetrieveAllEntitiesResponse)Service.Execute(retrieveAllEntityRequest);

                    args.Result = retrieveAllEntityResponse.EntityMetadata;
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error while retrieving the entities from the environment.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    var entityMetaDataArray = args.Result as EntityMetadata[];
                    if (entityMetaDataArray != null)
                    {
                        lstBxAllEntities.SelectedIndexChanged -= AllEntitiesListBox_SelectedIndexChanged;
                        foreach (EntityMetadata entityMetadata in entityMetaDataArray)
                        {
                            if (!MetadataValidator.IsValidEntity(entityMetadata))
                            {
                                continue;
                            }

                            EntityItemModel entityItemModel = new EntityItemModel(entityMetadata);
                            Model.AddEntity(entityItemModel);
                            //lstBxAllEntities.Items.Add(entityItemModel);
                        }
                        lstBxAllEntities.SelectedIndexChanged += AllEntitiesListBox_SelectedIndexChanged;
                        lstBxAllEntities.SelectedItem          = null;
                        ToggleWebsiteToolbarComponents(true);
                        entitiesSplitContainer.Visible = true;
                    }
                    else
                    {
                        ToggleWebsiteToolbarComponents(false);
                        MessageBox.Show("Error while connecting to the environment.");
                    }
                    LoadInnerErrorTrackingSettings();
                }
            });
        }
コード例 #5
0
        private static string GenerateBasicDeleteSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes)
        {
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample delete snippet using the DELETE operator. Use this when you want to delete a record. You need to specify the ID of the record between the brackets.*/");

            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"DELETE\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "(00000000-0000-0000-0000-000000000000)\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tsuccess: function(res) {");
            snippetTextBuilder.AppendLine("\t\tconsole.log(res)");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");

            return(snippetTextBuilder.ToString());
        }
コード例 #6
0
        private static string GenerateDeleteSingleSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, bool addFields)
        {
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample delete snippet to delete a single property using the DELETE operator. Use this when you want to clear out a single property value and not the whole record. You need to specify the ID of the record between the brackets and the logical name of the propery*/");

            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"DELETE\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "(00000000-0000-0000-0000-000000000000)/ATTRIBUTE_NAME_HERE\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tsuccess: function(res) {");
            snippetTextBuilder.AppendLine("\t\tconsole.log(res)");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");

            return(snippetTextBuilder.ToString());
        }
コード例 #7
0
        private static string GenerateUpdateSingleSnippet(EntityItemModel selectedEntityInfo, List <WebAPIAttributeItemModel> selectedAttributes, bool addFields)
        {
            StringBuilder snippetTextBuilder = new StringBuilder();

            snippetTextBuilder.AppendLine("/*This is a sample single field update snippet using the PUT operator. You need to specify the ID of the record being updated, the logical name of the attribute and the value of the targeted attribute.*/");

            snippetTextBuilder.AppendLine("webapi.safeAjax({");
            snippetTextBuilder.AppendLine("\ttype: \"PUT\",");
            snippetTextBuilder.AppendLine("\turl: \"/_api/" + selectedEntityInfo.CollectionName + "(00000000-0000-0000-0000-000000000000)/ATTRIBUTE_NAME_HERE\",");
            snippetTextBuilder.AppendLine("\tcontentType:\"application/json\",");
            snippetTextBuilder.AppendLine("\tdata: JSON.stringify({");
            snippetTextBuilder.AppendLine("\t\t\"value\":\"NEW VALUE HERE\"");
            snippetTextBuilder.AppendLine("\t}),");
            snippetTextBuilder.AppendLine("\tsuccess: function(res) {");
            snippetTextBuilder.AppendLine("\t\tconsole.log(res)");
            snippetTextBuilder.AppendLine("\t}");
            snippetTextBuilder.AppendLine("});");


            return(snippetTextBuilder.ToString());
        }