コード例 #1
0
        public void TestTempDeletedChildItemIgnored( )
        {
            var svc = new EntityInfoService( );

            EntityRef orgRef = null;

            try
            {
                var o = new Report
                {
                    Name  = "org rpt",
                    Alias = "shared:a" + Guid.NewGuid( )
                };

                var b = new ReportColumn
                {
                    Name            = "bob",
                    Alias           = "shared:a" + Guid.NewGuid( ),
                    ColumnForReport = o
                };

                EntityData result = svc.GetEntityData(b, EntityRequestHelper.BuildRequest("name, columnForReport.name"));

                result.Relationships[0].Instances[0].DataState = DataState.Delete;

                orgRef = svc.CreateEntity(result);
            }
            finally
            {
                if (orgRef != null)
                {
                    Entity.Delete(orgRef);
                }
            }
        }
コード例 #2
0
        public void CreateInstance( )
        {
            // Define a new entity
            var data = new EntityData
            {
                Fields  = new List <FieldData>( ),
                TypeIds = new EntityRef("test", "person").ToEnumerable( ).ToList( )
            };

            data.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("Isaac Newton")
            });

            // Create it
            var       svc = new EntityInfoService( );
            EntityRef id  = svc.CreateEntity(data);

            // Verify it was created
            Assert.IsTrue(id.Id > 0, "Positive Id");

            // Select the data
            EntityMemberRequest request = EntityRequestHelper.BuildRequest("name");
            EntityData          result  = svc.GetEntityData(id, request);

            // Verify results
            Assert.AreEqual("Isaac Newton", result.Fields[0].Value.Value);

            svc.DeleteEntity(id);
        }
コード例 #3
0
ファイル: ImageManager.cs プロジェクト: hardin253874/Platform
        /// <summary>
        ///     Creates a new image
        /// </summary>
        /// <param name="imageFileUploadId">The image file upload identifier.</param>
        /// <param name="imageEntityData">The image entity data.</param>
        /// <returns>The requested data.</returns>
        /// <exception cref="System.ArgumentNullException">@imageEntityData</exception>
        /// <exception cref="System.ArgumentException">@imageEntityData</exception>
        public EntityRef CreateImageFromExistingFile(long imageFileUploadId, EntityData imageEntityData)
        {
            if (imageEntityData == null)
            {
                throw new ArgumentNullException(@"imageEntityData");
            }

            // Create a new image entity
#pragma warning disable 618
            var entityInfoService = new EntityInfoService( );
#pragma warning restore 618
            var imageFile = entityInfoService.CreateEntity(imageEntityData).Entity.AsWritable <ImageFileType>( );

            int width;
            int height;

            using (Stream stream = GetImageDataStream(imageFileUploadId))
            {
                using (Image image = Image.FromStream(stream))
                {
                    width  = image.Width;
                    height = image.Height;
                }
            }
            var existingImage = Entity.Get <ImageFileType>(imageFileUploadId);

            imageFile.FileDataHash  = existingImage.FileDataHash;
            imageFile.FileExtension = existingImage.FileExtension;
            imageFile.ImageWidth    = width;
            imageFile.ImageHeight   = height;
            imageFile.Save( );

            return(imageFile);
        }
