public IndexModel(ApplicationDbContext context,
                   GoogleDriveService googleDriveService
                   )
 {
     _context            = context;
     _googleDriveService = googleDriveService;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GoogleDriveFileSystem"/> class.
 /// </summary>
 /// <param name="service">The <see cref="GoogleDriveService"/> instance to use to access the Google Drive</param>
 /// <param name="rootFolderInfo">The <see cref="File"/> to use as root folder</param>
 /// <param name="requestFactory">A <see cref="IRequestFactory"/> used to create <see cref="IRestClient"/> and <see cref="HttpWebRequest"/> objects</param>
 public GoogleDriveFileSystem(GoogleDriveService service, File rootFolderInfo, GoogleDriveSupportFactory requestFactory)
 {
     _requestFactory = requestFactory;
     Service         = service;
     RootFolderInfo  = rootFolderInfo;
     Root            = new GoogleDriveDirectoryEntry(this, RootFolderInfo, "/", true);
 }
Пример #3
0
        private async Task ProcessImage(String path)
        {
            try
            {
                string imageUrl = await GoogleDriveService.UploadImage(path);

                FeedbackModel.Image = imageUrl;
                SnackbarMessageQueue.Enqueue("Please Wait, We now verify your image");
                bool isConfident = await ImageAnlyzer.CheckIceCreamConfidentByPath(path);

                if (isConfident)
                {
                    SnackbarMessageQueue.Enqueue("Your image was verifyed successfully.");
                }
                else
                {
                    SnackbarMessageQueue.Enqueue("Sorry, Your image was not verifyed! please replace the image");
                    FeedbackModel.Image = "";
                }
            }
            catch (Exception e)
            {
                SnackbarMessageQueue.Enqueue("Sorry, it is impossible to add image now");
                FeedbackModel.Image = "";
            }
        }
        public SearchResponse GetFilesPage(System.Security.Claims.ClaimsPrincipal user, string pageToken)
        {
            var service     = GoogleDriveService.GetDriveService(user);
            var listRequest = service.Files.List();

            listRequest.PageSize = 25;
            listRequest.Fields   = "nextPageToken, files(id, name, webViewLink)";
            listRequest.Q        =
                "mimeType contains 'spreadsheet'";
            string previousPageToken = null;

            if (!string.IsNullOrWhiteSpace(pageToken))
            {
                previousPageToken     = listRequest.PageToken;
                listRequest.PageToken = pageToken;
            }
            // List files.
            var listResponse  = listRequest.Execute();
            var files         = listResponse.Files.ToList();
            var nextPageToken = listResponse.NextPageToken;

            return(new SearchResponse {
                Files = files, NextPageToken = nextPageToken, PreviousPageToken = previousPageToken
            });
        }
Пример #5
0
        public static void Initialize()
        {
            var settingsDB = PlayerSettingsDB.Get();

            bool loaded = settingsDB.Load();

            if (loaded)
            {
                settingsDB.SaveBackup();
            }
            else
            {
                Logger.WriteLine("Warning: failed to load player settings!");
            }

            if (!string.IsNullOrEmpty(settingsDB.forcedLanguage))
            {
                LocalizationDB.SetCurrentUserLanguage(settingsDB.forcedLanguage);
            }

            if (settingsDB.useXInput)
            {
                XInputStub.StartPolling();
            }

            CloudStorage = new GoogleDriveService(
                GoogleClientIdentifiers.Keys,
                new GoogleOAuth2.Token()
            {
                refreshToken = settingsDB.cloudToken
            });
        }
Пример #6
0
        public ConfigurationViewModel()
        {
            _googleDriveService = GetProvider <GoogleDriveService>();

            _config = _googleDriveService.Config;

            Accounts = new ObservableCollection <AccountModelBase>(_config.Accounts);
        }
Пример #7
0
        public PresentationModel(Model model, Control canvas)
        {
            this._model = model;
            const string APPLICATION_NAME        = "DrawAnywhere";
            const string CLIENT_SECRET_FILE_NAME = "clientSecret.json";

            _service = new GoogleDriveService(APPLICATION_NAME, CLIENT_SECRET_FILE_NAME);
        }
Пример #8
0
        public static void GoogleDriveSample()
        {
            var googleDriveService = new GoogleDriveService();
            var file  = googleDriveService.CreateFolder("Arise").Result;
            var file2 = googleDriveService.CreateFolder("Folder1", file.Id).Result;

            var file3 = googleDriveService.CreateFolder("Folder3", file2.Id);
        }
        public async Task UplodingTest()
        {
            //GoogleDriveService.Init();

            string path   = @"C:\Users\Chayim\Documents\KioskInformation\Pictures\4.jpg";
            var    result = await GoogleDriveService.UploadImage(path);

            Assert.IsNotNull(result);
        }
Пример #10
0
        public FromUrl()
        {
            InitializeComponent();
            driveService = new GoogleDriveService(preferences.Model.ClientID, preferences.Model.ClientSecret, preferences.Model.ApiKey);
            msgs         = new Messages(data, logs);
            data.Url     = preferences.Model.LastUrl;

            DataContext = data;
        }
Пример #11
0
 public JsonResult Form(AuthorForm form, HttpPostedFileBase image, string imagePath)
 {
     if (image != null && image.ContentLength > 0)
     {
         var driveService = GoogleDriveService.GetDriveService();
         var fileID       = GoogleDriveService.uploadFile(driveService, image.InputStream, image.FileName, imagePath);
         form.ImageUrl = fileID;
     }
     return(SaveChanges(form, Facade <AuthorFacade>().AddAuthor));
 }
Пример #12
0
        public MainWindow(GoogleDriveService store, FileService fileService)
        {
            InitializeComponent();

            this.fileService = fileService;
            this.fileStore   = store;
            this.context     = new ApplicationViewModel(fileService);

            UpdateDbContext();
            DataContext = context;
        }
Пример #13
0
 //
 public EzPaintForm(Model model)
 {
     _model = model;
     _model._modelChange += RefreshUI;
     InitializeComponent();
     _presentationModel             = new PresentationModel(_model, _printPanel);
     _undoToolStripMenuItem.Enabled = false;
     _redoToolStripMenuItem.Enabled = false;
     SetStyle(ControlStyles.DoubleBuffer, true);
     SetStyle(ControlStyles.UserPaint, true);
     SetStyle(ControlStyles.AllPaintingInWmPaint, true);
     _service = new GoogleDriveService(APPLICATION_NAME, CLIENT_SECRET_FILE_NAME);
 }
Пример #14
0
        public HttpResponseMessage GetIn(string parent)
        {
            GoogleDriveService.MemorySelectedFolder(parent);

            var files   = GoogleDriveService.GetFiles(parent);
            var folders = GoogleDriveService.RetainFolders(files);

            return(Request.CreateResponse(HttpStatusCode.OK, new FilesResponse
            {
                files = files,
                folders = folders
            }));
        }
Пример #15
0
        public JsonResult Form(NovelForm form, HttpPostedFileBase image, string imagePath)
        {
            if (image != null && image.ContentLength > 0)
            {
                imagePath = string.IsNullOrWhiteSpace(imagePath)
                    ? "/Fanslations/Novels/" + form.Title.ToSeo()
                    : imagePath;

                var driveService = GoogleDriveService.GetDriveService();
                var fileID       = GoogleDriveService.uploadFile(driveService, image.InputStream, image.FileName, imagePath);
                form.ImageUrl = fileID;
            }
            return(SaveChanges(form, Facade <NovelFacade>().AddNovel));
        }
Пример #16
0
        static void Main(string[] args)
        {
            //load up a google drive object
            var gDrive   = new GoogleDriveService();
            var dBox     = new DropboxService();
            var oneDrive = new OneDriveService();

            Console.WriteLine($"Found Google Drive Path: {gDrive.Directory}, Service Installed? {gDrive.IsServiceInstalled()}");
            Console.WriteLine($"Found Dropbox Path: {dBox.Directory}, Service Installed? {dBox.IsServiceInstalled()}");
            Console.WriteLine($"Found OneDrive Path: {oneDrive.Directory}, Service Installed? {oneDrive.IsServiceInstalled()}");

            //pause the console
            Console.ReadKey();
        }
Пример #17
0
        public TelegramService(ILogger <TelegramService> logger, IConfiguration configuration, GoogleDriveService googleDrive)
        {
            _logger = logger;

            Configuration = configuration;
            GoogleDrive   = googleDrive;
            BotClient     = new TelegramBotClient(Configuration["ApiKey"]);

            BotClient.OnMessage += OnMessage;
            BotClient.StartReceiving();

            _logger.LogInformation("Starting listening Telegram bot with id {0} and name {1}",
                                   BotClient.BotId,
                                   BotClient.GetMeAsync().Result.Username.ToString());
        }
Пример #18
0
 public SmsController(ILogger <SmsController> logger, ICloudStorage storageClient, IConfiguration configuration, TenantFileContext context, [Service] ITopicEventSender eventSender, GoogleDriveService driveService)
 {
     this.eventSender   = eventSender;
     this.logger        = logger;
     this.storageClient = storageClient;
     this.context       = context;
     this.keyWords      = new List <string>()
     {
     };
     this.keyPhrases = new List <string>()
     {
         "written request for repairs"
     };
     this.driveService = driveService;
 }
Пример #19
0
        public HttpResponseMessage Get()
        {
            GoogleDriveService.MemorySelectedFolder(null);

            var authKeyPath = ConfigurationSettings.AppSettings["key_p12_path"];
            var keyPath     = System.Web.Hosting.HostingEnvironment.MapPath(authKeyPath);

            GoogleDriveService.Authenticate(keyPath);

            var files   = GoogleDriveService.GetRootFiles();
            var folders = GoogleDriveService.RetainFolders(files);

            return(Request.CreateResponse(HttpStatusCode.OK, new FilesResponse
            {
                files = files,
                folders = folders
            }));
        }
Пример #20
0
        //private static string ApplicationName = App.Configuration.getse;
        static async Task Main(string[] args)
        {
            #region Setup
            App.Configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                .AddCommandLine(args)
                                .Build();

            // Logging
            var configuration = TelemetryConfiguration.CreateDefault();
            configuration.TelemetryProcessorChainBuilder
            .Use(tp => new ApplicationInsightsOfflineFilter(tp))
            .Build();
            var telemetryClient = new TelemetryClient(configuration);
            #endregion


            var googleOauth = new GoogleOauth2Service();

            var credentials = await googleOauth.GetUserCredentialAsync();

            GoogleJsonWebSignature.Payload jwtPayload = await googleOauth.GetJwtPayloadAsync(credentials);

            var username = jwtPayload.Email;



            var driveService = new GoogleDriveService(credentials);

            var aboutRequest = driveService.About.Get();
            aboutRequest.Fields = "*";

            var response = await aboutRequest.ExecuteAsync();

            Console.WriteLine("Import formats");
            response.ExportFormats.ToList().ForEach(x => Console.WriteLine($"{x.Key} {x.Value.FirstOrDefault()}"));
            Console.WriteLine("Export formats");
            response.ImportFormats.ToList().ForEach(x => Console.WriteLine($"{x.Key} {x.Value.FirstOrDefault()}"));

            MailService.SendMailWithXOAUTH2(username, credentials.Token.AccessToken);
            Console.WriteLine("Finished :)");
        }
Пример #21
0
        public async Task <IHttpActionResult> Upload()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);

            foreach (var file in provider.Contents)
            {
                var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
                var stream   = await file.ReadAsStreamAsync();

                GoogleDriveService.UploadSharedFile(stream, filename);
            }

            return(Ok());
        }
