Exemple #1
0
        //save shapes to local document
        public void SaveShapes(List <Shape> shapes)
        {
            const string    CONTENT_TYPE    = "application/octet-stream";
            FileStream      fileStream      = new FileStream(FILE_NAME, FileMode.Create);
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            binaryFormatter.Serialize(fileStream, shapes);
            fileStream.Close();
            _fileList = _service.ListRootFileAndFolder();
            if (_fileList.Exists(file => file.Title == FILE_NAME))
            {
                Google.Apis.Drive.v2.Data.File foundFile = _fileList.Find(item => { return(item.Title == FILE_NAME); });
                _service.UpdateFile(FILE_NAME, foundFile.Id, CONTENT_TYPE);
            }
            else
            {
                _service.UploadFile(FILE_NAME, CONTENT_TYPE);
            }
        }
Exemple #2
0
        // 按下瀏覽按鈕
        private void ClickLoad(object sender, EventArgs e)
        {
            const String DOWNLOAD_QUESTION = "要下載嗎";
            const String QUESTION          = "Question";
            DialogResult dialogResult      = MessageBox.Show(DOWNLOAD_QUESTION, QUESTION, MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                const String PATH = "./";
                List <Google.Apis.Drive.v2.Data.File> rootFolderFile = _service.ListRootFileAndFolder();
                Google.Apis.Drive.v2.Data.File        selectedFile   = rootFolderFile[(int)9m];
                _service.DownloadFile(selectedFile, PATH);
                using (Stream stream = File.Open(FILE_NAME, FileMode.Open))
                {
                    var           binaryFormatter = new BinaryFormatter();
                    List <IShape> items           = (List <IShape>)binaryFormatter.Deserialize(stream);
                    _model.ReloadAllShapes(items);
                }
            }
        }
        //click save
        private void ClickSaveButton(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(_panel.Width, _panel.Height);

            _panel.DrawToBitmap(bitmap, new Rectangle(0, 0, _panel.Width, _panel.Height));
            bitmap.Save(FILENAME);
            const string CONTENT_TYPE = "image/jpeg";
            List <Google.Apis.Drive.v2.Data.File> fileList = _service.ListRootFileAndFolder();

            Google.Apis.Drive.v2.Data.File foundFile = fileList.Find(item => { return(item.Title == FILENAME); });
            int exist = fileList.FindIndex(item => { return(item.Title == FILENAME); });

            if (exist != -1)
            {
                _service.UpdateFile(FILENAME, foundFile.Id, CONTENT_TYPE);
            }
            else
            {
                _service.UploadFile(FILENAME, CONTENT_TYPE);
            }
        }
        public Form1()
        {
            const string APPLICATION_NAME        = "DrawAnywhere";
            const string CLIENT_SECRET_FILE_NAME = "clientSecret.json";
            const string PATH = "C:/Users/user/Desktop";

            InitializeComponent();
            //
            // prepare presentation model and model
            //
            _model                = new DrawingModel.Model();
            _presentationModel    = new PresentationModel.PresentationModel(_model, _panel);
            _model._modelChanged += HandleModelChanged;
            _service              = new GoogleDriveService(APPLICATION_NAME, CLIENT_SECRET_FILE_NAME);
            List <Google.Apis.Drive.v2.Data.File> fileList = _service.ListRootFileAndFolder();

            Google.Apis.Drive.v2.Data.File foundFile = fileList.Find(item => { return(item.Title == FILENAME); });
            int find = fileList.FindIndex(item => { return(item.Title == FILENAME); });

            if (find != -1)
            {
                _service.DownloadFile(foundFile, PATH);
            }
        }