コード例 #4
0
        public void GetFieldInstanceDbType( )
        {
            /////
            // Define a new entity
            /////
            var data = new EntityData
            {
                Fields  = new List <FieldData>( ),
                TypeIds = new EntityRef("test", "person").ToEnumerable( ).ToList( )
            };

            /////
            // Create it
            /////
            var       svc = new EntityInfoService( );
            EntityRef id  = svc.CreateEntity(data);

            /////
            // Verify it was created
            /////
            Assert.IsTrue(id.Id > 0, "Positive Id");

            EntityMemberRequest fieldRequest = EntityRequestHelper.BuildRequest(@"
				fields.isOfType.name,
				fields.isOfType.alias,
				fields.isOfType.dbType,
				fields.isOfType.dbTypeFull,
				fields.isOfType.readiNowType,
				fields.isOfType.xsdType"                );

            EntityData result = svc.GetEntityData(data.TypeIds.First( ), fieldRequest);

            /////
            // Verify results
            /////
            Assert.AreEqual(1, result.Relationships.Count);

            svc.DeleteEntity(id);
        }
コード例 #5
0
        public void UpdateFieldOnRelatedInstance( )
        {
            // Define a new entity
            var data = new EntityData
            {
                Fields  = new List <FieldData>( ),
                TypeIds = new EntityRef("test", "person").ToEnumerable().ToList()
            };

            data.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("Isaac Newton")
            });

            // Define a new related entity
            var data2 = new EntityData
            {
                Fields  = new List <FieldData>( ),
                TypeIds = new EntityRef("test", "employee").ToEnumerable().ToList()
            };

            data2.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("Isaac Newtons Emmployer")
            });
            data2.DataState = DataState.Create;

            data.Relationships = new List <RelationshipData>
            {
                new RelationshipData
                {
                    RelationshipTypeId = new EntityRef("test", "reportsTo"),
                    IsReverse          = false,
                    Instances          = new List <RelationshipInstanceData>
                    {
                        new RelationshipInstanceData
                        {
                            Entity    = data2,
                            DataState = DataState.Create
                        }
                    },
                }
            };

            // Create it
            var       svc = new EntityInfoService( );
            EntityRef id  = svc.CreateEntity(data);

            // Verify it was created
            Assert.IsTrue(id.Id > 0, "Positive Id");

            // Select the data
            EntityMemberRequest request = EntityRequestHelper.BuildRequest("name, test:reportsTo.name");
            EntityData          result  = svc.GetEntityData(id, request);

            // Verify results
            Assert.AreEqual("Isaac Newton", result.Fields[0].Value.Value);

            EntityData employee           = result.Relationships[0].Instances[0].Entity;
            FieldData  employersNameField = employee.Fields[0];

            Assert.AreEqual("Isaac Newtons Emmployer", employersNameField.Value.Value);

            // Update employees name
            employersNameField.Value.Value = "bob";
            employee.DataState             = DataState.Update;

            svc.UpdateEntity(result);

            // comfirm it changed
            EntityData resultAfterUpdate = svc.GetEntityData(id, request);

            employee           = resultAfterUpdate.Relationships[0].Instances[0].Entity;
            employersNameField = employee.Fields[0];
            Assert.AreEqual("bob", employersNameField.Value.Value);

            // delete the referenced Entity leaving the data state of the top entity unchanged
            employee.DataState = DataState.Delete;

            svc.UpdateEntity(resultAfterUpdate);

            // comfirm it deleted
            EntityData resultAfterDelete = svc.GetEntityData(id, request);

            Assert.AreEqual(0, resultAfterDelete.Relationships[0].Instances.Count, "There should be no manager");

            // clean up
            svc.DeleteEntity(id);
        }
コード例 #6
0
        public void TestLoopsDontBreakCreate( )
        {
            // Define a new entity
            var data1 = new EntityData
            {
                Fields  = new List <FieldData>( ),
                TypeIds = new EntityRef("test", "person").ToEnumerable( ).ToList( )
            };

            data1.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("Isaac Newton")
            });

            // Define a new related entity
            var data2 = new EntityData
            {
                Fields  = new List <FieldData>( ),
                TypeIds = new EntityRef("test", "employee").ToEnumerable( ).ToList( )
            };

            data2.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("Isaac Newtons Emmployer")
            });
            data2.DataState = DataState.Create;

            data1.Relationships = new List <RelationshipData>
            {
                new RelationshipData
                {
                    RelationshipTypeId = new EntityRef("test", "reportsTo"),
                    IsReverse          = false,
                    Instances          = new List <RelationshipInstanceData>
                    {
                        new RelationshipInstanceData
                        {
                            Entity    = data2,
                            DataState = DataState.Create
                        }
                    },
                }
            };

            data2.Relationships = new List <RelationshipData>
            {
                new RelationshipData
                {
                    RelationshipTypeId = new EntityRef("test", "reportsTo"),
                    IsReverse          = false,
                    Instances          = new List <RelationshipInstanceData>
                    {
                        new RelationshipInstanceData
                        {
                            Entity    = data1,
                            DataState = DataState.Create
                        }
                    },
                }
            };

            // Create it
            var       svc = new EntityInfoService( );
            EntityRef id  = svc.CreateEntity(data1);

            // Verify it was created
            Assert.IsTrue(id.Id > 0, "Positive Id");

            svc.DeleteEntity(id);
        }
