Example #1
0
        public void UpdateEntryNode(EditableEntry node, ParamEntry entry)
        {
            node.ImageKey         = "empty";
            node.SelectedImageKey = "empty";

            switch (entry.ParamType)
            {
            case ParamType.Boolean:
            case ParamType.Float:
            case ParamType.Int:
            case ParamType.Uint:
            case ParamType.String64:
            case ParamType.String32:
            case ParamType.String256:
            case ParamType.StringRef:
                node.Text = $"{entry.HashString} {entry.Value}";
                break;

            case ParamType.Vector2F:
                var vec2 = (Vector2F)entry.Value;
                node.Text = $"{entry.HashString} {vec2.X} {vec2.Y}";
                break;

            case ParamType.Vector3F:
                var vec3 = (Vector3F)entry.Value;
                node.Text = $"{entry.HashString} {vec3.X} {vec3.Y} {vec3.Z}";
                break;

            case ParamType.Vector4F:
                var vec4 = (Vector4F)entry.Value;
                node.Text = $"{entry.HashString} {vec4.X} {vec4.Y} {vec4.Z} {vec4.W}";
                break;

            case ParamType.Color4F:
                var col = (Vector4F)entry.Value;
                node.Text = $"{entry.HashString} {col.X} {col.Y} {col.Z} {col.W}";

                int ImageIndex = Images.Count;
                node.ImageIndex = ImageIndex;

                var color = System.Drawing.Color.FromArgb(
                    Utils.FloatToIntClamp(col.W),
                    Utils.FloatToIntClamp(col.X),
                    Utils.FloatToIntClamp(col.Y),
                    Utils.FloatToIntClamp(col.Z));

                Bitmap   bmp = new Bitmap(32, 32);
                Graphics g   = Graphics.FromImage(bmp);
                g.Clear(color);

                Images.Add(bmp);
                break;

            default:
                break;
            }
        }
Example #2
0
        public void LoadObjectNodes(ParamObject paramObject, TreeNode parentNode)
        {
            TreeNode objNode = new TreeNode(paramObject.HashString);

            parentNode.Nodes.Add(objNode);

            foreach (var entry in paramObject.paramEntries)
            {
                EditableEntry entryNode = new EditableEntry($"{entry.HashString}");
                entryNode.entry = entry;
                objNode.Nodes.Add(entryNode);

                UpdateEntryNode(entryNode, entry);
            }
        }
        static async Task <TermRequest> CreateTermRequest()
        {
            Console.WriteLine("Test creating entry");
            var termbaseName = "Kalcium";
            var termbase     = myTermbases.Values.First(tb => tb.Name == termbaseName);
            var tbDef        = myTermbaseDefinitions[termbase.Id];
            var ee           = new EditableEntry
            {
                TermbaseId = termbase.Id,
                Languages  = new List <EditableLanguageGroup>
                {
                    new EditableLanguageGroup
                    {
                        LanguageId = tbDef.LanguageGroupDefinitions.First().LanguageId,
                        Terms      = new List <EditableTermGroup>
                        {
                            new EditableTermGroup
                            {
                                Term = $"test term request in termbase {termbase.Name}, language ${tbDef.LanguageGroupDefinitions.First().LanguageName}"
                            }
                        }
                    }
                }
            };
            var createTermRequestModel = new CreateTermRequestModel
            {
                Content          = ee,
                TermbaseId       = termbase.Id,
                Comment          = "This is a sample term request",
                SourceExpression = ee.Languages[0].Terms[0].Term,
                SourceLanguageId = ee.Languages[0].LanguageId,
            };
            var newTermRequestId = await kalcClient.TermRequests.CreateTermRequestAsync(createTermRequestModel, null, null);

            return((await kalcClient.TermRequests.GetTasksByIdAsync(new[] { newTermRequestId }, false, false))[0]);
        }
