private async Task <TokenEndpointResponse> UpdateAsync(string refreshToken, ExternalService service)
        {
            Uri tokenEndpoint;
            var client = new HttpClient();
            var body   = new Dictionary <string, string>();

            if (service == ExternalService.Spotify)
            {
                tokenEndpoint = new Uri("https://accounts.spotify.com/api/token");
                var encodedAuth =
                    Convert.ToBase64String(Encoding.UTF8.GetBytes($"{_options.AppId}:{_options.AppSecret}"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedAuth);
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(service), service, null);
            }

            body.Add("grant_type", "refresh_token");
            body.Add("refresh_token", refreshToken);

            var response = await client.PostAsync(tokenEndpoint, new FormUrlEncodedContent(body)).ConfigureAwait(false);

            var responsebody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                throw new InvalidOperationException(responsebody);
            }
            return(JsonConvert.DeserializeObject <TokenEndpointResponse>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
        /// <summary>
        /// Add and register the sever on Revit startup.
        /// </summary>
        public ExternalDBApplicationResult OnStartup(ControlledApplication application)
        {
            ExternalService plumbingFixtureService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipePlumbingFixtureFlowService);

            Pipe.PlumbingFixtureFlowServer flowServer = new Pipe.PlumbingFixtureFlowServer();
            if (plumbingFixtureService != null)
            {
                plumbingFixtureService.AddServer(flowServer);
            }

            ExternalService pipePressureDropService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipePressureDropService);

            Pipe.PipePressureDropServer pressureDropServer = new Pipe.PipePressureDropServer();
            if (pipePressureDropService != null)
            {
                pipePressureDropService.AddServer(pressureDropServer);
            }

            ExternalService ductPressureDropService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DuctPressureDropService);

            Duct.DuctPressureDropServer ductPressureDropServer = new Duct.DuctPressureDropServer();
            if (ductPressureDropService != null)
            {
                ductPressureDropService.AddServer(ductPressureDropServer);
            }

            return(ExternalDBApplicationResult.Succeeded);
        }
Example #3
0
        public void Execute()
        {
            var breaker = new CircuitBreaker();
            var service = new ExternalService();

            do
            {
                try
                {
                    breaker.ExecuteAction(() =>
                    {
                        int result = service.CallMe();
                        Console.WriteLine($"The result is {result}");
                    });
                }
                catch (CircuitBreakerOpenException ex)
                {
                    Console.WriteLine("Method not called");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Generic error");
                }
                Console.ReadLine();
            } while (true);
        }
Example #4
0
        // GET: External/Details/5
        public ActionResult Details(int id)
        {
            var service = new ExternalService();
            var model   = service.GetExternalById(id);

            return(View(model));
        }
Example #5
0
 private static bool TryParseAsExternalService(TorService torService, out ExternalService externalService)
 {
     externalService = null;
     if (torService.ServiceType == TorServiceType.P2P)
     {
         externalService = new ExternalService()
         {
             CryptoCode       = torService.Network.CryptoCode,
             DisplayName      = "Full node P2P",
             Type             = ExternalServiceTypes.P2P,
             ConnectionString = new ExternalConnectionString(new Uri($"bitcoin-p2p://{torService.OnionHost}:{torService.VirtualPort}", UriKind.Absolute)),
             ServiceName      = torService.Name,
         };
     }
     if (torService.ServiceType == TorServiceType.RPC)
     {
         externalService = new ExternalService()
         {
             CryptoCode       = torService.Network.CryptoCode,
             DisplayName      = "Full node RPC",
             Type             = ExternalServiceTypes.RPC,
             ConnectionString = new ExternalConnectionString(new Uri($"btcrpc://*****:*****@{torService.OnionHost}:{torService.VirtualPort}?label=BTCPayNode", UriKind.Absolute)),
             ServiceName      = torService.Name
         };
     }
     return(externalService != null);
 }
