public async Task <IActionResult> SingleAttachmentAsync(Guid id, AttachmentSize size = AttachmentSize.MEDIA_SIZE_ORIG)
        {
            var res = await fileStorageProvider.ReadAsync(id, size);

            res.content.Position = 0;
            return(File(res.content, res.attachment.MimeType, res.attachment.Filename));
        }
Beispiel #2
0
 public Component_AttachPoint(AttachmentSize maxSize, bool active, bool swappable)
 {
     this.attachedEntity = null;
     this.MaxSize        = maxSize;
     this.Active         = active;
     this.Swappable      = swappable;
 }
Beispiel #3
0
        public async Task <Attachment> ByIdAndSizeAsync(Guid id, AttachmentSize size)
        {
            var document = await attachments
                           .FindAsync(a => size == AttachmentSize.MEDIA_SIZE_ORIG && a.Id.Equals(id) ||
                                      a.OriginalAttachmentId.Equals(id) && a.Size.Equals(size));

            return(await document.FirstOrDefaultAsync());
        }
 private static Entity BuildWeapon(string label, AttachmentSize size, int maxRange, int damage,
                                   int refireTicks, DamageType type)
 {
     return(new Entity(label: label, typeLabel: "Weapon")
            .AddComponent(new Component_Attachable(size))
            .AddComponent(new Component_Weapon(size, Config.ZERO, maxRange, damage, refireTicks, type))
            .AddComponent(new Component_Attacker()));
 }
 public Task <(Stream content, Attachment attachment)> ReadAsync(Guid id, AttachmentSize size = AttachmentSize.MEDIA_SIZE_ORIG)
 {
     return(mediator.Send(new AttachmentInSizeQuery
     {
         Id = id,
         Size = size,
     }));
 }
Beispiel #6
0
 // TODO: I would like to define a construct which can be read from a file to construct these!
 // Right now I'll just hard-code them all and feel bad about it.
 public Component_Weapon(AttachmentSize size, int toHit, int maxRange, int damage, int refireTicks)
     : base(EntityAttributeType.REFIRE_TICKS)
 {
     this.Size             = size;
     this.WeaponAttributes = new Dictionary <EntityAttributeType, int>()
     {
         { EntityAttributeType.MAX_RANGE, maxRange },
         { EntityAttributeType.DAMAGE, damage },
         { EntityAttributeType.REFIRE_TICKS, refireTicks },
     };
 }
        public async Task <Attachment> MetaDataAsync(Guid id, AttachmentSize size = AttachmentSize.MEDIA_SIZE_ORIG)
        {
            var resp = await mediator.Send(new AttachmentInSizeQuery
            {
                Id            = id,
                Size          = size,
                ReturnContent = false,
            });

            return(resp.attachment);
        }
            protected void SetPropertyValues(IAnnotation annotation, DataAdapterDependencies dataAdapterDependencies)
            {
                CreatedOn        = annotation.CreatedOn;
                CreatedOnDisplay = CreatedOn.ToString(DateTimeClientFormat);
                var text = annotation.NoteText;

                Text            = AnnotationHelper.FormatNoteText(text).ToString();
                UnformattedText = text.Replace(AnnotationHelper.WebAnnotationPrefix, string.Empty);
                if (annotation.FileAttachment != null)
                {
                    AttachmentFileName    = annotation.FileAttachment.FileName;
                    HasAttachment         = annotation.FileAttachment != null;
                    AttachmentContentType = annotation.FileAttachment.MimeType;
                    AttachmentUrl         = HasAttachment
                                                ? annotation.Entity.GetFileAttachmentUrl(dataAdapterDependencies.GetWebsite())
                                                : string.Empty;
                    AttachmentSize        = annotation.FileAttachment.FileSize;
                    AttachmentSizeDisplay = AttachmentSize.ToString();
                    AttachmentIsImage     = HasAttachment &&
                                            (new List <string> {
                        "image/jpeg", "image/gif", "image/png"
                    }).Contains(AttachmentContentType);
                }
                var subject = annotation.Subject;

                Subject   = subject;
                IsPrivate = AnnotationHelper.GetNotePrivacy(annotation);
                var noteContact = AnnotationHelper.GetNoteContact(subject);
                var user        = dataAdapterDependencies.GetPortalUser();

                IsPostedByCurrentUser = noteContact != null && user != null && noteContact.Id == user.Id;
                PostedByName          = noteContact == null?AnnotationHelper.GetNoteCreatedByName(annotation) : noteContact.Name;

                if (CanWrite)
                {
                    CanWrite = IsPostedByCurrentUser;
                }
                if (CanDelete)
                {
                    CanDelete = IsPostedByCurrentUser;
                }
                DisplayToolbar = CanWrite || CanDelete;
            }