Example #4
0
        void SetObjNode(ParamObject paramObj, TreeNode parentNode)
        {
            string name      = paramObj.HashString;
            string groupName = paramObj.GroupHashString;

            var objNode = new TreeNode(name);

            parentNode.Nodes.Add(objNode);

            foreach (var entry in paramObj.paramEntries)
            {
                var entryNode = new EditableEntry($"{entry.HashString}");
                entryNode.ImageIndex       = 0;
                entryNode.ImageKey         = "empty";
                entryNode.SelectedImageKey = "empty";

                switch (entry.ParamType)
                {
                case ParamType.Boolean:
                case ParamType.Float:
                case ParamType.Int:
                case ParamType.Uint:
                case ParamType.String64:
                case ParamType.String32:
                case ParamType.String256:
                case ParamType.StringRef:
                    entryNode.Text = $"{entry.HashString} {entry.Value}";
                    break;

                case ParamType.Vector2F:
                    var vec2 = (Vector2F)entry.Value;
                    entryNode.Text = $"{entry.HashString} {vec2.X} {vec2.Y}";
                    break;

                case ParamType.Vector3F:
                    var vec3 = (Vector3F)entry.Value;
                    entryNode.Text = $"{entry.HashString} {vec3.X} {vec3.Y} {vec3.Z}";
                    break;

                case ParamType.Vector4F:
                    var vec4 = (Vector4F)entry.Value;
                    entryNode.Text = $"{entry.HashString} {vec4.X} {vec4.Y} {vec4.Z} {vec4.W}";
                    break;

                case ParamType.Color4F:
                    var col = (Vector4F)entry.Value;
                    entryNode.Text = $"{entry.HashString} {col.X} {col.Y} {col.Z} {col.W}";

                    int ImageIndex = Images.Count;
                    entryNode.ImageIndex = ImageIndex;

                    var color = System.Drawing.Color.FromArgb(
                        EditBox.FloatToIntClamp(col.W),
                        EditBox.FloatToIntClamp(col.X),
                        EditBox.FloatToIntClamp(col.Y),
                        EditBox.FloatToIntClamp(col.Z));

                    Bitmap   bmp = new Bitmap(32, 32);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.Clear(color);

                    Images.Add(bmp);
                    break;

                default:
                    break;
                }

                entryNode.entry = entry;
                objNode.Nodes.Add(entryNode);
            }
        }
        static async Task <Entry> CreateEntry()
        {
            Console.WriteLine("Test creating entry");
            var termbaseName = "Kalcium";
            var termbase     = myTermbases.Values.First(tb => tb.Name == termbaseName);
            var tbDef        = myTermbaseDefinitions[termbase.Id];
            var ee           = new EditableEntry
            {
                TermbaseId = termbase.Id,
                Languages  = new List <EditableLanguageGroup>
                {
                    new EditableLanguageGroup
                    {
                        LanguageId = tbDef.LanguageGroupDefinitions.First().LanguageId,
                        Terms      = new List <EditableTermGroup>
                        {
                            new EditableTermGroup
                            {
                                Term = $"test term in termbase {termbase.Name}, language ${tbDef.LanguageGroupDefinitions.First().LanguageName}"
                            }
                        }
                    }
                }
            };

            Console.WriteLine($" > Adding term to language {tbDef.LanguageGroupDefinitions.First().LanguageName} (#{tbDef.LanguageGroupDefinitions.First().LanguageId}): '${ee.Languages[0].Terms[0].Term}'");
            ee.Fields = new List <EditableFieldGroup>();
            //test text fields
            var textFieldDef = tbDef.FieldDefinitions.FirstOrDefault(fieldDef => fieldDef.FieldType == FieldTypes.Text);

            if (textFieldDef != null)
            {
                ee.Fields.Add(new EditableFieldGroup
                {
                    Name  = textFieldDef.Name,
                    Value = "sample text field content"
                });
                Console.WriteLine($" > Adding entry level text field, field name: ${textFieldDef.Name}; value: ${ee.Fields[0].Value}");
            }
            //test media fields
            var mediaFiles    = new List <UploadFileModel>();
            var imageFieldDef =
                tbDef.FieldDefinitions.FirstOrDefault(fieldDef => fieldDef.FieldType == FieldTypes.Multimedia);

            if (imageFieldDef != null)
            {
                var sampleImagePath = Path.Combine(Environment.CurrentDirectory, "Resources/sample.png");
                if (File.Exists(sampleImagePath))
                {
                    var sampleUploadFileModel = UploadFileModel.LoadUploadFileModel(sampleImagePath);
                    ee.Fields.Add(new EditableFieldGroup
                    {
                        Name  = imageFieldDef.Name,
                        Value = sampleUploadFileModel.FileName,
                    });

                    mediaFiles.Add(sampleUploadFileModel);
                }
                Console.WriteLine($" > Adding media field {ee.Fields.Last().Name}: {ee.Fields.Last().Value}");
            }
            var createdEntry = await kalcClient.Terminology.CreateEntryAsync(ee, termbase.Id, mediaFiles);

            Console.WriteLine($" > Entry created with id #{createdEntry.Id.UUID}");
            Console.WriteLine(JsonConvert.SerializeObject(createdEntry, Formatting.Indented));

            //test reading entry
            var queryEntryResult = await kalcClient.Terminology.GetEntriesByUUIDAsync(tbDef.TermbaseId, new string[] { createdEntry.Id.UUID },
                                                                                      termbase.LanguageIds, false, false, true, false, false);

            var queriedEntry = queryEntryResult.Entries[0];

            if (queriedEntry != null)
            {
                Console.WriteLine($" > Entry #{createdEntry.Id.UUID} has been queried again");
                Console.WriteLine(JsonConvert.SerializeObject(queriedEntry, Formatting.Indented));
            }

            if (imageFieldDef != null)
            {
                var streamResult = await kalcClient.Terminology.GetMediaFileAsync(tbDef.TermbaseId, queriedEntry.Fields.Last().Value, false,
                                                                                  null, queriedEntry.Id.UUID, null);

                var bytes = await streamResult.ReadAsByteArrayAsync();

                var tempFile = Path.GetTempPath() + Guid.NewGuid().ToString() + Path.GetExtension(queriedEntry.Fields.Last().Value);
                File.WriteAllBytes(tempFile, bytes);
                Console.WriteLine($" >> Image attachment has been downloaded to {tempFile}");
            }

            return(queriedEntry);
        }