コード例 #1
0
        private void LoadFileList(ICloudDirectoryEntry directory)
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                fseListView.Items.Clear();
                IEnumerable <DropboxFSEObject> folderContentList = DropboxManager.GetFolderContent(directory, GetSelectedExtension());

                //fseListView loading
                foreach (DropboxFSEObject folderContent in folderContentList.Where(folderContent => folderContent.Type == DropboxFSEObject.FSEType.Directory))
                {
                    fseListView.Items.Add(new ListViewItem(folderContent.Name, folderIconIndex));
                }
                foreach (DropboxFSEObject folderContent in folderContentList.Where(folderContent => folderContent.Type == DropboxFSEObject.FSEType.File))
                {
                    fseListView.Items.Add(new ListViewItem(folderContent.Name, fileIconIndex));
                }

                positionLabel.Text          = DropboxManager.GetFolderCompletePath(directory);
                superiorLevelButton.Enabled = positionLabel.Text != "/";
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> Put(string id)
        {
            switch (id.ToLowerInvariant())
            {
            case "users":
                await DropboxManager.SaveBackup(new List <User>(this.data.Users.All()));

                break;

            case "votes":
                await DropboxManager.SaveBackup(new List <Vote>(this.data.Votes.All()));

                break;

            case "projects":
                await DropboxManager.SaveBackup(new List <Project>(this.data.Projects.All()));

                break;

            case "favourites":
                await DropboxManager.SaveBackup(new List <Favourite>(this.data.Favourites.All()));

                break;

            default:
                return(this.BadRequest());
            }

            return(this.Ok("All " + id + " were backed up."));
        }
コード例 #3
0
        internal bool InitializeForm()
        {
            form = (Form1)Owner;
            form.DropboxCloudStorage = DropboxManager.InitCouldStorage(form, form.DropboxCloudStorage);
            if (form.DropboxCloudStorage == null)
            {
                WindowManager.CloseForm(this);
                return(false);
            }

            InitializeComponent();
            if (windowType == WindowType.Open)
            {
                fileNameTextBox.ReadOnly = true;
                //fileNameTextBox.ContextMenuStrip = textMenuStrip;
            }
            SetLanguage();
            ControlUtil.SetContextMenuStrip(this, fileNameTextBox);

            if (!String.IsNullOrEmpty(form.LastDropboxFolder) && DropboxManager.ExistsDirectory(form, form.LastDropboxFolder))
            {
                positionLabel.Text = form.LastDropboxFolder;
            }

            viewComboBox.SelectedIndex = Convert.ToInt32(LookFeelUtil.ListViewView.List);
            SetFileDialogFilter(); //associazione saveAsComboBox

            if (!ConfigUtil.GetBoolParameter("EnableDropboxDelete"))
            {
                fseListView.ContextMenuStrip = null;
            }

            return(true);
        }
コード例 #4
0
        public void TestMethod1()
        {
            IStorageManager manager = new DropboxManager();

            Assert.IsNotNull(manager);

            //Assert.IsFalse(manager.IsSignIn());
        }
コード例 #5
0
        private void newFolderButton_Click(object sender, EventArgs e)
        {
            WindowManager.ShowNameEntry(this);

            if (!String.IsNullOrEmpty(newObjectName) && DropboxManager.CreateDirectoryOnDropbox(form, newObjectName, DropboxManager.GetDirectory(form, positionLabel.Text)))
            {
                LoadFileList(DropboxManager.GetDirectory(form, positionLabel.Text));
            }
        }
