/// <summary>
        /// Register all service with its implementation
        /// </summary>
        /// <param name="containerRegistry">Container registry.</param>
        private void RegisterServices(IContainerRegistry containerRegistry)
        {
            containerRegistry.Register <IStartupService, StartupService>();

            /* ==================================================================================================
             * Register for api gateway, use register instance
             * ================================================================================================*/
            //containerRegistry.RegisterInstance(RestServiceHelper.GetApi<IPhotoApi>());
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IUserApi>());
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IOrgsApi>());
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IApiTokenApi>());
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IInvitationsApi>());
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IAppsApi>());
            RegisterAppCenterApis(containerRegistry);

            /* ==================================================================================================
             * register logic services which using for app
             * ...
             * ================================================================================================*/
            containerRegistry.Register <IUserService, UserService>();
            containerRegistry.Register <IOrgsService, OrgsService>();
            containerRegistry.Register <IApiTokenService, ApiTokenService>();
            containerRegistry.Register <IInvitationsService, InvitationsService>();
            containerRegistry.Register <IAppsService, AppsService>();
        }
示例#2
0
        public NewItemPage()
        {
            InitializeComponent();

            Item = new Asset();

            BindingContext = this;

            var allclients = RestServiceHelper.InvokeGetAllClientsAsync();

            foreach (var client in allclients.Result)
            {
                this.ClientIdPicker.Items.Add(client);
            }

            var allAssetTypes = RestServiceHelper.InvokeGetAllAssetTypesAsync();

            foreach (var assetType in allAssetTypes.Result)
            {
                this.AssetTypePicker.Items.Add(assetType.AssetType1);
            }

            var allAssetSubTypes = RestServiceHelper.InvokeGetAllAssetSubTypesAsync();

            foreach (var assetSubType in allAssetSubTypes.Result)
            {
                this.AssetSubTypePicker.Items.Add(assetSubType.AssetSubType1);
            }
        }
示例#3
0
    protected void SqlAsset_OnUpdated(object sender, SqlDataSourceStatusEventArgs e)
    {
        var updatedAsset = GetAssetFromDb();

        if (updatedAsset == null)
        {
            return;
        }

        try
        {
            if (string.Compare(editedAsset.ClientID, updatedAsset.ClientID, StringComparison.InvariantCulture) != 0 || editedAsset.AssetType != updatedAsset.AssetType || editedAsset.AssetSubType != updatedAsset.AssetSubType)
            {
                if (!RestServiceHelper.InvokePost(editedAsset.ClientID, editedAsset.AssetType, editedAsset.AssetSubType, -1))
                {
                    ErrorMsg.Text = "Asset Updated. Failed to update Global Asset counter Service.";
                }

                if (!RestServiceHelper.InvokePost(updatedAsset.ClientID, updatedAsset.AssetType, updatedAsset.AssetSubType, 1))
                {
                    ErrorMsg.Text = "Asset Updated. Failed to update Global Asset counter Service.";
                }
            }

            if (!RestServiceHelper.InvokePostGlobalAsset(updatedAsset))
            {
                ErrorMsg.Text = "Asset Updated. Failed to update Global Asset Service.";
            }
        }
        catch (Exception exception)
        {
            Debug.WriteLine(exception);
            ErrorMsg.Text = "Asset Updated. Failed to update Global Asset Service." + exception.GetDisplayMessage();
        }
    }
示例#4
0
        /* ==================================================================================================
         * example for action in service usage (farmiliar to sysfx)
         * this way vs handling in viewmodel are same
         * ================================================================================================*/
        public async Task Get(Action <List <PhotoDto> > onSuccessAction, Action onFailedAction, CancellationToken extToken)
        {
            //await Task.Delay(2000);
            var pair = await RestServiceHelper.CallWithRetry(() => _photoApi.Get(extToken), RetryMode.Confirm);

            switch (pair.ExtendedResult.Result)
            {
            case ApiResult.Failed:
                /* ==================================================================================================
                 * failed api call
                 * ================================================================================================*/
                onFailedAction?.Invoke();
                break;

            case ApiResult.Ok:
                /* ==================================================================================================
                 * success api call
                 * ================================================================================================*/
                onSuccessAction?.Invoke(pair.MainResult);
                break;

            case ApiResult.Canceled:
                /* ==================================================================================================
                 * Do nothing
                 * ================================================================================================*/
                break;

            default:
                break;
            }
        }
        public void WhenIPostEmployeeToTheApi()
        {
            var restService = new RestService();
            var helper      = new StepDefinitionHelper();

            foreach (var emp in _employees)
            {
                var response = restService.MakePostRequest(RestServiceHelper.BuildJsonObject(emp));
                isSuccessfull = response.IsSuccessful;
            }
        }
 public T DeserializeJsonToObject <T>(IRestResponse response)
 {
     if (response.IsSuccessful && !response.Content.Contains("error"))
     {
         return(RestServiceHelper.DeserializeJson <T>(response.Content));
     }
     else
     {
         throw new Exception($"Something went wrong! {response.Content}");
     }
 }
示例#7
0
    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        string        conString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnectionString"].ToString();
        SqlConnection sqlConn   = new SqlConnection(conString);
        object        AssetID;
        SqlCommand    command = new SqlCommand("usp_GetLastAssetID", sqlConn);

        command.CommandType = CommandType.StoredProcedure;
        sqlConn.Open();
        AssetID = command.ExecuteScalar();
        sqlConn.Close();

        string ClientID = ConfigurationManager.AppSettings["SubscriptionID"];

        var newAsset = GetAssetFromDb(Decimal.ToInt32((decimal)AssetID));

        if (newAsset == null)
        {
            return;
        }

        try
        {
            if (!RestServiceHelper.InvokePostGlobalAsset(newAsset))
            {
                ErrorMsg.Text = "Asset Added. Failed to update Global Asset Service.";
            }

            if (!RestServiceHelper.InvokePost(newAsset.ClientID, newAsset.AssetType, newAsset.AssetSubType))
            {
                ErrorMsg.Text = "Asset Added. Failed to update Global Asset Counter Service.";
            }
        }
        catch (Exception exception)
        {
            System.Diagnostics.Trace.WriteLine(exception.Message);
            System.Diagnostics.Trace.WriteLine(exception.InnerException.Message);
            System.Diagnostics.Trace.WriteLine(exception.StackTrace);
            ErrorMsg.Text = "Asset Added. Failed to update Global Asset Counter Service." + exception.GetDisplayMessage();
        }

        string URL = "AssetDetail.aspx?ID=" + Convert.ToString(AssetID);

        if (!string.IsNullOrEmpty(ErrorMsg.Text))
        {
            URL = string.Concat(URL, "&ErrorMessage=", ErrorMsg.Text);
        }

        Response.Redirect(URL);
    }
示例#8
0
        public async Task <PostDto> CreatePost(PostDto dto)
        {
            /* ==================================================================================================
             * map dto to request for api call
             * ================================================================================================*/
            var request = dto.MapTo <CreatePostRequest>();

            /* ==================================================================================================
             * action call
             * ================================================================================================*/
            var pair = await RestServiceHelper.CallWithRetry(() => _postsApi.Create(request));

            /* ==================================================================================================
             * exp dont care about extended result
             * ================================================================================================*/
            return(pair.MainResult);
        }
示例#9
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                //ClientAssetChartItems.Clear();
                //var assetsGroupedByClient = RestServiceHelper.InvokeGetByClientAsync().Result;
                //foreach (var item in assetsGroupedByClient)
                //{
                //    ClientAssetChartItems.Add(new ClientAssetChartData{ClientId = item.Key , AssetCount = item.Value.Count()});
                //}

                LabAssetChartItems.Clear();
                var assetsGroupedByClient = RestServiceHelper.InvokeGetByLabAsync().Result;
                foreach (var item in assetsGroupedByClient)
                {
                    LabAssetChartItems.Add(new LabAssetChartData {
                        LabId = item.Key, AssetCount = item.Value.Count()
                    });
                }

                AssetByAssetTypeChartItems.Clear();
                var assetsGroupedByAssetType = RestServiceHelper.InvokeGetByAssetTypeAsync().Result;
                foreach (var item in assetsGroupedByAssetType)
                {
                    AssetByAssetTypeChartItems.Add(new AssetByAssetTypeChartData {
                        AssetType = item.Key, AssetCount = item.Value.Count()
                    });
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
示例#10
0
        /// <summary>
        /// Register all service with its implementation
        /// </summary>
        /// <param name="containerRegistry">Container registry.</param>
        private void RegisterServices(IContainerRegistry containerRegistry)
        {
            containerRegistry.Register <IStartupService, StartupService>();
            containerRegistry.Register <ISecurityService, SecurityService>();
            containerRegistry.Register <IPatientService, PatientService>();
            containerRegistry.Register <IPhotoService, PhotoService>();
            containerRegistry.Register <IPostService, PostService>();

            /* ==================================================================================================
             * Register for api gateway, use register instance
             * ================================================================================================*/
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IPhotoApi>());
            containerRegistry.RegisterInstance(RestServiceHelper.GetApi <IPostsApi>());

            /* ==================================================================================================
             * todo: register logic services which using for app
             * ...
             * ================================================================================================*/
        }
示例#11
0
        public async Task <PhotoDto> GetWithSilentRetryUntilSuccess(int id)
        {
            var pair = await RestServiceHelper.CallWithRetry(() => _photoApi.Get(id), RetryMode.SilentUntilSuccess);

            return(pair.MainResult);
        }
示例#12
0
        public async Task <PhotoDto> Get(int id)
        {
            var pair = await RestServiceHelper.CallWithRetry(() => _photoApi.Get(id), RetryMode.Confirm);

            return(pair.MainResult);
        }
 public static void RegisterAppCenterApi <T>(this IContainerRegistry containerRegistry)
 {
     containerRegistry.RegisterInstance(RestServiceHelper.GetApi <T>());
 }