Example #6
0
        // GET: External
        public ActionResult Index()
        {
            var service = new ExternalService();
            var exList  = service.GetAllExternals();

            return(View(exList));
        }
        /// <summary>
        /// Use this method to report any problems that occurred while the user was browsing for External Resources.
        /// Revit will call this method each time the end user browses to a new folder location, or selects an item
        /// and clicks Open.
        /// </summary>
        public void HandleBrowseResult(ExternalResourceUIBrowseResultType resultType, string browsingItemPath)
        {
            if (resultType == ExternalResourceUIBrowseResultType.Success)
            {
                return;
            }

            String resultString = resultType.ToString("g");

            // While executing its SetupBrowserData() method, the "DB server" - SampleExternalResourceServer - can store
            // detailed information about browse failures that occurred (user not logged in, network down, etc.).
            // Subsequently, when Revit calls this method, the details can be read from the DB server and reported to the user.
            ExternalService externalResourceService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.ExternalResourceService);

            if (externalResourceService == null)
            {
                System.Windows.Forms.MessageBox.Show("External Resource Service unexpectedly not found.");
                return;
            }
            SampleExternalResourceDBServer myDBServer = externalResourceService.GetServer(GetDBServerId()) as SampleExternalResourceDBServer;

            if (myDBServer == null)
            {
                System.Windows.Forms.MessageBox.Show("Cannot get SampleExternalResourceDBServer from ExternalResourceService.");
                return;
            }
            // ... Retrieve detailed failure information from SampleExternalResourceServer here.

            String message = String.Format("The browse result for <{0}> was: <{1}>.", browsingItemPath, resultString);

            System.Windows.Forms.MessageBox.Show(message);
        }
        public int CheckStockLevel()
        {
            var service = new ExternalService();

            StockLevel = service.GetStock();
            return(StockLevel);
        }
Example #9
0
        /// <summary>
        /// Same as AddRevitElementServer(), but for multiple elements.
        /// </summary>
        /// <param name="uidoc"></param>
        public void AddMultipleRevitElementServers(UIDocument uidoc)
        {
            IList <Reference> references = uidoc.Selection.PickObjects(ObjectType.Element, "Select elements to duplicate with DirectContext3D");

            ExternalService    directContext3DService   = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService);
            MultiServerService msDirectContext3DService = directContext3DService as MultiServerService;
            IList <Guid>       serverIds = msDirectContext3DService.GetActiveServerIds();

            // Create one server per element.
            foreach (Reference reference in references)
            {
                Element elem = uidoc.Document.GetElement(reference);

                RevitElementDrawingServer revitServer = new RevitElementDrawingServer(uidoc, elem, m_offset);
                directContext3DService.AddServer(revitServer);
                m_servers.Add(revitServer);

                serverIds.Add(revitServer.GetServerId());
            }

            msDirectContext3DService.SetActiveServers(serverIds);

            m_documents.Add(uidoc.Document);
            uidoc.UpdateAllOpenViews();
        }
Example #10
0
        private async Task <string> GetServiceLink(ExternalService service)
        {
            var connectionString = await service.ConnectionString.Expand(Request.GetAbsoluteUriNoPathBase(), service.Type, _BtcpayServerOptions.NetworkType);

            var tokenParam = service.Type == ExternalServiceTypes.ThunderHub ? "token" : "access-key";

            return($"{connectionString.Server}?{tokenParam}={connectionString.AccessKey}");
        }
Example #11
0
        public ActionResult GetAllMovies()
        {
            ExternalService service = new ExternalService();
            List <MovieDTO> result  = service.GetAllMoviesList();
            var             data    = Mapper.Map <List <MovieViewModel> >(result);

            return(View(data));
        }
Example #12
0
 public void LoadExportedService(uint hash, uint id)
 {
     exportedServicesIds[hash] = new ExternalService
                                     {
                                         Hash = hash,
                                         Id = (byte)id,
                                     };
 }