コード例 #7
0
ファイル: ImageManager.cs プロジェクト: hardin253874/Platform
        /// <summary>
        ///     Creates a new image
        /// </summary>
        /// <param name="imageFileUploadId">The image file upload id.</param>
        /// <param name="imageEntityData">The image entity data.</param>
        /// <param name="fileExtension">The file extension.</param>
        /// <returns>
        ///     The requested data.
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public EntityRef CreateImageFromUploadedFile(string imageFileUploadId, EntityData imageEntityData, string fileExtension)
        {
            if (string.IsNullOrEmpty(imageFileUploadId))
            {
                throw new ArgumentException(@"The imageFileUploadId is empty.", "imageFileUploadId");
            }

            if (imageEntityData == null)
            {
                throw new ArgumentNullException(@"imageEntityData");
            }

            if (string.IsNullOrEmpty(fileExtension))
            {
                throw new ArgumentNullException(@"fileExtension");
            }

            ImageFileType imageFile;
            string        filePath = string.Empty;

            try
            {
                // Create a new image entity
#pragma warning disable 618
                var entityInfoService = new EntityInfoService( );
#pragma warning restore 618
                imageFile = entityInfoService.CreateEntity(imageEntityData).Entity.AsWritable <ImageFileType>( );

                var        fileManagerService = new FileManagerService( );
                FileDetail fileDetails        = fileManagerService.GetFileDetails(imageFileUploadId);

                filePath = fileDetails.FullName;

                int width;
                int height;

                using (Image image = Image.FromFile(fileDetails.FullName))
                {
                    width  = image.Width;
                    height = image.Height;
                }

                string token;
                using (var source = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    token = FileRepositoryHelper.AddTemporaryFile(source);
                }

                imageFile.FileDataHash  = token;
                imageFile.FileExtension = FileHelper.GetFileExtension(filePath);
                imageFile.ImageWidth    = width;
                imageFile.ImageHeight   = height;
                imageFile.Save( );
            }
            finally
            {
                // Delete the underlying temp file
                if (!string.IsNullOrEmpty(filePath))
                {
                    File.Delete(filePath);
                }
            }

            return(imageFile);
        }
コード例 #8
0
        public void Test_NewDefinitionOnRelated_GetEntitiesUsingInstancesOfType()
        {
            EntityMemberRequest request = EntityRequestHelper.BuildRequest("instancesOfType.{alias,name,description}");
            var svc = GetService();

            // Check before create
            var result = svc.GetEntityData(new EntityRef("core:definition"), request);
            int count  = result.Relationships[0].Instances.Count;

            Assert.IsTrue(count > 1);

            // Define a new form & definition
            var defn = new EntityData
            {
                Fields    = new List <FieldData>(),
                TypeIds   = new EntityRef("core", "definition").ToEnumerable().ToList(),
                DataState = DataState.Create
            };

            defn.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("TestDefnT " + Guid.NewGuid().ToString())
            });
            var form = new EntityData
            {
                Fields    = new List <FieldData>(),
                TypeIds   = new EntityRef("console", "customEditForm").ToEnumerable().ToList(),
                DataState = DataState.Create
            };

            form.Fields.Add(new FieldData
            {
                FieldId = new EntityRef("name"),
                Value   = new TypedValue("TestFormT " + Guid.NewGuid().ToString())
            });
            form.Relationships = new List <RelationshipData> {
                new RelationshipData
                {
                    RelationshipTypeId = new EntityRef("console", "typeToEditWithForm"),
                    RemoveExisting     = true
                }
            };
            form.Relationships[0].Instances = new List <RelationshipInstanceData> {
                new RelationshipInstanceData
                {
                    Entity    = defn,
                    DataState = DataState.Create
                }
            };
            var svcWrite = new EntityInfoService();

            using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
            {
                EntityRef id = svcWrite.CreateEntity(form);

                ctx.CommitTransaction();
            }

            // Check after create
            var result2 = svc.GetEntityData(new EntityRef("core:definition"), request);
            int count2  = result2.Relationships[0].Instances.Count;

            Assert.AreEqual(count + 1, count2);
        }