Beispiel #9
0
 public Component_Attachable(AttachmentSize sizeRequired)
 {
     this.attachedTo   = null;
     this.SizeRequired = sizeRequired;
 }
        public async Task <IActionResult> SingleAttachmentDataAsync(Guid id, AttachmentSize size = AttachmentSize.MEDIA_SIZE_ORIG)
        {
            var res = await fileStorageProvider.MetaDataAsync(id, size);

            return(Ok(res));
        }
        public void TestReciveSendMessageBlockWcf()
        {
            const string BaseAddress     = "http://*****:*****@"<s:Envelope xmlns:s=""http://www.w3.org/2003/05/soap-envelope"">
                                <s:Header />
                                <s:Body>
                                    <AcceptMessageResponse xmlns=""http://tempuri.org/"" />
                                </s:Body>
                            </s:Envelope>"));
                        });
                    }))
                    {
                        int timeout = sendingManager.ScanningPeriodMilliseconds + SendTimeout;

                        var recievingThread = new Thread(asyncReciever.AsyncRecieve);

                        sendingManager.Prepare();
                        sendingManager.Start();

                        try
                        {
                            var sw = new Stopwatch();

                            bool sendingStarted = false;
                            int  n = 0;

                            recievingThread.Start();

                            while (true)
                            {
                                var now = DateTime.Now;

                                // wait for the callback
                                resetEvent.WaitOne(timeout);

                                // synchronous waiting time measurement
                                double waitingTime = (DateTime.Now - now).TotalMilliseconds;

                                if (!sendingStarted)
                                {
                                    timeout        = SendTimeout;
                                    sendingStarted = true;
                                    sw.Start();
                                }

                                if (exception != null)
                                {
                                    throw exception;
                                }

                                var sendedCount = sendedMessages.Count;

                                if (sendedCount > BlockSize)
                                {
                                    // the test will fail at Assert block
                                    break;
                                }

                                if (sendedCount == n)
                                {
                                    if (waitingTime < SendTimeout)
                                    {
                                        continue;
                                    }

                                    if (sendedCount < BlockSize)
                                    {
                                        throw new TimeoutException($"{dataService.ToString()}. Время ожидания callback-вызова превысило {SendTimeout} мсек.");
                                    }

                                    // the test result will be determined at Assert block
                                    break;
                                }

                                n = sendedCount;
                            }

                            sw.Stop();
                            sendingTime = sw.Elapsed.TotalMilliseconds - SendTimeout;
                        }
                        catch (Exception ex)
                        {
                            asyncReciever.SetStopFlag();
                            exception = exception ?? ex;
                        }
                        finally
                        {
                            sendingManager.Stop();
                            sendingManager.AfterStop();
                        }

                        recievingThread.Join();

                        if (exception != null)
                        {
                            throw exception;
                        }
                    }

                // Assert.
                Assert.False(sendedMessages.Count > BlockSize, $"{ dataService.ToString()}. Количество отправленных сообщений превысило количество полученных сообщений.");

                var diagnosticMessage = $"{dataService.ToString()}:";
                diagnosticMessage += $"{Environment.NewLine}  Recieving time {asyncReciever.RecievingTime.ToString()} ms.";
                diagnosticMessage += $"{Environment.NewLine}  Sending time {sendingTime.ToString()} ms.";
                Console.WriteLine(diagnosticMessage);
            }
        }