Example #1
0
        /// <summary>
        /// Annotation to the use of the ConfigureAwait method:
        ///     Because console application by default lack a SynchronizationContext the ConfigureAwait method will have no effect.
        ///     Nevertheless one should always specify ConfigureAwait to make the code reusable and to prevent exceptions when adding a library that installs a SynchronizationContext.
        /// http://stackoverflow.com/questions/25817703/configureawaitfalse-not-needed-in-console-win-service-apps-right
        /// https://msdn.microsoft.com/en-us/magazine/jj991977.aspx
        /// </summary>
        static async Task MainAsync(string[] args)
        {
            var client = new PlatformClient(rootUri, user, password, TimeSpan.FromMilliseconds(60000), organization);

            var org = client.Conn.Organizations.FirstOrDefault();

            if (org == null)
            {
                throw new OrganizationNotFoundException($"No Organizations found.");
            }

            var fc =
                await
                org.GetFileCabinetsFromFilecabinetsRelationAsync()
                .ContinueWith(
                    t => t.Result.Content
                    .FileCabinet.FirstOrDefault(f => !f.IsBasket))
                .ConfigureAwait(false);

            if (fc == null)
            {
                throw new FileCabinetNotFoundException($"No filecabinet found for user {user}.");
            }


            Console.WriteLine($"Selected FileCabinet: {fc.Name}");
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            // configure the system
            var store = @"C:\LokadData\dp-store";
            // scan "default" event container
            var reader = PlatformClient.ConnectToEventStoreAsReadOnly(store, storeId: "default");
            var views  = PlatformClient.ConnectToViewStorage(store, "sample2-views");

            // Load view, in case this console continues previous work
            var data = views.ReadAsJsonOrGetNew <Sample2Data>(ViewName);

            // print it for debug purposes
            PrintDataToConsole(data, true);

            // this process runs incrementally until stopped
            while (true)
            {
                try
                {
                    ProcessNextIncrementOfEventsOrSleep(data, reader, views);
                }
                catch (Exception ex)
                {
                    // print and sleep on error
                    Console.WriteLine(ex);
                    Thread.Sleep(1000);
                }
            }
        }
Example #3
0
        public IHttpActionResult Post(DlgInfos dlgInfos)
        {
            PlatformClient platformClient = null;

            try
            {
                platformClient = new PlatformClient("http://localhost/", "Peters Engineering", "admin", "admin");


                Validator validator = new Validator();
                validator.HasAmountOnInvoice(dlgInfos);
                validator.IsPendingDateInFuture(dlgInfos);
                validator.ProjectExistsInExternalApp(dlgInfos);

                platformClient.IsDuplicate(dlgInfos);

                return(Json(new ValidationResponseModel(ValidationResponseStatus.OK, "Everything was fine!")));
            }
            catch (Exception ex)
            {
                return(Json(CreateErrorResponse(ex)));
            }
            finally
            {
                platformClient?.Logout();
            }
        }
Example #4
0
        static void Main()
        {
            RawDataPath     = ConfigurationManager.AppSettings["RawDataPath"];
            StorePath       = ConfigurationManager.AppSettings["StorePath"];
            StoreConnection = ConfigurationManager.AppSettings["StoreConnection"];

            Console.WriteLine("This is Sample3.Dump tool");
            Console.WriteLine("Using settings from the .config file");
            Console.WriteLine("  RawDataPath (put stack overflow dump here): {0}", RawDataPath);
            Console.WriteLine("  StoreDataPath: {0}", StorePath);
            Console.WriteLine("  StoreConnection: {0}", StoreConnection);

            _reader = PlatformClient.ConnectToEventStore(StorePath, "sample3", StoreConnection);
            Thread.Sleep(2000); //waiting for server initialization

            var threads = new List <Task>
            {
                Task.Factory.StartNew(DumpComments,
                                      TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness),
                Task.Factory.StartNew(DumpPosts,
                                      TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness),
                Task.Factory.StartNew(DumpUsers,
                                      TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness)
            };

            Task.WaitAll(threads.ToArray());
        }
 public DAPIClient()
 {
     _rpcConnector = new RpcConnector();
     System.AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
     channel        = GrpcChannel.ForAddress(gRPCServer);
     coreClient     = new CoreClient(channel);
     platformClient = new PlatformClient(channel);
     transactionsFilterStreamClient = new TransactionsFilterStreamClient(channel);
 }
Example #6
0
        public Client(ClientOptions options)
        {
            Options = options;
            // TODO : pass server options
            ClientHttpBase = string.Format("http://{0}:{1}", options.Ip, options.HttpPort);
            Views          = PlatformClient.ConnectToViewStorage(options.StoreLocation, options.ViewsFolder);

            UseEventStore("default");

            RegisterCommands();
        }
Example #7
0
    public void TestPlatformClientDisposeOnlyOnce()
    {
        PlatformClient client = new PlatformClient("", "");

        try
        {
            client.eligibility(new Dictionary <string, object> {
            });
        }
        catch (PokitDokException) { }

        client.Dispose();
        GC.Collect();
    }
Example #8
0
        static void Main()
        {
            StorePath = ConfigurationManager.AppSettings["StorePath"];

            if (string.IsNullOrWhiteSpace(StorePath))
            {
                StorePath = @"C:\LokadData\dp-store";
            }

            StoreConnection = ConfigurationManager.AppSettings["StoreConnection"];
            if (string.IsNullOrWhiteSpace(StoreConnection))
            {
                StoreConnection = "http://localhost:8080";
            }

            // Use "default" container for reading/writing events
            _client = PlatformClient.ConnectToEventStore(StorePath, storeId: "default", platformServerEndpoint: StoreConnection);
            _view   = PlatformClient.ConnectToViewStorage(StorePath, "sample1-views");


            Console.WriteLine("You name:");
            _userName = Console.ReadLine();
            Console.WriteLine("Chat starting...");

            _client.WriteEvent("", Encoding.UTF8.GetBytes("|join a new user " + _userName));
            Task.Factory.StartNew(ScanChat,
                                  TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness);

            WriteColorText(_userName + ">", ConsoleColor.Green);

            _userMessage = "";

            while (true)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                if (keyInfo.KeyChar != '\r')
                {
                    _userMessage += keyInfo.KeyChar;
                }
                else
                {
                    _client.WriteEvent("", Encoding.UTF8.GetBytes(string.Format("{0}|{1}", _userName, _userMessage)));
                    Console.WriteLine();
                    WriteColorText(_userName + ">", ConsoleColor.Green);
                    _userMessage = "";
                }
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            var store = PlatformClient.ConnectToEventStoreAsReadOnly(PlatformPath, "sample3");
            var views = PlatformClient.ConnectToViewStorage(PlatformPath, Conventions.ViewContainer);

            var threads = new List <Task>
            {
                Task.Factory.StartNew(() => TagProjection(store, views),
                                      TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness),
                Task.Factory.StartNew(() => CommentProjection(store, views),
                                      TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness),
                Task.Factory.StartNew(() => UserCommentsPerDayDistributionProjection(store, views),
                                      TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness)
            };

            Task.WaitAll(threads.ToArray());
        }
Example #10
0
        /// <summary>
        /// Traverses the structure of the folder tree (location structure) and collects the results in the passed list.
        /// </summary>
        /// <param name="platformClient">The PlatformClient against the platform.</param>
        /// <param name="rootItem">The Item to start traversal from.</param>
        /// <param name="results">!!Will be modified!! The list, in which the results of traversal will be collected.</param>
        /// <param name="depth">The depth of the traversal.</param>
        private static void Traverse(PlatformClient platformClient, Item rootItem, IList <HierarchicalItem> results, int depth)
        {
            results.Add(Tuple.Create(rootItem, depth));

            var children = Enumerable.Empty <Item>();

            Collection collection = rootItem.Collection != null && rootItem.Collection.Links != null ? rootItem.Collection : null;

            // The item is a folder:
            if (null != collection)
            {
                // Get the items of the folder pagewise:
                do
                {
                    children   = children.Concat(collection.Items);
                    collection = platformClient.GetHalResource <Collection>(collection.GetUri("next", Enumerable.Empty <EmbedResource>()));
                }while (null != collection);
            }
            else
            {
                // The item to traverse is no folder.
            }


            Item[] materializedChildren = children.ToArray();
            foreach (Item child in materializedChildren)
            {
                if (child.DiscoverLinks("loc:collection").Any())
                {
                    Traverse(platformClient, platformClient.GetHalResource <Item>(new Uri(child.Href)), results, depth + 1);
                }
            }

            foreach (Item child in materializedChildren)
            {
                if (!child.DiscoverLinks("loc:collection").Any())
                {
                    results.Add(Tuple.Create(child, depth + 1));
                }
            }
        }
Example #11
0
    private IEnumerator Start()
    {
#if UNITY_EDITOR
        _assetLoader = gameObject.AddComponent <LocalAsset>();
        _client      = gameObject.AddComponent <EditorClient>();
#elif UNITY_ANDROID
        var bundles = gameObject.AddComponent <Bundles>();
        bundles.StartDownloads(BundlesUri);
        _assetLoader = bundles;
        _client      = gameObject.AddComponent <AndroidClient>();
#endif
        while (!_assetLoader.IsDone())
        {
            yield return(null);
        }

        _scenes   = gameObject.AddComponent <Scenes>();
        _luaState = gameObject.AddComponent <LuaState>();
        _servlet  = gameObject.AddComponent <Servlet>();
        Client.Login();
    }
        public void StartDownload(System.Net.CookieContainer cookies)
        {
            IsWatchingStream = true;
            _client = new PlatformClient(cookies);
            if (_stream != null)
                _stream.Dispose();

            _stream = _client.Activities.GetStream()
                .OfType<CommentInfo>()
                //.Where(cmmInf => cmmInf.Html.Contains("ふぅ") || cmmInf.Owner.Name.Result.Contains("lome"))
                .Distinct(commentInfo => commentInfo.ParentActivity.Id)
                .Select(commentInfo => commentInfo.ParentActivity.UpdateGetActivityAsync(false).Result)
                .Where(activityInfo => activityInfo.PostStatus != PostStatusType.Removed && activityInfo.AttachedContentType == ContentType.Image)
                .Select(activityInfo => new
                {
                    ActivityInfo = activityInfo,
                    ImageInfos = ((AttachedAlbum)activityInfo.AttachedContent).Pictures
                })
                .Subscribe(item =>
                    {
                        var imgs = item.ImageInfos.Select(inf => new ImageDownloader(this, inf)).ToArray();
                        DownloadJobs.AddRange(imgs);
                        OnAddedDownloadingImage(new DownloadingImageEventArgs(item.ActivityInfo, imgs));
                        foreach (var job in imgs)
                            job.Download();
                    },
                    exp => OnRaiseError(new RaiseErrorEventArgs(exp)));
        }
Example #13
0
 public void InitializeTest()
 {
     _connection     = Substitute.For <IConnectionInternal>();
     _platformClient = new PlatformClient(_connection);
 }
Example #14
0
 public void UseEventStore(string storeId = "default")
 {
     EventStores = PlatformClient.ConnectToEventStore(Options.StoreLocation, storeId, ClientHttpBase);
 }