Example #13
0
 public void LoadExportedService(uint hash, uint id)
 {
     exportedServicesIds[hash] = new ExternalService
     {
         Hash = hash,
         Id   = (byte)id,
     };
 }
Example #14
0
        private void CreateServices()
        {
            var externalService = new ExternalService();

            CandidateService = new CandidateService(externalService);
            VoteService      = new VoteService();
            ResultService    = new ResultService(externalService, VoteService, CandidateService);
        }
        public ActionResult Index()
        {
            var comment = ExternalService.ReadComment();
            // HACK: Service docs say it can handle up to 30 chars but it crashes.
            var fixedComment = ServiceHelper.TrimForExternalService(comment);

            ExternalService.UploadCommentUpTo30Chars(fixedComment);
            return(View());
        }
Example #16
0
        public JsonResult GetAllActors()
        {
            ExternalService service = new ExternalService();
            List <ActorDTO> result  = service.GetAllActors();
            var             data    = Mapper.Map <List <ActorViewModel> >(result);

            return(Json(data, JsonRequestBehavior.AllowGet));
            //return Json(new { data = data, JsonRequestBehavior.AllowGet });
        }
Example #17
0
        public JsonResult AddActor(ActorViewModel actor)
        {
            ExternalService service  = new ExternalService();
            ActorDTO        actorDTO = Mapper.Map <ActorDTO>(actor);
            var             result   = service.AddActor(actorDTO);

            return(Json(new { data = result, JsonRequestBehavior.AllowGet }));
            //return View();
        }
Example #18
0
        public ActionResult EditMovie(int movieID)
        {
            ExternalService service = new ExternalService();
            MovieDTO        result  = service.GetMovieByID(movieID);
            MovieViewModel  movie   = Mapper.Map <MovieViewModel>(result);

            ViewData["counter"] = movie.Actors.Count;;
            return(View(movie));
        }
Example #19
0
        public ActionResult DeleteExternal(int id)
        {
            var service = new ExternalService();

            service.DeleteExternal(id);

            TempData["SaveResult"] = "Your External drive entry was deleted.";
            return(RedirectToAction("Index"));
        }
Example #20
0
        public JsonResult AddProducer(ProducerViewModel producer)
        {
            ExternalService service     = new ExternalService();
            ProducerDTO     producerDTO = Mapper.Map <ProducerDTO>(producer);
            var             result      = service.AddProducer(producerDTO);

            return(Json(new { data = result, JsonRequestBehavior.AllowGet }));
            //return View();
        }
        public async Task OnGetAsync(int id)
        {
            TenantId = _sessionTenantAccessor.TenantId;
            Entity   = await _adminServices.GetExternalServiceByIdAsync(TenantId, id);

            Input = new InputModel()
            {
                Id = Entity.Id,
            };
        }
Example #22
0
        // GET: External/Delete/5
        public ActionResult Delete(int id)
        {
            var service = new ExternalService();
            var model   = service.GetExternalById(id);

            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
        public string GetMessage()
        {
            var message = ExternalService.GetMessage();

            if (message.Length > 140)
            {
                // Message can't be more than 140 characters
                message = message.Substring(0, 140);
            }
            return(message);
        }
Example #24
0
        public ActionResult Create(ExternalCreate ex)
        {
            var service = new ExternalService();

            if (ModelState.IsValid)
            {
                service.CreateExternal(ex);
                return(RedirectToAction("Index"));
            }
            return(View(ex));
        }
Example #25
0
        /// <summary>
        /// Search data based on search term for Actors
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <returns></returns>
        public JsonResult SearchActors(string searchTerm = "")
        {
            ExternalService service = new ExternalService();
            List <ActorDTO> result  = service.GetAllActors();
            var             Actors  = Mapper.Map <List <ActorViewModel> >(result);
            var             data    = (from N in Actors
                                       where N.Name.StartsWith(searchTerm.ToUpper())
                                       select new { N.Name, N.ActorID });

            return(Json(data, JsonRequestBehavior.AllowGet));
            //return Json(new { data = data, JsonRequestBehavior.AllowGet });
        }
Example #26
0
        public JsonResult GetAllYears(string searchTerm = "")
        {
            ExternalService service = new ExternalService();
            List <YearDTO>  result  = service.GetAllYear();
            var             Years   = Mapper.Map <List <YearViewModel> >(result);
            var             data    = (from N in Years
                                       where N.Value.StartsWith(searchTerm.ToUpper())
                                       select new { N.Value, N.YearID }).Take(50);

            return(Json(data, JsonRequestBehavior.AllowGet));
            //return Json(new { data = data, JsonRequestBehavior.AllowGet });
        }
        private IActionResult LightningChargeServices(ExternalService service, ExternalConnectionString connectionString, bool showQR = false)
        {
            ChargeServiceViewModel vm = new ChargeServiceViewModel();

            vm.Uri      = connectionString.Server.AbsoluteUri;
            vm.APIToken = connectionString.APIToken;
            var builder = new UriBuilder(connectionString.Server);

            builder.UserName    = "******";
            builder.Password    = vm.APIToken;
            vm.AuthenticatedUri = builder.ToString();
            return(View(nameof(LightningChargeServices), vm));
        }
Example #28
0
        /// <summary>
        /// Registers an instance of a SampleExternalResourceUIServer with the ExternalService
        /// of type ExternalResourceUIService.
        /// </summary>
        /// <param name="application">An object that is passed to the external application
        /// which contains the controlled application.</param>
        /// <returns>Return the status of the external application.  A result of Succeeded
        /// means that the external application was able to register the IExternalResourceUIServer.
        /// </returns>
        public Result OnStartup(UIControlledApplication application)
        {
            ExternalService externalResourceUIService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.ExternalResourceUIService);

            if (externalResourceUIService == null)
            {
                return(Result.Failed);
            }

            // Create an instance of your IExternalResourceUIServer and register it with the ExternalResourceUIService.
            IExternalResourceUIServer sampleUIServer = new SampleExternalResourceUIServer();

            externalResourceUIService.AddServer(sampleUIServer);
            return(Result.Succeeded);
        }
Example #29
0
        public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action <IMessage> done)
        {
            uint            hash            = method.Service.GetHash();
            ExternalService externalService = exportedServicesIds[hash];

            var requestId = externalService.GetNextRequestId();

            callbacks.Enqueue(new Callback {
                Action = done, Builder = responsePrototype.WeakToBuilder(), RequestId = requestId
            });

            ServerPacket data = new ServerPacket(externalService.Id, (int)GetMethodId(method), requestId, ListenerId).WriteMessage(request);

            Send(data);
        }
        public async Task UpdateExternalService(ExternalService externalService, CancellationToken cancellationToken = default(CancellationToken))
        {
            var entity = await _repository.GetById(externalService.Id);

            if (entity != null)
            {
                entity.Description = externalService.Description;

                if (!string.IsNullOrEmpty(externalService.ConfigString))
                {
                    await _secretVault.Update(entity.Name, externalService.ConfigString, cancellationToken);
                }

                await _repository.Update(entity, cancellationToken);
            }
        }
 private static bool TryParseAsExternalService(TorService torService, out ExternalService externalService)
 {
     externalService = null;
     if (torService.ServiceType == TorServiceType.P2P)
     {
         externalService = new ExternalService()
         {
             CryptoCode       = torService.Network.CryptoCode,
             DisplayName      = "Nodo completo P2P",
             Type             = ExternalServiceTypes.P2P,
             ConnectionString = new ExternalConnectionString(new Uri($"bitcoin-p2p://{torService.OnionHost}:{torService.VirtualPort}", UriKind.Absolute)),
             ServiceName      = torService.Name,
         };
     }
     return(externalService != null);
 }