コード例 #6
0
        public async Task <ActionResult> UploadImage(UploadImageBindingModel model)
        {
            var contest = this.Data.Contests.All().FirstOrDefault(c => c.Id == model.ContestId);

            if (!this.ModelState.IsValid || model == null)
            {
                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                TempData["uploadFail"] = "Wrong input. " + string.Join("\n", errorList);
                return(this.RedirectToAction("Details", "Contest", new { id = contest.Id }));
            }

            var userId = User.Identity.GetUserId();

            //var contest = this.Data.Contests.All().FirstOrDefault(c => c.Id == model.ContestId);

            if (!this.RightToParticipate(contest, userId))
            {
                TempData["uploadFail"] = "You have no right to participate in this contest.";
                return(this.RedirectToAction("Details", "Contest", new { id = contest.Id }));
            }

            var fileExtension   = Path.GetExtension(model.PhotoFile.FileName);
            var rawFileName     = Path.GetFileNameWithoutExtension(model.PhotoFile.FileName);
            var uniquePhotoName = Guid.NewGuid() + "-" + rawFileName + fileExtension;

            var folderNameInDropbox = Regex.Replace(contest.Title, "\\s+", "");

            var sharedLink = await DropboxManager.Upload("/" + folderNameInDropbox, uniquePhotoName, model.PhotoFile.InputStream);

            if (sharedLink == null)
            {
                TempData["uploadFail"] = "No connection to the cloud environment. \nPlease try again later";
                return(this.RedirectToAction("Details", "Contest", new { id = contest.Id }));
            }

            var rawSharedLink = sharedLink.Substring(0, sharedLink.IndexOf("?")) + "?raw=1";

            var newImage = new Image()
            {
                Title       = model.Title,
                Description = model.Description,
                ContestId   = model.ContestId,
                CreatedOn   = DateTime.Now,
                ImagePath   = rawSharedLink,
                UserId      = userId,
                FileName    = uniquePhotoName
            };

            this.Data.Images.Add(newImage);
            await this.Data.SaveChangesAsync();

            TempData["successUpload"] = "Image was successfully uploaded.";
            return(this.RedirectToAction("Details", "Contest", new { id = contest.Id }));
        }
コード例 #7
0
        private bool ValidateFileName()
        {
            if (DropboxManager.StringContainsCharNotAllowed(fileNameTextBox.Text))
            {
                WindowManager.ShowAlertBox(this, LanguageUtil.GetCurrentLanguageString("DPDefaultFileCharNotAllowed", Name));
                fileNameTextBox.Focus();

                return(false);
            }

            return(true);
        }
コード例 #8
0
        private void superiorLevelButton_Click(object sender, EventArgs e)
        {
            switch (positionLabel.Text.LastIndexOf('/'))
            {
            case 0:
                LoadFileList(DropboxManager.GetDirectory(form, "/"));
                break;

            default:
                LoadFileList(DropboxManager.GetDirectory(form, positionLabel.Text.Substring(0, positionLabel.Text.LastIndexOf('/'))));
                break;
            }
        }
コード例 #9
0
ファイル: NameEntry.cs プロジェクト: fredatgithub/DtPad
        private void fileNameTextBox_TextChanged(object sender, EventArgs e)
        {
            StringForm form = (StringForm)Owner;

            okButton.Enabled = !(String.IsNullOrEmpty(fileNameTextBox.Text));

            if (form.GetType() == typeof(DropboxFileDialog) && DropboxManager.StringContainsCharNotAllowed(fileNameTextBox.Text))
            {
                okButton.Enabled = false;
                WindowManager.ShowAlertBox(this, LanguageUtil.GetCurrentLanguageString("DPDefaultFileCharNotAllowed", Name));
                fileNameTextBox.Focus();
            }
        }
コード例 #10
0
        private void ActivationItem(ListView item)
        {
            switch (item.FocusedItem.ImageIndex)
            {
            case folderIconIndex:
                String position = positionLabel.Text;
                if (!position.EndsWith("/"))
                {
                    position += "/";
                }

                LoadFileList(DropboxManager.GetDirectory(form, position + item.FocusedItem.Text));
                break;

            case fileIconIndex:
                OpenSave();
                break;
            }
        }
コード例 #11
0
        public async Task <ActionResult> Delete(int id)
        {
            var imageTarget = this.Data.Images.GetById(id);

            if (imageTarget == null)
            {
                return(new HttpStatusCodeResult(400, "No record for this image in the database"));
            }

            var userId = User.Identity.GetUserId();

            if (User.IsInRole("Admin") || userId != imageTarget.User.Id)
            {
                return(new HttpStatusCodeResult(400, "You don't have the right to delete this picture."));
            }

            var  folderNameInDropbox = Regex.Replace(imageTarget.Contest.Title, "\\s+", "");
            bool deleted             = await DropboxManager.Delete("/" + folderNameInDropbox + "/" + imageTarget.FileName);

            if (!deleted)
            {
                return(new HttpStatusCodeResult(500, "Unable to delete image."));
            }

            int contestId = imageTarget.Contest.Id;

            this.Data.Images.Delete(imageTarget);
            await this.Data.SaveChangesAsync();

            var imgs = this.Data.Contests.All().First(c => c.Id == contestId).Pictures
                       .Select(p => new PagedImageViewModel()
            {
                Id             = p.Id,
                ImagePath      = p.ImagePath,
                VotesCount     = p.Votes.Count(),
                AuthorUsername = p.User.UserName,
                HasVoted       = p.Votes.Any(u => u.Id == userId)
            });

            TempData["succDelete"] = "Image was successfully deleted.";
            return(PartialView("_ListPagedImages", imgs));
        }
