/// <summary>
    /// Executes the task asynchronously.
    /// </summary>
    /// <returns></returns>
    public async Task ExecuteAsync()
    {
        var config = _application.Config;

        await using var fileStream = new FileStream(ApplicationConfig.GetAbsoluteAppLocation(_application), FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 524288);
        var indexApi = new IndexApi();
        var index    = await indexApi.GetIndexAsync();

        var hash         = Hashing.ToString(await Hashing.FromStreamAsync(fileStream));
        var applications = index.FindApplication(hash, config.AppId, out bool hashMatches);

        await await ActionWrappers.ExecuteWithApplicationDispatcherAsync(async() =>
        {
            if (applications.Count == 1 && hashMatches)
            {
                ApplyIndexEntry(await indexApi.GetApplicationAsync(applications[0]), _application, hash);
            }
            else if (applications.Count >= 1)
            {
                // Select application.
                var viewModel = new SelectAddedGameDialogViewModel(applications);
                var result    = Actions.ShowSelectAddedGameDialog(viewModel);
                if (result == null)
                {
                    return;
                }

                ApplyIndexEntry(await indexApi.GetApplicationAsync(result), _application, hash);
            }
        });
    }
Ejemplo n.º 2
0
 public HttpResponseMessage Index(IndexApi api)
 {
     if (ModelState.IsValid && api != null)
     {
         // var response = new HttpRequest();
         return(Request.CreateResponse(System.Net.HttpStatusCode.OK));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "No Value"));
     }
 }
    private async Task InitializeApiAsync()
    {
        try
        {
            var indexApi = new IndexApi();
            var index    = await indexApi.GetIndexAsync();

            var packages = await index.TryGetGameBananaPackageList(GameId);

            if (packages.result)
            {
                _indexPackageProvider = new IndexPackageProvider(packages.list);
                _initializedApi       = true;
            }
        }
        catch (Exception) { /* ignored */ }

        _initializeComplete = true;
    }
    private async Task ExecuteInternal(IJobExecutionContext context)
    {
        // Pull from Git
        _gitPusherService.ResetToRemote();

        // Build
        var watch  = Stopwatch.StartNew();
        var source = (SourceEntry)context.MergedJobDataMap[JobSourceEntryKey];

        // Create Index
        var builder = new IndexBuilder();

        builder.Sources.Add(source);

        // Update Index
        var indexApi = new IndexApi(_settings.GitRepoPath);
        var index    = await indexApi.GetOrCreateLocalIndexAsync();

        index = await builder.UpdateAsync(index, false);

        // Delete Unused
        var cleanupBuilder = new IndexBuilder();

        cleanupBuilder.Sources.AddRange(_settings.Sources);
        cleanupBuilder.RemoveNotInBuilder(index);
        await cleanupBuilder.WriteToDiskAsync(index);

        // Update Stats
        _stats.TotalBuilds        += 1;
        _stats.BuildsSinceStarted += 1;
        await _stats.WriteAsync();

        // Notify others.
        await _mediator.Publish(new BuildFinishedNotification()
        {
            Entry   = source,
            Runtime = watch.Elapsed,
        });

        // Push to git.
        _gitPusherService.Push();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Gets an index from local folder, or returns a dummy.
    /// </summary>
    public static async Task <Structures.Index> GetOrCreateLocalIndexAsync(this IndexApi api)
    {
        var uri = new Uri(api.IndexUrl, Routes.Index);

        if (!uri.IsFile)
        {
            throw new ArgumentException("The index API was created with a non-local path.");
        }

        if (!File.Exists(uri.LocalPath))
        {
            return new Structures.Index()
                   {
                       BaseUrl = api.IndexUrl
                   }
        }
        ;

        return(await api.GetIndexAsync());
    }
}
    private async Task InitializeApiAsync(string?appId)
    {
        try
        {
            var indexApi = new IndexApi();
            var index    = await indexApi.GetIndexAsync();

            var packages = await index.TryGetNuGetPackageList(SourceUrl);

            if (packages.result)
            {
                // Filter out by tag if app requested
                if (!string.IsNullOrEmpty(appId))
                {
                    packages.list.Packages = packages.list.Packages.Where(x => x.Tags != null && x.Tags.Contains(appId, StringComparer.OrdinalIgnoreCase)).ToList();
                }

                _indexPackageProvider = new IndexPackageProvider(packages.list);
                _initializedApi       = true;
            }
        }
        catch (Exception) { /* ignored */ }
    }
Ejemplo n.º 7
0
 public void Init()
 {
     instance = new IndexApi();
 }
