예제 #1
0
 //read shapes from local document
 public List <Shape> ReadShapes()
 {
     _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.DownloadFile(foundFile);
         FileStream      fileStream      = new FileStream(FILE_NAME, FileMode.Open);
         BinaryFormatter binaryFormatter = new BinaryFormatter();
         return(binaryFormatter.Deserialize(fileStream) as List <Shape>);
     }
     else
     {
         return(null);
     }
 }
예제 #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);
                }
            }
        }
예제 #3
0
        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);
            }
        }