コード例 #1
0
ファイル: WatchImpl.cs プロジェクト: xwyangjshb/etcdclientv3
 private static bool isHaltError(Grpc.Core.Status status)
 {
     // Unavailable codes mean the system will be right back.
     // (e.g., can't connect, lost leader)
     // Treat Internal codes as if something failed, leaving the
     // system in an inconsistent state, but retrying could make progress.
     // (e.g., failed in middle of send, corrupted frame)
     return(status.StatusCode != Grpc.Core.StatusCode.Unavailable && status.StatusCode != Grpc.Core.StatusCode.Internal);
 }
コード例 #2
0
        public void FSCreateDocument()
        {
            FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Creating a new Document ::\n");
            FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Collection [cities]: ");
            string collectionId = Console.ReadLine();

            if (collectionId == "")
            {
                collectionId = "cities";
            }

            FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\nEnter Document: ");
            var docId            = Console.ReadLine();
            var createDocRequest = new CreateDocumentRequest();

            createDocRequest.Parent       = Parent;
            createDocRequest.DocumentId   = docId;
            createDocRequest.CollectionId = collectionId;
            var fsDocument = new Document();

            createDocRequest.Document = fsDocument;
            try
            {
                fsDocument = FsClient.CreateDocument(createDocRequest);
            }
            catch (Grpc.Core.RpcException e)
            {
                Grpc.Core.Status stat = e.Status;
                if (stat.StatusCode == Grpc.Core.StatusCode.AlreadyExists)
                {
                    FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nDocument already exists.");
                }
                FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Yellow, "\n" + stat.Detail);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }

            // get the document to ensure it was created
            Document retDoc;

            try
            {
                retDoc = GetDocument(docId, collectionId);
            }
            catch (Grpc.Core.RpcException e)
            {
                if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound)
                {
                    FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nDocument was not added.");
                }
                FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\n" + e.Status.Detail);
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return;
            }
            FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully created new document!\nName:" + retDoc.Name + "\n");
        }
コード例 #3
0
ファイル: WatchImpl.cs プロジェクト: xwyangjshb/etcdclientv3
 private static bool IsNoLeaderError(Grpc.Core.Status status)
 {
     return(status.StatusCode == Grpc.Core.StatusCode.Unavailable &&
            "etcdserver: no leader".Equals(status.Detail));
 }
コード例 #4
0
        public void FSCreateIndex()
        {
            FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\n:: Creating a Index ::\n");
            var index = new Index();

            while (true)
            {
                FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Field Name (blank when finished): ");
                string fieldName = Console.ReadLine();
                if (fieldName != "")
                {
                    FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.White, "\nEnter Mode (ASCENDING/DESCENDING) [ASCENDING]: ");
                    string fieldMode = Console.ReadLine();
                    IndexField.Types.Mode indexFieldMode = IndexField.Types.Mode.Ascending;
                    if (fieldMode == "" || fieldMode == "ASCENDING")
                    {
                        indexFieldMode = IndexField.Types.Mode.Ascending;
                    }
                    else
                    if (fieldMode == "DESCENDING")
                    {
                        indexFieldMode = IndexField.Types.Mode.Descending;
                    }
                    else
                    if (fieldMode != "ASCENDING" && fieldMode != "DESCENDING")
                    {
                        FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nUnrecognized Mode - Choosing ASCENDING");
                        indexFieldMode = IndexField.Types.Mode.Ascending;
                    }
                    var indexField = new IndexField();
                    indexField.FieldPath = fieldName;
                    indexField.Mode      = indexFieldMode;
                    index.Fields.Add(indexField);
                }
                else
                {
                    var createIndexRequest = new CreateIndexRequest();
                    createIndexRequest.Parent = Parent;
                    index.CollectionId        = BaseCollectionId;
                    createIndexRequest.Index  = index;
                    try
                    {
                        Operation operation = FsAdminClient.CreateIndex(createIndexRequest);
                    }
                    catch (Grpc.Core.RpcException e)
                    {
                        Grpc.Core.Status stat = e.Status;
                        if (stat.StatusCode == Grpc.Core.StatusCode.AlreadyExists)
                        {
                            Console.WriteLine("\nIndex already exists.");
                        }
                        Console.WriteLine(stat.Detail);
                    }
                    catch (Exception e)
                    {
                        FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Red, "\nException caught\n" + e.Message);
                    }
                    break;
                }
            }
            FirestoreTestUtils.ColoredConsoleWrite(ConsoleColor.Green, "\nSuccessfully created new index!\n");
        }