Example #1
0
        public void GetPhotoFilePathTest()
        {
            string     expectedPath = "myphoto.png";
            PhotoEvent pe           = new PhotoEvent(new GRLocation(0, 0), "", expectedPath);

            Assert.AreEqual(expectedPath, pe.PhotoFilePath);
        }
Example #2
0
        public void PrepareAllPhotosArchive(PhotoEvent lastEvent)
        {
            Logger SecondTaskLogger = LogManager.GetLogger("secondTaskFile");

            Regex pathRegex = new Regex("photos");
            IEnumerable <FileInfo> files =
                new DirectoryInfo(DslrPhotoDirPath)
                .GetFiles("*.*", SearchOption.AllDirectories)
                .Where(f =>
                       pathRegex.IsMatch(f.FullName) &&
                       f.LastWriteTime > lastEvent.StartDateTime &&
                       f.LastWriteTime < lastEvent.EndDateTime);

            SecondTaskLogger.Info("Total files for archiving: {0}", files.Count());


            var archivePath = Path.Combine("Archives", lastEvent.Id + ".zip");

            using (var fileStream = new FileStream(archivePath, FileMode.CreateNew))
            {
                using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create, true))
                {
                    foreach (var file in files)
                    {
                        SecondTaskLogger.Info("File {0} added to archive", file.Name);
                        var fileBytes       = ImageToByte(Image.FromFile(file.FullName));
                        var zipArchiveEntry = archive.CreateEntry(file.Name, CompressionLevel.Optimal);
                        using (var zipStream = zipArchiveEntry.Open())
                            zipStream.Write(fileBytes, 0, fileBytes.Length);
                    }
                }
            }
            SecondTaskLogger.Info("Archive by path {0} created", archivePath);
        }
Example #3
0
        //[HttpPost]
        public async Task <ActionResult> GetGallery(Guid?id, string password)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PhotoEvent photoEvent = await this._db.PhotoEvents.FindAsync(id);

            if (photoEvent == null)
            {
                return(this.HttpNotFound());
            }

            if (photoEvent.IsPublic)
            {
                if (string.IsNullOrWhiteSpace(password))
                {
                    return(this.RedirectToAction("ShowError", new { errorText = "Вы должны ввести пароль!" }));
                }

                if (photoEvent.Password != password)
                {
                    return(this.RedirectToAction("ShowError", new { errorText = "Не верный пароль!" }));
                }
            }

            var photos = this._db.Photos.Where(p => p.PhotoEventId == id).Include(p => p.PhotoEvent);

            return(this.View(await photos.ToListAsync()));
        }
Example #4
0
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            PhotoEvent photoEvent = await this.db.PhotoEvents.FindAsync(id);

            this.db.PhotoEvents.Remove(photoEvent);
            await this.db.SaveChangesAsync();

            return(this.RedirectToAction("Index"));
        }
Example #5
0
        // GET: PhotoEvents/Details/5
        public async Task <ActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhotoEvent photoEvent = await this.db.PhotoEvents.FindAsync(id);

            if (photoEvent == null)
            {
                return(this.HttpNotFound());
            }
            return(this.View(photoEvent));
        }
Example #6
0
        // GET: PhotoEvents/Edit/5
        public async Task <ActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhotoEvent photoEvent = await this.db.PhotoEvents.FindAsync(id);

            if (photoEvent == null)
            {
                return(this.HttpNotFound());
            }
            this.ViewBag.PhotoBoothEntityId = new SelectList(this.db.PhotoBooths, "Id", "Name", photoEvent.PhotoBoothEntityId);
            return(this.View(photoEvent));
        }
Example #7
0
 private void btn_submit_Click(object sender, EventArgs e)
 {
     dt = dtPicker.Value;
     if (Ready())
     {
         Event newEvent = new PhotoEvent(new GRLocation(eventLocation.Latitude, eventLocation.Longitude), dt.ToString(), fileName);
         GREventManager.AddEvent(newEvent);
         MessageBox.Show("Event successfully added!");
         this.Hide();
     }
     else
     {
         MessageBox.Show("Could not add event.");
     }
 }
        public async Task <IHttpActionResult> GetPhotoEvent(Guid id)
        {
            var nowDateTime        = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time"));
            var currentBoothEvents = await db.PhotoEvents.Where(pe => pe.PhotoBoothEntityId == id).Include(x => x.Photos).ToListAsync();

            PhotoEvent photoEvent = currentBoothEvents.FirstOrDefault(currentBoothEvent => currentBoothEvent.StartDateTime <= nowDateTime && currentBoothEvent.EndDateTime >= nowDateTime);

            //PhotoEvent photoEvent = currentBoothEvents.FirstOrDefault();

            if (photoEvent == null)
            {
                return(NotFound());
            }

            return(Ok(photoEvent));
        }
Example #9
0
        public static void Write(string ns, XmlTextWriter writer, PhotoEvent aEvent)
        {
            writer.WriteStartElement(ns + "photo");

            writer.WriteStartElement(ns + "filepath");
            writer.WriteString(aEvent.PhotoFilePath);
            writer.WriteEndElement();

            Write(ns, writer, aEvent.EventLocation);

            writer.WriteStartElement(ns + "datetimestamp");
            Write(ns, writer, aEvent.EventDateTime);
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
        public PhotoEvent GetCurrentEvent()
        {
            PhotoEvent currentBoothEventNow = null;

            try
            {
                using (var db = new PhotoBoothContext())
                {
                    IQueryable <PhotoEvent> currentBoothEvents = db.PhotoEvents.Where(pe => pe.PhotoBoothEntityId == _boothGuid);
                    foreach (var currentBoothEvent in currentBoothEvents)
                    {
                        if (currentBoothEvent.StartDateTime <= DateTime.Now && currentBoothEvent.EndDateTime >= DateTime.Now)
                        {
                            currentBoothEventNow = currentBoothEvent;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("firstTaskFile").Error(ex);
            }

            //if (currentBoothEventNow != null)
            //{
            //    logger.Info("Event {0} right now!", currentBoothEventNow.Id);
            //    Settings.CurrentEvent = currentBoothEventNow;
            //    Settings.LastEvent = currentBoothEventNow;

            //    EventInfo eventInfo = new EventInfo()
            //    {
            //        Id = currentBoothEventNow.Id,
            //        StartDate = currentBoothEventNow.StartDateTime,
            //        EndDate = currentBoothEventNow.EndDateTime
            //    };
            //    WriteEventToFile(eventInfo);
            //}
            //else
            //{
            //    logger.Info("No new events...");
            //    Settings.CurrentEvent = null;
            //}

            return(currentBoothEventNow);
        }
Example #11
0
        public async Task <ActionResult> DownloadZip(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PhotoEvent photoEvent = await this.db.PhotoEvents.FindAsync(id);

            if (photoEvent == null)
            {
                return(this.HttpNotFound());
            }

            //string applicationZip = "application/zip";
            string account                     = CloudConfigurationManager.GetSetting("StorageAccountName");
            string key                         = CloudConfigurationManager.GetSetting("StorageAccountAccessKey");
            string connectionString            = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", account, key);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer  container      = blobClient.GetContainerReference(id.ToString());

            container.CreateIfNotExists();

            CloudBlockBlob blockZipDownloadBlob = container.GetBlockBlobReference(id + ".zip");

            if (!blockZipDownloadBlob.Exists())
            {
                return(this.HttpNotFound());
            }

            blockZipDownloadBlob.FetchAttributes();

            //Important to set buffer to false. IIS will download entire blob before passing it on to user if this is not set to false
            this.Response.Buffer = false;
            this.Response.AddHeader("Content-Disposition", "attachment; filename=" + id + ".zip");
            this.Response.AddHeader("Content-Length", blockZipDownloadBlob.Properties.Length.ToString()); //Set the length the file
            this.Response.ContentType = "application/octet-stream";
            this.Response.Flush();

            //Use the Azure API to stream the blob to the user instantly.
            // *SNIP*
            blockZipDownloadBlob.DownloadToStream(this.Response.OutputStream);
            return(new EmptyResult());
        }
Example #12
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Description,HashTag,StartDateTime,EndDateTime,ShowOnGallery,IsPublic,Password,LinkToLastZip,InstagrammBrandingImage,InstagrammBrandingFile,LinkToGalleryPreviewImage,PhotoBoothEntityId")] PhotoEvent photoEvent)
        {
            if (this.ModelState.IsValid)
            {
                this.db.Entry(photoEvent).State = EntityState.Modified;
                if (photoEvent.InstagrammBrandingFile != null)
                {
                    using (Image image = Image.FromStream(photoEvent.InstagrammBrandingFile.InputStream))
                    {
                        photoEvent.InstagrammBrandingImage = ImageToBase64(image);
                    }
                }
                await this.db.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }
            this.ViewBag.PhotoBoothEntityId = new SelectList(this.db.PhotoBooths, "Id", "Name", photoEvent.PhotoBoothEntityId);
            return(this.View(photoEvent));
        }
Example #13
0
        public PhotoEvent GetCurrentEvent(Logger logger)
        {
            PhotoEvent currentBoothEventNow = null;

            try
            {
                using (var db = new PhotoBoothContext())
                {
                    IQueryable <PhotoEvent> currentBoothEvents = db.PhotoEvents.Where(pe => pe.PhotoBoothEntityId == _boothGuid);
                    foreach (var currentBoothEvent in currentBoothEvents)
                    {
                        if (currentBoothEvent.StartDateTime <= DateTime.Now && currentBoothEvent.EndDateTime >= DateTime.Now)
                        {
                            currentBoothEventNow = currentBoothEvent;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            if (currentBoothEventNow != null)
            {
                logger.Info("Event {0} right now!", currentBoothEventNow.Id);
                Settings.CurrentEvent = currentBoothEventNow;
                Settings.LastEvent    = currentBoothEventNow;
            }
            else
            {
                logger.Info("No new events...");
                Settings.CurrentEvent = null;
            }

            return(currentBoothEventNow);
        }
Example #14
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,Description,HashTag,StartDateTime,EndDateTime,ShowOnGallery,IsPublic,Password,LinkToLastZip,InstagrammBrandingFile,LinkToGalleryPreviewImage,PhotoBoothEntityId")] PhotoEvent photoEvent)
        {
            if (this.ModelState.IsValid)
            {
                if (photoEvent.StartDateTime != null)
                {
                    var nowDateTime = TimeZoneInfo.ConvertTime(photoEvent.StartDateTime.Value, TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time"));
                    var existEvent  = await db.PhotoEvents.Where(e => e.PhotoBoothEntityId == photoEvent.PhotoBoothEntityId)
                                      .FirstOrDefaultAsync(currentBoothEvent => currentBoothEvent.StartDateTime <= nowDateTime && currentBoothEvent.EndDateTime >= nowDateTime);

                    if (existEvent != null)
                    {
                        this.ViewBag.ExistIsTrue        = true;
                        this.ViewBag.PhotoBoothEntityId = new SelectList(this.db.PhotoBooths, "Id", "Name", photoEvent.PhotoBoothEntityId);
                        return(this.View(photoEvent));
                    }
                }

                if (photoEvent.InstagrammBrandingFile != null)
                {
                    using (Image image = Image.FromStream(photoEvent.InstagrammBrandingFile.InputStream))
                    {
                        photoEvent.InstagrammBrandingImage = ImageToBase64(image);
                    }
                }

                photoEvent.Id = Guid.NewGuid();
                this.db.PhotoEvents.Add(photoEvent);
                await this.db.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

            this.ViewBag.PhotoBoothEntityId = new SelectList(this.db.PhotoBooths, "Id", "Name", photoEvent.PhotoBoothEntityId);
            return(this.View(photoEvent));
        }
Example #15
0
    public void RegisterPhotoEvent(Progress.Fish fType)
    {
        PhotoEvent ev = new PhotoEvent(fType);

        TrackEvent(ev);
    }
Example #16
0
 public IpRuder(String preferedCaptureDevice)
 {
     SampleGrabberCount    = 0;
     PreferedCaptureDevice = preferedCaptureDevice;
     WakeProcessing        = new ManualResetEvent(false);
     ProccessingEvents     = new Thread(() =>
     {
         try
         {
             EventCode ev;
             IntPtr p1, p2;
             while (true)
             {
                 WakeProcessing.WaitOne( );
                 while (VideoEvent.GetEvent(out ev, out p1, out p2, 0) == 0)
                 {
                     try
                     {
                         if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                         {
                             StopVideo( );
                             break;
                         }
                         else if (ev == EventCode.ErrorAbort)
                         {
                             Console.WriteLine("An error occured: HRESULT={0:X}", p1);
                             StopVideo( );
                             break;
                         }
                     }
                     finally
                     {
                         VideoEvent.FreeEventParams(ev, p1, p2);
                     }
                 }
                 while (PhotoEvent.GetEvent(out ev, out p1, out p2, 0) == 0)
                 {
                     try
                     {
                         if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                         {
                             StopPhoto( );
                             break;
                         }
                         else if (ev == EventCode.ErrorAbort)
                         {
                             Console.WriteLine("An error occured: HRESULT={0:X}", p1);
                             StopPhoto( );
                             break;
                         }
                         PhotoEvent.FreeEventParams(ev, p1, p2);
                     }
                     finally
                     {
                         PhotoEvent.FreeEventParams(ev, p1, p2);
                     }
                 }
                 Thread.Sleep(500);
             }
         }
         catch (COMException ex)
         {
             Console.WriteLine("COM error: " + ex.ToString( ));
         }
         catch (Exception ex)
         {
             Console.WriteLine("Error: " + ex.ToString( ));
         }
     });
     ProccessingEvents.IsBackground = true;
     ProccessingEvents.Start( );
     PhotoCallBack = new SampleGrabberCallback( );
 }
        internal static async Task Do(CancellationToken token, int delaySeconds)
        {
            while (!token.IsCancellationRequested)
            {
                EventInfo eventInfo;

                PhotoEvent currentEvent = EventHelper.Instance.GetCurrentEvent();
                if (currentEvent != null)
                {
                    FirstTaskLogger.Info("Current event id: {0}", currentEvent.Id);
                    if (currentEvent.InstagrammBrandingImage == null)
                    {
                        Settings.BrandImage = InstagramHelper.Instance.DefaultBrandingImage;
                        FirstTaskLogger.Info("Branding is default");
                    }
                    else
                    {
                        if (Settings.BrandImage == null)
                        {
                            Settings.BrandImage = currentEvent.InstagrammBrandingImage;
                            FirstTaskLogger.Info("Branding is custom");
                        }
                    }
                    Settings.CurrentEvent = currentEvent;
                    Settings.LastEvent    = currentEvent; //for archive preparation
                    eventInfo             = new EventInfo()
                    {
                        Id        = currentEvent.Id,
                        StartDate = currentEvent.StartDateTime,
                        EndDate   = currentEvent.EndDateTime,
                        HashTag   = currentEvent.HashTag,
                        InstagrammBrandingImage = currentEvent.InstagrammBrandingImage
                    };
                    EventHelper.Instance.WriteEventToFile(eventInfo);
                }
                else
                {
                    FirstTaskLogger.Info("Current event in db == null");

                    eventInfo = EventHelper.Instance.ReadEventFromFile();
                    if (eventInfo != null)
                    {
                        FirstTaskLogger.Info("Local file contain event, id: {0}", eventInfo.Id);

                        if (eventInfo.InstagrammBrandingImage == null)
                        {
                            Settings.BrandImage = InstagramHelper.Instance.DefaultBrandingImage;
                            FirstTaskLogger.Info("local: Branding is default");
                        }
                        else
                        {
                            if (Settings.BrandImage == null)
                            {
                                Settings.BrandImage = eventInfo.InstagrammBrandingImage;
                                FirstTaskLogger.Info("local: Branding is custom");
                            }
                        }

                        PhotoEvent photoEvent = new PhotoEvent()
                        {
                            Id                      = eventInfo.Id,
                            StartDateTime           = eventInfo.StartDate,
                            EndDateTime             = eventInfo.EndDate,
                            HashTag                 = eventInfo.HashTag,
                            InstagrammBrandingImage = eventInfo.InstagrammBrandingImage
                        };
                        Settings.CurrentEvent = photoEvent;
                        Settings.LastEvent    = photoEvent; //for archive preparation
                    }
                    else
                    {
                        FirstTaskLogger.Info("Local file not exits or no event now");
                        EventHelper.Instance.DeleteEventInfoFile();
                        Settings.BrandImage   = null;
                        Settings.CurrentEvent = null;
                    }
                }
                await Task.Delay(TimeSpan.FromSeconds(delaySeconds));
            }
        }
Example #18
0
 public void Add(PhotoEvent photo)
 {
     throw new System.NotImplementedException();
 }