Exemplo n.º 1
0
        public void TestCustomException()
        {
            // To create a record that implement IDataRecord we start with a record set definition.
            RecordSetDefinition recordSetDefinition = new RecordSetDefinition(
                new ColumnDefinition("ID", SqlDbType.Int),
                new ColumnDefinition("Name", SqlDbType.Char, 50),
                new ColumnDefinition("Description", SqlDbType.NVarChar),
                // This column is not nullable so defaults to true
                new ColumnDefinition("Active", SqlDbType.Bit, isNullable: false, defaultValue: true)
                );

            // Now we can create a record
            IObjectRecord dataRecord = new ObjectRecord(recordSetDefinition, 1, "Test", "This is my test record");

            // To create a record that throws an exception we first create an ExceptionRecord
            IObjectRecord exceptionRecord = new ExceptionRecord(new SqlInvalidSyntaxException());

            // We can stick these records into a recordset
            // Note the records must have the same RecordSetDefinition (unless it's an exception record)
            // The final record will through an exception when reached!
            ObjectSet recordSet = new ObjectSet(recordSetDefinition)
            {
                dataRecord,
                exceptionRecord
            };

            // We can add recordsets to an ObjectReader
            ObjectReader reader = new ObjectReader
            {
                recordSet
            };

            // Now that we have a reader we can use it like a normal reader - it even simulates disposal.
            ReadFromRecordSet(reader);
        }
Exemplo n.º 2
0
 void Record(ObjectRecord objectRecord)
 {
     if (!gameOver)
     {
         listObjectRecord.Add(objectRecord);
     }
 }
        public static void SaveRecord(GameObject forObject, ObjectRecord record, bool isUndo)
        {
            UndoRedoOps operations = new UndoRedoOps();
            int         key        = forObject.GetHashCode();

            bool containsEntry = dataContainer.objectsHistory.TryGetValue(key, out operations);


            if (containsEntry)
            {
                if (isUndo)
                {
                    if (operations.undoOperations.Count == undoLimit)
                    {
                        operations.undoOperations[0].Destruct();
                        operations.undoOperations.RemoveAt(0);
                    }

                    operations.undoOperations.Add(record);
                }

                else
                {
                    if (operations.redoOperations.Count == undoLimit)
                    {
                        operations.redoOperations[0].Destruct();
                        operations.redoOperations.RemoveAt(0);
                    }

                    operations.redoOperations.Add(record);
                }
            }

            else
            {
                if (dataContainer.objectsHistory.Count == objectRecordLimit)
                {
                    dataContainer.objectsHistory[0].Destruct();
                    dataContainer.objectsHistory.Remove(0);
                }


                operations                = new UndoRedoOps();
                operations.gameObject     = forObject;
                operations.undoOperations = new List <ObjectRecord>();
                operations.redoOperations = new List <ObjectRecord>();

                if (isUndo)
                {
                    operations.undoOperations.Add(record);
                }
                else
                {
                    operations.redoOperations.Add(record);
                }

                dataContainer.objectsHistory.Add(key, operations);
            }
        }
 public ObjectEntryViewModel(Action onSave, Action onCancel, object objectToEnter, FormController formController, RecordEntryViewModelBase parentForm, string parentFormReference, IDictionary <string, IEnumerable <string> > onlyValidate = null, string saveButtonLabel = null, string cancelButtonLabel = null)
     : base(formController, parentForm, parentFormReference, onlyValidate, saveButtonLabel : saveButtonLabel, cancelButtonLabel : cancelButtonLabel)
 {
     _objectRecord = new ObjectRecord(objectToEnter);
     OnSave        = onSave;
     OnCancel      = onCancel;
     RecordType    = _objectRecord.Type;
 }
Exemplo n.º 5
0
        internal static IObjectInfo <AssetsObject> Parse(AssetsFile file, ObjectRecord record)
        {
            var obji = FromTypeIndex(file, record.TypeIndex, null);

            obji.ObjectID   = record.ObjectID;
            obji.DataOffset = record.DataOffset;
            obji.DataSize   = record.DataSize;
            return(obji);
        }
        public ObjectDisplayViewModel(object objectToEnter, FormController formController, Action backAction = null, Action nextAction = null)
            : base(formController, saveButtonLabel: "Next")
        {
            IsReadOnly = true;
            OnSave     = nextAction;
            OnBack     = backAction;

            _objectRecord = new ObjectRecord(objectToEnter);
            RecordType    = _objectRecord.Type;
        }
        public override ReferencePicklistItem GetValueAsPicklistItem()
        {
            if (Value == null)
            {
                return(null);
            }
            //just use this type of irecord as only for an irecord reference and otherwise may throw type error
            var iReocrd = new ObjectRecord(Value);

            //iReocrd.Id = Value.Id;
            return(new ReferencePicklistItem(iReocrd, Value.ToString()));
        }
        public ObjectDisplayViewModel(object objectToEnter, FormController formController)
            : base(formController)
        {
            IsReadOnly = true;

            _objectRecord = new ObjectRecord(objectToEnter);
            RecordType    = _objectRecord.Type;

            if (objectToEnter.GetType().IsTypeOf(typeof(INotifyPropertyChanged)))
            {
                var iNotify = (INotifyPropertyChanged)objectToEnter;
                iNotify.PropertyChanged += NotifyOnPropertyChanged;
            }
        }
Exemplo n.º 9
0
        public ConditionViewModel(QueryCondition conditionObject, string recordType, IRecordService recordService, IApplicationController controller)
            : base(FormController.CreateForObject(conditionObject, controller, recordService, optionSetLimitedvalues: new Dictionary <string, IEnumerable <string> > { { nameof(QueryCondition.FieldName), GetValidFields(recordType, recordService) } }))
        {
            _queryCondition       = conditionObject;
            _queryConditionRecord = new ObjectRecord(conditionObject);

            var metadata         = FormService.GetFormMetadata(GetRecord().Type, RecordService);
            var sections         = metadata.FormSections;
            var firstSection     = sections.First();
            var sectionViewModel = new FieldSectionViewModel(
                (FormFieldSection)firstSection,
                this
                );

            FormFieldSection = sectionViewModel;
            OnLoad();
        }
Exemplo n.º 10
0
        public static ObjectRecord CreateObjectRecord(GameObject forObject, bool isMeshless, Vector3 posToUpdate)
        {
            /*
             * CollRecognize colliderObj = forObject.GetComponentInChildren<CollRecognize>();
             * GameObject duplicateColl = null;
             *
             * if (colliderObj)
             * {
             *  duplicateColl = DuplicateGameObject(colliderObj.gameObject, "_duplicate" + Guid.NewGuid().ToString(), true, true);
             *  //duplicate.hideFlags = HideFlags.HideAndDontSave;
             * }
             */

            //var childStates = SaveChildrenStates(forObject);
            //ColliderState collState = SaveColliderState(forObject);

            Vector3    position = forObject.transform.position;
            Quaternion rotation = forObject.transform.rotation;

            ObjectRecord record = new ObjectRecord(null, position, posToUpdate, rotation, isMeshless);

            return(record);
        }
        public void WriteObject(object objectToWrite)
        {
            var objectRecord  = new ObjectRecord(objectToWrite);
            var recordService = new ObjectRecordService(objectToWrite, null);
            var formService   = new ObjectFormService(objectToWrite, recordService);
            var formMetadata  = formService.GetFormMetadata(objectToWrite.GetType().AssemblyQualifiedName);

            foreach (var section in formMetadata.FormSections.OrderBy(s => s.Order))
            {
                if (section is FormFieldSection fieldSection)
                {
                    if (fieldSection.FormFields.Any(f => objectToWrite.IsInContext(f.FieldName)))
                    {
                        _content.AppendLine("<p>");
                        if (fieldSection.DisplayLabel)
                        {
                            AppendSectionHeading(fieldSection.SectionLabel);
                        }
                        foreach (var field in fieldSection.FormFields.OrderBy(f => f.Order))
                        {
                            if (objectToWrite.IsInContext(field.FieldName))
                            {
                                if (field.DisplayLabel)
                                {
                                    AppendFieldHeading(recordService.GetFieldLabel(field.FieldName, objectRecord.Type));
                                }
                                if (recordService.GetFieldType(field.FieldName, objectRecord.Type) == RecordFieldType.Enumerable)
                                {
                                    //okay need to generate a table
                                    var enumerableMetadata = recordService.GetFieldMetadata(field.FieldName, objectRecord.Type) as EnumerableFieldMetadata;
                                    var gridFieldMetadata  = recordService.GetGridFields(enumerableMetadata.EnumeratedTypeQualifiedName, ViewType.AssociatedView);
                                    var table = new StringBuilder();
                                    table.AppendLine("<table>");
                                    table.AppendLine("<thead><tr>");

                                    var fieldJustifies = new Dictionary <string, string>();
                                    foreach (var gridField in gridFieldMetadata)
                                    {
                                        var justify     = recordService.GetFieldType(gridField.FieldName, enumerableMetadata.EnumeratedTypeQualifiedName).GetHorizontalJustify(true);
                                        var htmlJustify = justify == HorizontalJustify.Left
                                            ? "left"
                                            : justify == HorizontalJustify.Middle
                                            ? "center"
                                            : "right";
                                        fieldJustifies.Add(gridField.FieldName, htmlJustify);
                                    }

                                    foreach (var gridField in gridFieldMetadata)
                                    {
                                        table.AppendLine($"<th width={gridField.WidthPart} {thStyle.Replace("left", fieldJustifies[gridField.FieldName])}>{recordService.GetFieldLabel(gridField.FieldName, enumerableMetadata.EnumeratedTypeQualifiedName)}</th>");
                                    }
                                    table.AppendLine("</tr></thead>");

                                    var linkedObjects = recordService
                                                        .GetLinkedRecords(enumerableMetadata.EnumeratedTypeQualifiedName, objectRecord.Type, field.FieldName, objectRecord.Id)
                                                        .Cast <ObjectRecord>()
                                                        .ToArray();
                                    var objectsForTable = linkedObjects
                                                          .Take(MaximumNumberOfEntitiesToList)
                                                          .ToArray();

                                    foreach (var gridRecord in objectsForTable.Take(MaximumNumberOfEntitiesToList))
                                    {
                                        table.AppendLine("<tr>");
                                        foreach (var gridField in gridFieldMetadata
                                                 .Where(gf => objectsForTable.Any(o => o.Instance.IsInContext(gf.FieldName))))
                                        {
                                            table.AppendLine(string.Format("<td {0}>", tdStyle.Replace("left", fieldJustifies[gridField.FieldName])));
                                            table.Append(recordService.GetFieldAsDisplayString(gridRecord, gridField.FieldName));
                                            table.AppendLine("</td>");
                                        }
                                        table.AppendLine("</tr>");
                                    }
                                    table.AppendLine("</table>");
                                    _content.AppendLine(table.ToString());

                                    if (linkedObjects.Count() > MaximumNumberOfEntitiesToList)
                                    {
                                        AppendParagraph(string.Format("Note this list is incomplete as the maximum of {0} items has been listed", MaximumNumberOfEntitiesToList));
                                    }
                                }
                                else
                                {
                                    AppendFieldValue(recordService.GetFieldAsDisplayString(objectRecord, field.FieldName));
                                }
                            }
                        }
                        _content.AppendLine("</p>");
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void RecordExample()
        {
            // To create a record that implement IDataRecord we start with a record set definition.
            RecordSetDefinition recordSetDefinition = new RecordSetDefinition(
                new ColumnDefinition("ID", SqlDbType.Int),
                new ColumnDefinition("Name", SqlDbType.Char, 50),
                new ColumnDefinition("Description", SqlDbType.NVarChar),
                // This column is not nullable so defaults to true
                new ColumnDefinition("Active", SqlDbType.Bit, isNullable: false, defaultValue: true)
                );

            // Now we can create a record
            IObjectRecord dataRecord = new ObjectRecord(recordSetDefinition, 1, "Test", "This is my test record");

            // Or we can create one with random values
            IObjectRecord randomRecord = new ObjectRecord(recordSetDefinition, true);

            // To create a record that throws an exception we first create a SqlException
            // We can't do this directly, but we can use our prototypes to construct one.

            // SqlExceptions are made from a collection of SqlErrors - which can make like this :
            SqlErrorCollection errorCollection = new SqlErrorCollectionPrototype
            {
                new SqlErrorPrototype(
                    1000,
                    80,
                    17,
                    "MyFakeServer",
                    "Connection Timeout.",
                    "spMySproc",
                    54)
            };

            SqlException  sqlException    = new SqlExceptionPrototype(errorCollection, "9.0.0.0", Guid.NewGuid());
            IObjectRecord exceptionRecord = new ExceptionRecord(sqlException);

            // We can stick these records into a recordset
            // Note the records must have the same RecordSetDefinition (unless it's an exception record)
            // The final record will through an exception when reached!
            ObjectSet recordSet = new ObjectSet(recordSetDefinition)
            {
                dataRecord,
                randomRecord,
                //exceptionRecord
            };

            // We can add recordsets to an ObjectReader
            ObjectReader reader = new ObjectReader
            {
                recordSet
            };

            // We can also add random record sets - this one has the same definition as the first.
            reader.Add(new RandomSet(recordSetDefinition));

            // We can also fix certain rows values using the column generators arry, a null indicates
            // that the column should us a random value, otherwise a lambda can be supplied - in this case
            // it sets the row to the row number (1 - indexed).
            reader.Add(
                new RandomSet(
                    recordSetDefinition,
                    columnGenerators: new Func <int, object>[] { null, row => "Row #" + row }));

            // Whereas this one has a random set of columns (with random types).
            reader.Add(new RandomSet(10));

            // Now that we have a reader we can use it like a normal reader - it even simulates disposal.
            using (IDataReader dataReader = reader)
            {
                int recordset = 1;
                do
                {
                    Trace.Write("Recordset #" + recordset);
                    int rows = 0;
                    while (dataReader.Read())
                    {
                        rows++;
                    }
                    Trace.WriteLine(" - " + rows + " rows.");
                    recordset++;
                } while (dataReader.NextResult());
            }
        }
Exemplo n.º 13
0
 public void UpdatePostion(ObjectRecord obj)
 {
     transform.position    = obj.Position;
     transform.eulerAngles = obj.Rotation;
 }
Exemplo n.º 14
0
 public void UpdatePostion(ObjectRecord obj)
 {
     transform.position = obj.Position;
     centerPosition     = obj.Position;
 }