Exemplo n.º 1
0
        public static bool TryParse(DiscoDataContext Database, string UniqueIdentifier, out DocumentUniqueIdentifier Identifier)
        {
            if (IsDocumentUniqueIdentifier(UniqueIdentifier))
            {
                var components = UniqueIdentifier.Split('|');

                // Version 0, Version 1 Handling
                if ((components.Length == 7 || components.Length == 6) &&
                    (components[1].Equals("1", StringComparison.Ordinal) || components[1].Equals("AT", StringComparison.OrdinalIgnoreCase)))
                {
                    var documentTemplateId = components[2];
                    var targetId = components[3];
                    var creatorId = components[4];
                    var timeStamp = DateTime.Parse(components[5]);
                    var page = 0;
                    if (components.Length == 7)
                    {
                        page = int.Parse(components[6]);
                    }

                    Identifier = new DocumentUniqueIdentifier(Database, 1, -1, documentTemplateId, targetId, creatorId, timeStamp, page, null);
                    return true;
                }
            }

            Identifier = null;
            return false;
        }
Exemplo n.º 2
0
        public static bool TryParse(DiscoDataContext Database, byte[] Data, out DocumentUniqueIdentifier Identifier)
        {
            if (IsDocumentUniqueIdentifier(Data))
            {
                // first 4 bit indicate version
                var version = Data[1] >> 4;

                // Version 2
                if (version == 2)
                {
                    // Byte | Meaning
                    // 0    | magic number = 0xC4
                    // 1    | bits 0-3 = version;
                    //      |      4   = flag: has document template id
                    //      |      5-6 = (01 = device attachment, 10 = job attachment, 11 = user attachment)
                    //      |      7   = not used
                    // 2-3  | deployment checksum (int16)
                    // 4-7  | timestamp (uint32 unix epoch)
                    // 8-9  | page index (uint16)
                    // 10   | creator id encoded
                    // ?    | target id encoded
                    // ?    | document template id encoded (optional based on flag)

                    // read flags
                    var flags = Data[1] & 0x0F;

                    // read deployment checksum
                    short deploymentChecksum = (short)((Data[2] << 8) | Data[3]);

                    // read timestamp
                    var timeStampEpoch = ((long)Data[4] << 24) |
                        ((long)Data[5] << 16) |
                        ((long)Data[6] << 8) |
                        Data[7];

                    // write page index
                    var pageIndex = (Data[8] << 8) | Data[9];

                    var position = 10;

                    // write creator id
                    var creatorId = DocumentUniqueIdentifierExtensions.BinaryDecode(Data, position, out position);

                    // write target id
                    var targetId = DocumentUniqueIdentifierExtensions.BinaryDecode(Data, position, out position);

                    // write document template id
                    string documentTemplateId = null;

                    // Has document template id flag
                    if ((flags & 0x8) == 0x8)
                    {
                        documentTemplateId = DocumentUniqueIdentifierExtensions.BinaryDecode(Data, position, out position);
                    }

                    AttachmentTypes? attachmentType = null;
                    switch (flags & 0x6)
                    {
                        case 0x2:
                            attachmentType = AttachmentTypes.Device;
                            break;
                        case 0x4:
                            attachmentType = AttachmentTypes.Job;
                            break;
                        case 0x6:
                            attachmentType = AttachmentTypes.User;
                            break;
                    }

                    var timeStamp = DateTime.FromFileTimeUtc(116444736000000000L).AddTicks(TimeSpan.TicksPerSecond * timeStampEpoch).ToLocalTime();

                    Identifier = new DocumentUniqueIdentifier(Database, version, deploymentChecksum, documentTemplateId, targetId, creatorId, timeStamp, pageIndex, attachmentType);
                    return true;
                }
            }

            Identifier = null;
            return false;
        }
Exemplo n.º 3
0
        public static DocumentUniqueIdentifier Create(DiscoDataContext Database, DocumentTemplate DocumentTemplate, IAttachmentTarget Target, User Creator, DateTime TimeStamp, int PageIndex)
        {
            var deploymentChecksum = Database.DiscoConfiguration.DeploymentChecksum;
            var documentTemplateId = DocumentTemplate.Id;
            var targetId = Target.AttachmentReferenceId;
            var creatorId = Creator.UserId;
            var attachmentType = DocumentTemplate.AttachmentType;

            var identifier = new DocumentUniqueIdentifier(Database, CurrentVersion, deploymentChecksum, documentTemplateId, targetId, creatorId, TimeStamp, PageIndex, attachmentType);

            identifier.documentTemplate = DocumentTemplate;
            identifier.target = Target;
            identifier.creator = Creator;

            return identifier;
        }