예제 #1
0
        public override void Import(params DataStream[] strIn)
        {
            // If the cache does not contain this key, it meas we don't have to update.
            if (!cache.Contains(spreadsheetKey))
            {
                return;
            }

            // Get the worksheet from GDrive.
            Worksheet worksheet;

            try {
                worksheet = service.RetrieveWorksheet(spreadsheetKey, worksheetId);
            } catch (Google.GData.Client.GDataRequestException) {
                // Capture errors since if there isn't Internet connection
                // we don't want to abort the process.
                Console.WriteLine("ERROR: Can't get spreadhseet {0}", spreadsheetKey);
                return;
            }

            // Convert to XML
            var importedXml = new WorksheetToXml(worksheet).Convert();

            // Save to the path creating the directory if needed.
            Directory.CreateDirectory(Path.GetDirectoryName(output));
            importedXml.Save(output);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // Check if the argument is to update config files
            if (args.Length == 4 && args[0] == "-u")
            {
                Console.WriteLine("Starting modime config updater");
                ModimeConfigurationGenerator.UpdateWithSpreadsheet(args[1], args[2],
                                                                   args[3]);
                Console.WriteLine("Done");
                return;
            }

            // Get and create the output directory.
            string outDir;

            if (args.Length > 1)
            {
                outDir = args[0];
            }
            else
            {
                outDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                outDir = Path.Combine(outDir, "output");
            }

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            // Get the services and start working.
            var service = new SpreadsheetsService();

            // Ask for file names.
            while (true)
            {
                // Get the requested SpreadhSheet title.
                Console.WriteLine();
                Console.Write("Type the file title (\"exit\" to quit)> ");
                string title = Console.ReadLine();
                if (title == "exit")
                {
                    break;
                }

                // Search for it
                var spreadsheets = service.SearchSpreadsheets(title, 0).ToArray();
                var targetSheet  = SelectSpreadsheet(spreadsheets);
                if (targetSheet == null)
                {
                    continue;
                }

                // Check that it's a valid spreadsheet by comparing the name
                // All the converted XML are written into the first worksheet.
                var worksheet = targetSheet[0];
                var name      = worksheet[0, 0]; // Written into the first cell.
                if (string.IsNullOrEmpty(name) || !name.StartsWith("Filename "))
                {
                    Console.WriteLine("Invalid spreadsheet name. Please verify it.");
                    continue;
                }

                name = name.Substring("Filename ".Length);

                // Convert.
                Console.WriteLine("Converting {0}...", name);
                var xml = new WorksheetToXml(worksheet).Convert();

                // If it's a subtitle script, the root tag has an attribute with name
                if (xml.Root.Name == "Subtitle")
                {
                    xml.Root.SetAttributeValue("Name", name);
                }

                xml.Save(Path.Combine(outDir, name + ".xml"));
            }
        }