コード例 #12
0
        private void Rename(object sender, LabelEditEventArgs e)
        {
            ListView item = (ListView)sender;

            String oldName = item.Items[Convert.ToInt32(e.Item)].Text;
            String newName = e.Label;

            if (String.IsNullOrEmpty(newName) || oldName == e.Label || !ValidateFileName())
            {
                e.CancelEdit = true;
                return;
            }

            switch (item.FocusedItem.ImageIndex)
            {
            case folderIconIndex:
            {
                String folderToRename = positionLabel.Text;
                if (!folderToRename.EndsWith("/"))
                {
                    folderToRename += "/";
                }
                folderToRename += oldName;

                if (!DropboxManager.RenameFolder(form, DropboxManager.GetDirectory(form, folderToRename), newName))
                {
                    e.CancelEdit = true;
                }
            }
            break;

            case fileIconIndex:
                if (!DropboxManager.RenameFile(form, DropboxManager.GetDirectory(form, positionLabel.Text), oldName, newName))
                {
                    e.CancelEdit = true;
                }
                break;
            }
        }
コード例 #13
0
        /// <summary>
        /// Singleton 응용 프로그램 개체를 초기화합니다.  이것은 실행되는 작성 코드의 첫 번째
        /// 줄이며 따라서 main() 또는 WinMain()과 논리적으로 동일합니다.
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;



            /*** Injecting objects to public static instances ***/

            // App
            MobileService = new MobileServiceClient(
                "https://pinthecloud.azure-mobile.net/",
                "yvulzHAGRgNsGnPLHKcEFCPJcuyzKj23"
                );
            ApplicationSessions = new WSApplicationSessions();
            ApplicationSettings = new WSApplicationSettings();

            // Manager
            SpotManager         = new SpotManager();
            Geolocator          = new Geolocator();
            BlobStorageManager  = new BlobStorageManager();
            LocalStorageManager = new LocalStorageManager();

            OneDriveManager   = new OneDriveManager();
            DropBoxManager    = new DropboxManager();
            GoogleDriveManger = new GoogleDriveManager();


            /////////////////////////////////////////////////////
            // This order will be displayed at every App Pages
            /////////////////////////////////////////////////////
            StorageHelper.AddStorageManager(OneDriveManager.GetStorageName(), OneDriveManager);
            StorageHelper.AddStorageManager(DropBoxManager.GetStorageName(), DropBoxManager);
            StorageHelper.AddStorageManager(GoogleDriveManger.GetStorageName(), GoogleDriveManger);
            Switcher.SetStorageToMainPlatform();
            AccountManager = new AccountManager();
        }
コード例 #14
0
        private void Delete()
        {
            String name = fseListView.SelectedItems[0].Text;

            switch (fseListView.FocusedItem.ImageIndex)
            {
            case folderIconIndex:
            {
                String folderToDelete = positionLabel.Text;
                if (!folderToDelete.EndsWith("/"))
                {
                    folderToDelete += "/";
                }
                folderToDelete += name;

                DropboxManager.DeleteFolder(form, DropboxManager.GetDirectory(form, folderToDelete));
            }
            break;

            case fileIconIndex:
                DropboxManager.DeleteFile(form, DropboxManager.GetDirectory(form, positionLabel.Text), name);
                break;
            }
        }
