Example #1
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                #region credentials
                //ENTER CREDENTIALS
                userCreds.Username = "";
                userCreds.Password = "";
                userCreds.Referer = "";
                #endregion
                //

                Console.WriteLine("Authenticating user");
                AGOLClient client = new AGOLClient(userCreds);

                TokenParameters tokenParams = new TokenParameters();
                tokenParams.Username = userCreds.Username;
                tokenParams.Password = userCreds.Password;
                tokenParams.Expiration = "540";
                tokenParams.Referer = userCreds.Referer;
                token = client.GenerateToken(tokenParams);

                string file = args[0];
                string filename = file.Substring(file.LastIndexOf('\\') + 1);

                Console.WriteLine("Uploading shapefile");
                AddItemParameters addItemParams = new AddItemParameters();
                addItemParams.ItemInfoParameters.Type = "Shapefile";
                addItemParams.File = file;
                addItemParams.Filename = filename;

                addItemParams.Async = true;
                addItemParams.ItemInfoParameters.Title = filename.Substring(0, filename.Length - 4);
                addItemParams.ItemInfoParameters.Tags = filename.Substring(0, filename.Length - 4);

                JsonAddItemResponse addItemResponse = client.AddItem(addItemParams, token);
                if (addItemResponse.success)
                {
                    Console.WriteLine(string.Format("{0}\n", addItemResponse.id));

                    Console.WriteLine("Preparing item for publishing...");
                    StatusManager statusManager = new StatusManager(userCreds, token);
                    statusManager.CheckStatusCompletedEvent += new CheckStatusCompletedEventHandler(CheckStatusCompletedEventHandler);

                    //TODO: make a synchronous version of CheckStatus(), in case the user wants a blocking call
                    Task t = statusManager.CheckStatusAsync(addItemResponse.id);
                }
                else
                {
                    Console.WriteLine(string.Format("Upload failed {0}\n", addItemResponse.id));
                }
            }
            else
            {
                Console.WriteLine("Please specify a shapefile as an input parameter at runtime");
            }

            //press Esc to quit
            while (true)
            {
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) break;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            //ENTER CREDENTIALS
            #region credentials
            userCreds.Username = "";
            userCreds.Password = "";
            userCreds.Referer = "";
            #endregion
            //

            Console.WriteLine("Authenticating user\n");
            AGOLClient client = new AGOLClient(userCreds);

            TokenParameters tokenParams = new TokenParameters();
            tokenParams.Username = userCreds.Username;
            tokenParams.Password = userCreds.Password;
            tokenParams.Expiration = "540";
            tokenParams.Referer = userCreds.Referer;
            token = client.GenerateToken(tokenParams);

            foreach (string arg in args)
            {
                Console.WriteLine("Uploading shapefile");
                AddItemParameters addItemParams = new AddItemParameters();
                addItemParams.ItemInfoParameters.Type = "Shapefile";
                addItemParams.File = arg;
                string name = arg.Substring(arg.LastIndexOf('\\') + 1);
                addItemParams.Filename = name;

                addItemParams.Async = true;
                addItemParams.ItemInfoParameters.Title = name.Substring(0, name.Length-4);
                addItemParams.ItemInfoParameters.Tags = "bulkupload";

                JsonAddItemResponse addItemResponse = client.AddItem(addItemParams, token);
                if (addItemResponse.success)
                {
                    Console.WriteLine(string.Format("{0}\nid {1}\nPreparing item for publishing...\n", addItemResponse.item, addItemResponse.id));
                    StatusManager statusManager = new StatusManager(userCreds, token);
                    statusManager.CheckStatusCompletedEvent += new CheckStatusCompletedEventHandler(CheckStatusCompletedEventHandler);

                    Task t = statusManager.CheckStatusAsync(addItemResponse.id);
                }
                else
                {
                    Console.WriteLine(string.Format("Upload failed {0}\n", addItemResponse.id));
                }

            }

            //press Esc to quit
            while (true)
            {
                if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) break;
            }
        }