Пример #1
0
        public DataEntityCollectionDTO RetrieveEntityByNameQuery(string queryName, Dictionary <string, object> parameters,
                                                                 SecurityToken sessionToken)
        {
            SecuritySummary securitySummary = new SecuritySummary();
            CallStatus      callStatus      = new CallStatus();

            using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory(_applicationServerAddress)
                   )
            {
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);

                DataEntityCollectionDTO entities = secureConnection.RunNamedQuery(queryName, parameters,
                                                                                  ref securitySummary, ref callStatus);

                if (callStatus.Result == CallStatusenumCallResult.Success)
                {
                    return(entities);
                }

                StringBuilder sb = new StringBuilder();
                foreach (ValidationError error in callStatus.Messages)
                {
                    sb.AppendLine(error.Message);
                }
                throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
            }

            //TODO: CONTINUE WITH THIS METHOD SIMILAR TO StaffQuery
            return(null);
        }
Пример #2
0
        public DataEntityCollectionDTO RetrieveEntityById(string entityName, Guid entityId, SecurityToken sessionToken)
        {
            SecuritySummary securitySummary = new SecuritySummary();
            CallStatus callStatus = new CallStatus();

            using (ChannelFactory<IDataEntityIO> factory = GetApplicationServerChannelFactory(_applicationServerAddress))
            {
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);

                List<string> fieldNames = GetFields(entityName);

                DataEntityCollectionDTO entities = secureConnection.ReadEntity(
                   entityId,
                   entityName,
                   fieldNames, ref securitySummary, ref callStatus);

                if (callStatus.Result == CallStatusenumCallResult.Success) return entities;

                StringBuilder sb = new StringBuilder();
                foreach (ValidationError error in callStatus.Messages)
                {
                    sb.AppendLine(error.Message);
                }
                throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
            }
        }
Пример #3
0
        /// <summary>
        /// Example of retrieving some data from the application server. In this case we will use the ReadEnity call to retrieve data for a single Learner entity.
        ///
        /// This illustrates the method of constructing a single entity query, and handling the results that are returned. It also illustrates the use of the CallStatus
        /// structure to retrieve information about the call, and any failures that occured.
        /// </summary>
        /// <param name="learnerid"></param>
        /// <param name="sessionToken"></param>
        internal DataEntityCollectionDTO RetrieveSingleLearnerById(string learnerid, SecurityToken sessionToken)
        {
            // The security summary will be filled with any notifications of data fields which were removed by the security protocols prior to being sent to the recipient. This
            // enables you to see whether your data has been redacted before you got to see it.
            SecuritySummary securitySummary = new SecuritySummary();

            // Almost all iSIMS calls fill a callStatus response message in with status and error messages.
            CallStatus callStatus = new CallStatus();

            // Create a communication channel factory to communicate with the iSIMS application server
            using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory())
            {
                // Because our communication now will be secured using our Identity Token we need to use some WIF extension methods to make sure the identity token
                // is sent as a Cookie on the SOAP call that WCF will be generating.
                factory.Credentials.UseIdentityConfiguration = true;
                IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken);
                Guid          studentId        = new Guid(learnerid);

                // Construct a query to read a specific entity from SIMS8
                DataEntityCollectionDTO entities = secureConnection.ReadEntity( // Tell it which specific unique entity we want to fetch
                    studentId,                                                  // Tell it what type of entity this is
                    "Learner",                                                  // Tell it what scope of data we want to get back from the call.
                    new List <string>(new[]
                {
                    // The surname and forename
                    "Learner.LegalSurname",
                    "Learner.LegalForename",
                    "Learner.PreferredForename",
                    // The Unique Pupil Number
                    "Learner.UPN",
                    // The Learners Addresses, start date. Note that there are many Addresses attached to a single Learner
                    "Learner.LearnerAddresses.StartDate",
                    // The Learners Addresses, Post Code
                    "Learner.LearnerAddresses.Address.PostCode"
                }), ref securitySummary, ref callStatus);

                // Handle an unsuccessful call.
                if (callStatus.Result != CallStatusenumCallResult.Success)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (ValidationError error in callStatus.Messages)
                    {
                        sb.AppendLine(error.Message);
                    }
                    throw new Exception("Call did not complete successfully" + Environment.NewLine + sb);
                }
                return(entities);
            }
        }
Пример #4
0
        public IActionResult GetPrices(String ticker, String start, String end)
        {
            DateTime startDate, endDate;

            if (!DateTime.TryParse(start, out startDate) || !DateTime.TryParse(end, out endDate))
            {
                return(BadRequest());
            }

            try
            {
                SecuritySummary securitySummary = new SecuritySummary
                {
                    _ticker         = ticker,
                    _maxDailyProfit = new DailyProfit()
                };

                int     totalDays   = 0;
                Decimal totalVolume = 0;

                DateTime startMonth     = new DateTime(startDate.Year, startDate.Month, 1);
                DateTime startNextMonth = startMonth;

                // Loop through months - from 1st day of the month (inclusively) till 1st day of the next month (exclusively)
                while (startNextMonth.CompareTo(endDate) <= 0)
                {
                    startNextMonth = startNextMonth.AddMonths(1);

                    // Bring collection of daily data for the whole month
                    var securityData = _quandlConsumer.GetDailyPrices(ticker, startMonth.ToString("yyyy-MM-dd"), startNextMonth.ToString("yyyy-MM-dd")).Result;

                    Decimal totalMonthlyOpen  = 0;
                    Decimal totalMonthlyClose = 0;

                    foreach (var day in securityData)
                    {
                        // 1. Gather Open/Close for monthly average calculations
                        totalMonthlyOpen  += day.Open;
                        totalMonthlyClose += day.Close;

                        // 2. Find day with highest daily profit
                        var dayProfit = day.High - day.Low;
                        if (dayProfit > securitySummary._maxDailyProfit._profit)
                        {
                            securitySummary._maxDailyProfit._profit = dayProfit;
                            securitySummary._maxDailyProfit._date   = day.Date;
                        }

                        // 3. Gather Volume for average volume calculation
                        totalVolume += day.Volume;

                        // 4. Update number of "days of loss"
                        if (day.Close < day.Open)
                        {
                            securitySummary._daysOfLoss++;
                        }
                    }

                    totalDays += securityData.Count;

                    var averageOpen  = Decimal.Round(totalMonthlyOpen / securityData.Count, 3);
                    var averageClose = Decimal.Round(totalMonthlyClose / securityData.Count, 3);

                    // Add new entry to the list of monthly averages
                    securitySummary._monthlyAverages.Add(new MonthlyAverage(startMonth.ToString("yyyy-MM"), averageOpen, averageClose));

                    startMonth = startNextMonth;
                }

                // Keep security average volume for potential future use
                securitySummary._averageVolume = Decimal.Round(totalVolume / totalDays, 0);

                return(Ok(securitySummary));
            }  catch (Exception) {
                return(NotFound());
            }
        }