Пример #22
0
        private string[] UploadSongToGoogleDrive(string fileDataUrl, string fileName)
        {
            const string AudioMimeType = "audio/mpeg";

            byte[]       byteArray = Convert.FromBase64String(fileDataUrl);
            MemoryStream stream    = new MemoryStream(byteArray);

            var service = GoogleDriveService.Get();

            File body = new File
            {
                Title    = fileName,
                MimeType = AudioMimeType,
                Parents  =
                    new List <ParentReference>
                {
                    new ParentReference
                    {
                        Id =
                            MusicConstants
                            .GoogleDriveBlastOFFMusicFolderId
                    }
                }
            };

            try
            {
                FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, AudioMimeType);
                request.Upload();

                return(new[] { "success", "http://docs.google.com/uc?export=open&id=" + request.ResponseBody.Id });
            }
            catch (Exception exception)
            {
                return(new[] { "error", string.Format("Something happened.\r\n" + exception.Message) });
            }
        }
Пример #23
0
 public GoogleDriveMusicCollection(GoogleDriveService googleDriveService, string baseCollectionFolder)
 {
     _googleDriveService   = googleDriveService ?? throw new ArgumentNullException(nameof(googleDriveService));
     _baseCollectionFolder = baseCollectionFolder ?? throw new ArgumentNullException(nameof(baseCollectionFolder));
 }
Пример #24
0
        /// <summary>
        /// Run the program service.
        /// </summary>
        /// <returns>A task.</returns>
        public async Task RunAsync()
        {
            if (_service is null)
            {
                try
                {
                    _service = await GoogleDriveService.CreateAsync(_options.CredentialsPath);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Failed to start the service.");
                    return;
                }
            }

            _logger.Information("Starting scan.");

            var count        = 0;
            var matchesCount = 0;

            // Asynchronously scan the drive(s) for files/folders with non-owner permissions.
            // Essentially this says: 'Give me all the files/folders I own, but which also have non-owner permissions'.
            await foreach (var results in _service.GetFilesAsync(query: "'me' in owners and visibility != 'limited'"))
            {
                if (results.Count > 0)
                {
                    _logger.Information("Found result(s) {start} to {end}.", count + 1, count + results.Count);
                }

                var matches = new Dictionary <File, IReadOnlyList <Permission> >();
                foreach (var result in results)
                {
                    LogFileInformation(result);
                    foreach (var permission in result.Permissions)
                    {
                        _logger.Information("{@permission}", new { permission.Role, permission.Type, permission.DisplayName });
                    }

                    var nonOwnerPermissions = result.Permissions.Where(q => q.Role != Enums.Permission.Role.Owner);
                    if (nonOwnerPermissions.Any())
                    {
                        _logger.Information("Found {count} non-owner permission(s).", nonOwnerPermissions.Count());
                        matches.Add(result, nonOwnerPermissions.ToList());
                    }
                }

                // Remove permissions if matches found and remove flag is specified.
                if (matches.Any() && _options.RemoveNonOwnerPermissions)
                {
                    await RemoveNonOwnerPermissionsAsync(matches);
                }

                count        += results.Count;
                matchesCount += matches.Count;
            }

            if (_options.RemoveNonOwnerPermissions && matchesCount == 0)
            {
                _logger.Warning($"Remove flag specified, but no matching result(s) found.");
            }
            else if (!_options.RemoveNonOwnerPermissions)
            {
                _logger.Warning($"Remove flag not specified.");
            }

            _logger.Information("Finished! Found {matchesCount} result(s) with non-owner permissions.", matchesCount);
        }
Пример #25
0
 public void Delete(string id)
 {
     GoogleDriveService.DeleteFile(id);
 }
Пример #26
0
 public void GetFolders(string parent)
 {
     GoogleDriveService.GetFolders(parent);
 }
Пример #27
0
 // prepare service
 private void PrepareService()
 {
     _service = new GoogleDriveService(APPLICATION_NAME, CLIENT_SECRET_FILE_NAME);
 }
Пример #28
0
 public void CreateFolder(CreateFolderRequest req)
 {
     GoogleDriveService.CreateFolder(req.folderName, req.folderDesc, req.parentId);
 }
Пример #29
0
 public void Share(string id)
 {
     GoogleDriveService.Share(id);
 }
Пример #30
0
 public void GetFolders()
 {
     GoogleDriveService.GetFolders();
 }