コード例 #1
0
        static private async System.Threading.Tasks.Task <string> SendFile(DriveService driveService, IsolatedStorageFile storage, string fileName)
        {
            FilesResource.CreateMediaUpload requestFl;

            GoogleFile body = new GoogleFile();

            body.Name        = System.IO.Path.GetFileName(fileName);
            body.Description = "Test upload v4";
            body.MimeType    = "application/zip";
            body.Parents     = new List <string>()
            {
                GoogleDrive.idGoogleFolder
            };

            // Logger.Log.Info("Send file: " + nameFile);
            IsolatedStorageFileStream stream2 = new IsolatedStorageFileStream(fileName, FileMode.Open, storage);

            requestFl = driveService.Files.Create(body, stream2, "application/zip");
            IUploadProgress response = await requestFl.UploadAsync();

            stream2.Close();

            if (response.Exception != null)
            {
                Cliest.eventLog.WriteEntry($"{response.Exception.Message}, file: {fileName}", EventLogEntryType.Warning, 785);
                ListIsoStorageFile.Add(fileName);
                throw new Exception(response.Exception.Message);
            }
            // Logger.Log.Info("Send file " + nameFile + " complited");
            var Rfile = requestFl.ResponseBody;

            storage.DeleteFile(fileName);
            return(Rfile.Id);
        }
コード例 #2
0
        static public async System.Threading.Tasks.Task <List <string> > UploadFilesAsync(DriveService driveService)
        {
            List <string> UploadListFileId = new List <string>();

            IsolatedStorageFile machine = IsolatedStorageFile.GetMachineStoreForAssembly();

            long epochTicks = new DateTime(1970, 1, 1).Ticks;
            long unixTime   = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);

            string ZipFileName  = $"package_{unixTime}.zip";
            string idGoogleFile = "";

            using (IsolatedStorageFileStream fsZip = new IsolatedStorageFileStream(ZipFileName, FileMode.Create, machine))
            {
                using (ZipOutputStream s = new ZipOutputStream(fsZip))
                {
                    while (ListIsoStorageFile.ListFile.Count > 0)
                    {
                        string nameFile = ListIsoStorageFile.Get();

                        if (nameFile.EndsWith(".zip"))
                        {
                            idGoogleFile = await SendFile(driveService, machine, nameFile);

                            UploadListFileId.Add($"{nameFile} ({idGoogleFile})");
                            Cliest.eventLog.WriteEntry($"Resend {nameFile} ({idGoogleFile})", EventLogEntryType.Warning, 786);
                            continue;
                        }

                        try
                        {
                            IsolatedStorageFileStream stream = new IsolatedStorageFileStream(nameFile, FileMode.Open, machine);

                            s.PutNextEntry(nameFile);
                            byte[] buffer = ReadToEnd(stream);
                            s.Write(buffer, 0, buffer.Length);
                            stream.Close();
                            UploadListFileId.Add(nameFile);
                            machine.DeleteFile(nameFile);
                        }
                        catch (Exception ex)
                        {
                            Cliest.eventLog.WriteEntry($"{ex.Message} ({nameFile}), count: {ListIsoStorageFile.ListFile.Count}", EventLogEntryType.Error, 781);
                            ListIsoStorageFile.Add(nameFile);
                        }
                    }
                }
            }

            idGoogleFile = await SendFile(driveService, machine, ZipFileName);

            UploadListFileId.Add(idGoogleFile);

            return(UploadListFileId);
        }
コード例 #3
0
ファイル: datacollection.cs プロジェクト: degid/DCTR-system
        internal void Save()
        {
            long epochTicks = new DateTime(1970, 1, 1).Ticks;
            long unixTime   = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);

            FileName += $"_{unixTime}.json";

            IsolatedStorageFile       machine = IsolatedStorageFile.GetMachineStoreForAssembly();
            IsolatedStorageFileStream stream  = new IsolatedStorageFileStream(FileName, FileMode.Create, machine);

            StreamWriter str = new StreamWriter(stream);

            str.WriteLine(json);
            str.Close();
            ListIsoStorageFile.Add(FileName);
        }