コード例 #15
0
ファイル: Configuration.cs プロジェクト: jechev/PhotoContest
        private void SeedImages(PhotoContestDbContext context)
        {
            string[] foldersInDropBox = { "AnimalMemes", "Bridges", "RightPlaceRightTime", "SnapShotOfLife", "Space", "TheArtOfNature", "WiredIdeas" };

            var task = Task.Run(() => DropboxManager.GetAllSharedLinks());

            task.Wait();

            Dictionary <string, List <Tuple <string, string> > > photoSeedData = task.Result;

            for (var i = 0; i < foldersInDropBox.Length; i++)
            {
                if (!photoSeedData.ContainsKey("/" + foldersInDropBox[i]))
                {
                    continue;
                }

                List <Tuple <string, string> > imgInContest = photoSeedData["/" + foldersInDropBox[i]];
                int counter = 1;

                Queue <ApplicationUser> userHolder = new Queue <ApplicationUser>(allUsers);
                Queue <Tag>             tagHolder  = new Queue <Tag>(context.Tags.ToArray());

                Random rnd = new Random();

                foreach (var img in imgInContest)
                {
                    var user = userHolder.Dequeue();
                    userHolder.Enqueue(user);

                    string contestName = contestNames[i];

                    var newImg = new Image()
                    {
                        Title       = "Img " + (counter++),
                        ImagePath   = img.Item1,
                        Description = img.Item2 + " - Some inspiring description",
                        CreatedOn   = DateTime.Now,
                        User        = user,
                        Contest     = context.Contests.FirstOrDefault(c => c.Title == contestName),
                        Prize       = null
                    };

                    context.Images.Add(newImg);
                    context.SaveChanges();

                    for (int j = 0; j < rnd.Next(1, 15); j++)
                    {
                        user = userHolder.Dequeue();
                        userHolder.Enqueue(user);

                        if (j % 3 == 0)
                        {
                            user.FavoritePictures.Add(newImg);
                        }

                        if (j % 2 == 0)
                        {
                            newImg.Votes.Add(user);
                        }

                        var comment = new Comment()
                        {
                            Picture   = newImg,
                            Author    = user,
                            Content   = "Comment " + j,
                            CreatedAt = DateTime.Now
                        };

                        context.Comments.Add(comment);

                        for (int k = 0; k < rnd.Next(1, 4); k++)
                        {
                            var tag = tagHolder.Dequeue();
                            tagHolder.Enqueue(tag);

                            newImg.Tags.Add(tag);
                        }
                    }

                    context.SaveChanges();
                }
            }
        }
コード例 #16
0
 public DropBox()
 {
     this.InitializeComponent();
     files = new ObservableCollection <DropboxFile>();
     dbm   = new DropboxManager();
 }
コード例 #17
0
        public void TestInit1()
        {
            //App.MobileService = new MobileServiceClient(
            //    "https://pinthecloud.azure-mobile.net/",
            //    "yvulzHAGRgNsGnPLHKcEFCPJcuyzKj23"
            //);
            App.ApplicationSessions = new WSApplicationSessions();
            App.ApplicationSettings = new WSApplicationSettings();

            // Manager
            App.SpotManager         = new SpotManager();
            App.Geolocator          = new Geolocator();
            App.BlobStorageManager  = new BlobStorageManager();
            App.LocalStorageManager = new LocalStorageManager();

            IStorageManager OneDriveManager   = new OneDriveManager();
            IStorageManager DropBoxManager    = new DropboxManager();
            IStorageManager GoogleDriveManger = new GoogleDriveManager();


            /////////////////////////////////////////////////////
            // This order will be displayed at every App Pages
            /////////////////////////////////////////////////////
            StorageHelper.AddStorageManager(OneDriveManager.GetStorageName(), OneDriveManager);
            StorageHelper.AddStorageManager(DropBoxManager.GetStorageName(), DropBoxManager);
            StorageHelper.AddStorageManager(GoogleDriveManger.GetStorageName(), GoogleDriveManger);
            Switcher.SetStorageToMainPlatform();
            App.AccountManager = new AccountManager();


            if (!App.ApplicationSettings.Contains(Switcher.MAIN_PLATFORM_TYPE_KEY))
            {
                App.ApplicationSettings[Switcher.MAIN_PLATFORM_TYPE_KEY] = AppResources.OneDrive;
            }

            // Check nick name at frist login.
            if (!App.ApplicationSettings.Contains(StorageAccount.ACCOUNT_DEFAULT_SPOT_NAME_KEY))
            {
                App.ApplicationSettings[StorageAccount.ACCOUNT_DEFAULT_SPOT_NAME_KEY] = AppResources.AtHere;
            }

            // Check location access consent at frist login.
            if (!App.ApplicationSettings.Contains(StorageAccount.LOCATION_ACCESS_CONSENT_KEY))
            {
                App.ApplicationSettings[StorageAccount.LOCATION_ACCESS_CONSENT_KEY] = false;
            }


            // Do Signin work of each cloud storage.
            if (App.AccountManager.IsSignIn())
            {
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    TaskHelper.AddTask(App.AccountManager.GetPtcId(), App.AccountManager.SignIn());
                    using (var itr = StorageHelper.GetStorageEnumerator())
                    {
                        while (itr.MoveNext())
                        {
                            if (itr.Current.IsSignIn())
                            {
                                TaskHelper.AddSignInTask(itr.Current.GetStorageName(), itr.Current.SignIn());
                            }
                        }
                    }
                }
            }
        }
コード例 #18
0
 private void saveAsComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     LoadFileList(DropboxManager.GetDirectory(form, positionLabel.Text));
 }