Ejemplo n.º 8
0
        public void CreateTestDatabase()
        {
            IndexApi.RebuildIndex("TestQueryConfig", "Patient");
            IndexApi.RebuildIndex("TestQueryConfig", "Address");
            IndexApi.RebuildIndex("TestQueryConfig", "Policy");

            var    managerConfig   = ManagerFactoryConfiguration.BuildConfigurationManager();
            string configurationId = "TestQueryConfig";
            var    testconfig      = managerConfig.CreateItem(configurationId);

            managerConfig.MergeItem(testconfig);

            var managerDocument = new ManagerFactoryConfiguration(configurationId).BuildDocumentManager();

            dynamic documentMetadata1 = managerDocument.CreateItem("Patient");
            dynamic documentMetadata2 = managerDocument.CreateItem("Address");
            dynamic documentMetadata3 = managerDocument.CreateItem("Policy");


            documentMetadata1.Schema                       = new DynamicWrapper();
            documentMetadata1.Schema.Name                  = "Patient";
            documentMetadata1.Schema.Caption               = "Patient";
            documentMetadata1.Schema.Properties            = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Id         = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Id.Type    = "Uuid";
            documentMetadata1.Schema.Properties.Id.Caption = "Unique identifier";

            documentMetadata1.Schema.Properties.Name         = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Name.Type    = "String";
            documentMetadata1.Schema.Properties.Name.Caption = "Patient name";

            //weak reference
            documentMetadata1.Schema.Properties.Address          = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Address.Type     = "Object";
            documentMetadata1.Schema.Properties.Address.TypeInfo = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Address.TypeInfo.DocumentLink            = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Address.TypeInfo.DocumentLink.ConfigId   = configurationId;
            documentMetadata1.Schema.Properties.Address.TypeInfo.DocumentLink.DocumentId = "Address";
            documentMetadata1.Schema.Properties.Address.Caption = "Patient address";

            //inline reference
            documentMetadata1.Schema.Properties.Policies                = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Policies.Type           = "Array";
            documentMetadata1.Schema.Properties.Policies.Caption        = "Policies";
            documentMetadata1.Schema.Properties.Policies.Items          = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Policies.Items.Type     = "Object";
            documentMetadata1.Schema.Properties.Policies.Items.TypeInfo = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Policies.Items.TypeInfo.DocumentLink            = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Policies.Items.TypeInfo.DocumentLink.ConfigId   = configurationId;
            documentMetadata1.Schema.Properties.Policies.Items.TypeInfo.DocumentLink.DocumentId = "Policy";
            documentMetadata1.Schema.Properties.Policies.Items.TypeInfo.DocumentLink.Inline     = true;

            documentMetadata1.Schema.Properties.Phones            = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Phones.Type       = "Array";
            documentMetadata1.Schema.Properties.Phones.Caption    = "Phones";
            documentMetadata1.Schema.Properties.Phones.Items      = new DynamicWrapper();
            documentMetadata1.Schema.Properties.Phones.Items.Type = "String";

            documentMetadata2.Schema                       = new DynamicWrapper();
            documentMetadata2.Schema.Name                  = "Address";
            documentMetadata2.Schema.Caption               = "Address";
            documentMetadata2.Schema.Properties            = new DynamicWrapper();
            documentMetadata2.Schema.Properties.Id         = new DynamicWrapper();
            documentMetadata2.Schema.Properties.Id.Type    = "Uuid";
            documentMetadata2.Schema.Properties.Id.Caption = "Unique identifier";

            documentMetadata2.Schema.Properties.Street         = new DynamicWrapper();
            documentMetadata2.Schema.Properties.Street.Type    = "String";
            documentMetadata2.Schema.Properties.Street.Caption = "Address street";

            documentMetadata3.Schema            = new DynamicWrapper();
            documentMetadata3.Schema.Name       = "Policy";
            documentMetadata3.Schema.Caption    = "Policy";
            documentMetadata3.Schema.Properties = new DynamicWrapper();

            documentMetadata3.Schema.Properties.Id         = new DynamicWrapper();
            documentMetadata3.Schema.Properties.Id.Type    = "Uuid";
            documentMetadata3.Schema.Properties.Id.Caption = "Unique identifier";

            documentMetadata3.Schema.Properties.Number         = new DynamicWrapper();
            documentMetadata3.Schema.Properties.Number.Type    = "String";
            documentMetadata3.Schema.Properties.Number.Caption = "Policy number";


            managerDocument.MergeItem(documentMetadata1);
            managerDocument.MergeItem(documentMetadata2);
            managerDocument.MergeItem(documentMetadata3);

            RestQueryApi.QueryPostNotify(configurationId, TODO);

            var addressId = Guid.NewGuid().ToString();
            var policy1Id = Guid.NewGuid().ToString();
            var policy2Id = Guid.NewGuid().ToString();

            dynamic testDocument1 = new DynamicWrapper();

            testDocument1.Id                  = Guid.NewGuid().ToString();
            testDocument1.Name                = "Ivanov";
            testDocument1.Address             = new DynamicWrapper();
            testDocument1.Address.Id          = addressId;
            testDocument1.Address.DisplayName = "г. Челябинск";

            testDocument1.Policies = new List <dynamic>();
            testDocument1.Policies.Add(new DynamicWrapper());
            testDocument1.Policies.Add(new DynamicWrapper());

            testDocument1.Policies[0].Id     = policy1Id;
            testDocument1.Policies[0].Number = "7070";

            testDocument1.Policies[1].Id     = policy2Id;
            testDocument1.Policies[1].Number = "7070";

            testDocument1.Phones = new List <dynamic>();
            testDocument1.Phones.Add("89226567890");
            testDocument1.Phones.Add("89121234567");

            new DocumentApi().SetDocument("TestQueryConfig", "Patient", testDocument1);


            dynamic testAddress1 = new DynamicWrapper();

            testAddress1.Id     = addressId;
            testAddress1.Street = "г. Челябинск, пр. Ленина";

            new DocumentApi().SetDocument("TestQueryConfig", "Address", testAddress1);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            try
            {
                var util      = new UtilsApi();
                var searchApi = new SearchApi();
                var indexApi  = new IndexApi();

                Dictionary <string, object> result;
                try
                {
                    result = util.Sql(@"query=select * from products");
                    foreach (var item in result)
                    {
                        Console.WriteLine($"{item.Key} - {item.Value}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                var rs = util.Sql("mode=raw&query=create table products(title text, price float) morphology='stem_en'");

                Console.WriteLine("Create result " + rs.Count + Environment.NewLine);

                rs = util.Sql("mode=raw&query=SELECT * FROM products");

                Console.WriteLine("Select result " + rs.Count + Environment.NewLine);

                var newdoc = new InsertDocumentRequest();
                Dictionary <string, object> doc = new Dictionary <string, object>();
                doc.Add("title", "Crossbody Bag with Tassel");
                doc.Add("price", 19.85);

                newdoc.Index("products").Id(0).SetDoc(doc);
                var insertResult = indexApi.Insert(newdoc);

                Console.WriteLine(insertResult + Environment.NewLine);

                newdoc = new InsertDocumentRequest();
                doc    = new Dictionary <string, object>();

                doc.Add("title", "microfiber sheet set");
                doc.Add("price", 19.99);
                newdoc.Index("products").Id(0).SetDoc(doc);
                insertResult = indexApi.Insert(newdoc);

                Console.WriteLine(insertResult + Environment.NewLine);

                newdoc = new InsertDocumentRequest();
                doc    = new Dictionary <string, object>();
                doc.Add("title", "Pet Hair Remover Glove");
                doc.Add("price", 7.99);
                newdoc.Index("products").Id(0L).SetDoc(doc);
                insertResult = indexApi.Insert(newdoc);

                Console.WriteLine(insertResult + Environment.NewLine);

                var query = new Dictionary <string, object>();
                var match = new Dictionary <string, object>()
                {
                    { "title", "crossbody" }
                };
                query.Add("match", match);
                var searchRequest = new SearchRequest();
                searchRequest.SetIndex("products");
                searchRequest.SetQuery(query);
                Dictionary <string, object> highlight = new Dictionary <string, object>();
                highlight.Add("fields", new string[] { "title" });
                searchRequest.SetHighlight(highlight);
                var searchResponse = searchApi.Search(searchRequest);

                Console.WriteLine(searchResponse + Environment.NewLine);

                UpdateDocumentRequest updateRequest = new UpdateDocumentRequest();
                doc = new Dictionary <string, object>();
                doc.Add("price", 17.5);
                updateRequest.Index("products").Id(2L).SetDoc(doc);
                var updResult = indexApi.Update(updateRequest);

                Console.WriteLine(updResult + Environment.NewLine);

                DeleteDocumentRequest deleteRequest = new DeleteDocumentRequest();
                var condition = new Dictionary <string, object>()
                {
                    { "lte", 10 }
                };
                var field = new Dictionary <string, object>()
                {
                    { "price", condition }
                };
                query = new Dictionary <string, object>()
                {
                    { "range", field }
                };

                deleteRequest.Index("products").SetQuery(query);
                var deleteResult = indexApi.Delete(deleteRequest);

                Console.WriteLine(deleteResult + Environment.NewLine);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }