Пример #1
0
        private string GetNewNotificationToken()
        {
            var Authclient  = new RestClient("https://api-dev.sanlam.co.za/auth/oauth/v2/token");
            var Authrequest = new RestRequest(Method.POST);

            Authrequest.AddHeader("content-type", "application/x-www-form-urlencoded");
            Authrequest.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=l7401ccaea01034052abbda3d281b08d60&client_secret=0268a61963ca410a8181e1dc790c45e0", ParameterType.RequestBody);
            IRestResponse Authresponse = Authclient.Execute(Authrequest);
            TokenModel    token        = new TokenModel(Authresponse.Content);

            using (var tokencontext = new DepContextSC())
            {
                if (tokencontext.TempCache.Any(o => o.keyitem == "notificationtoken"))
                {
                    var updatetoken = tokencontext.TempCache.FirstOrDefault(e => e.keyitem == "notificationtoken");
                    updatetoken.valueitem = token.access_token;
                }
                else
                {
                    TempCache tx = new TempCache();
                    tx.keyitem   = "notificationtoken";
                    tx.valueitem = token.access_token;
                    tokencontext.TempCache.Add(tx);
                };
                tokencontext.SaveChanges();
            }

            return(token.access_token);
        }
Пример #2
0
        public IEnumerable <Subscriptions> NewSubscription(string IntermediaryCode, NewSubscriptionRequest bus)
        {
            using (var context = new DepContextSC())
            {
                string        tokenforCall = "";
                Subscriptions sub          = new Subscriptions();
                sub.IntermediaryCode = IntermediaryCode;
                sub.Serviceid        = bus.Serviceid;
                sub.Status           = bus.Status;

                context.Subscriptions.Add(sub);
                context.SaveChanges();

                if (context.TempCache.Any(o => o.keyitem == "notificationtoken"))
                {
                    TempCache bd = context.TempCache.Where(bus => bus.keyitem == "notificationtoken").FirstOrDefault();
                    tokenforCall = bd.valueitem;
                }
                else
                {
                    tokenforCall = GetNewNotificationToken();
                };
                string msg = "A new subscription was created IntermediaryCode: " + sub.IntermediaryCode + " with ServiceID: " + sub.Serviceid.ToString();

                if (SendEmailNotification(tokenforCall, msg, "New Subscription") == "valadationfail")
                {
                    tokenforCall = GetNewNotificationToken();

                    SendEmailNotification(tokenforCall, msg, "New Subscription");
                }
                ;

                return(context.Subscriptions.Where(bus => bus.IntermediaryCode == IntermediaryCode).ToList());
            }
        }
Пример #3
0
        public LookupService(OpCore core)
        {
            Core    = core;
            Network = core.Network;


            LookupCache = new TempCache(Network, ServiceID, DataTypeCache);

            // specify time out
            // specify how many results to send back
            // send back newest results?
            // put ttl
        }
Пример #4
0
        public object UpdateSubscriptions(int SubscriptionID, [FromBody] SubscriptionsRequest bus)
        {
            SubscriptionsResponse bdr = new SubscriptionsResponse();

            try
            {
                using (var context = new DepContextSC())
                {
                    string        tokenforCall = "";
                    Subscriptions bd           = context.Subscriptions.Where(bus => bus.Id == SubscriptionID).FirstOrDefault();
                    bd.Serviceid        = bus.Serviceid;
                    bd.IntermediaryCode = bus.IntermediaryCode;
                    bd.Status           = bus.Status;
                    context.SaveChanges();

                    if (bd.Status.ToLower() != "active")
                    {
                        if (context.TempCache.Any(o => o.keyitem == "notificationtoken"))
                        {
                            TempCache scr = context.TempCache.Where(bus => bus.keyitem == "notificationtoken").FirstOrDefault();
                            tokenforCall = scr.valueitem;
                        }
                        else
                        {
                            tokenforCall = GetNewNotificationToken();
                        };
                        string msg = "A subscription status was changed -  IntermediaryCode: " + bd.IntermediaryCode + " with ServiceID: " + bd.Serviceid.ToString();

                        if (SendEmailNotification(tokenforCall, msg, "Subscription cancellation") == "valadationfail")
                        {
                            tokenforCall = GetNewNotificationToken();

                            SendEmailNotification(tokenforCall, msg, "Subscription cancellation");
                        }
                        ;
                    }

                    bdr.subscriptiondata = context.Subscriptions.Where(bus => bus.Id == SubscriptionID).ToList();
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Information("UpdateSubscriptionsError: " + e.Message);
                bdr.error = e.Message;
                // throw new Exception();
            }
            return(bdr);
        }
Пример #5
0
        public IHttpActionResult Get__44([FromBody] Dictionary <string, string> kvp)
        {
            if (kvp["name"] == "reset")
            {
                _temp = new TempCache();
                return(WrapResultJson(default(object), true, "reset done"));
            }
            else
            {
                _temp.NeedHackUser   = true;
                _temp.HackUserName   = kvp["name"];
                _temp.HackUserGender = kvp["gender"];

                var newUserInfo = ReadMockingFileAsObject(300, DoHackUserIfNeed);
                return(WrapResultJson(newUserInfo));
            }
        }
Пример #6
0
        public ShareService(OpCore core)
        {
            Core    = core;
            Network = core.Network;

            string rootPath = Core.User.RootPath + Path.DirectorySeparatorChar +
                              "Data" + Path.DirectorySeparatorChar +
                              ServiceID.ToString() + Path.DirectorySeparatorChar;

            SharePath = rootPath + DataTypeShare.ToString() + Path.DirectorySeparatorChar;
            Directory.CreateDirectory(SharePath);

            HeaderPath = SharePath + Utilities.CryptFilename(Core, "ShareHeaders");

            PublicPath = rootPath + DataTypePublic.ToString() + Path.DirectorySeparatorChar;
            Directory.CreateDirectory(PublicPath);

            DownloadPath = Core.User.RootPath + Path.DirectorySeparatorChar + "Downloads" + Path.DirectorySeparatorChar;


            Core.SecondTimerEvent += Core_SecondTimer;

            // data
            Network.RudpControl.SessionUpdate += new SessionUpdateHandler(Session_Update);
            Network.RudpControl.SessionData[ServiceID, DataTypeSession] += new SessionDataHandler(Session_Data);

            Core.Transfers.FileSearch[ServiceID, DataTypeShare]  += new FileSearchHandler(Transfers_FileSearch);
            Core.Transfers.FileRequest[ServiceID, DataTypeShare] += new FileRequestHandler(Transfers_FileRequest);

            Core.Transfers.FileSearch[ServiceID, DataTypePublic]  += new FileSearchHandler(Transfers_PublicSearch);
            Core.Transfers.FileRequest[ServiceID, DataTypePublic] += new FileRequestHandler(Transfers_PublicRequest);

            // location
            TempLocation = new TempCache(Network, ServiceID, DataTypeLocation);

            Local = new ShareCollection(Core.UserID);
            Collections.SafeAdd(Core.UserID, Local);

            LoadHeaders();
        }
Пример #7
0
        public ChatService(OpCore core)
        {
            Core    = core;
            Network = Core.Network;
            Trust   = core.Trust;

            Network.RudpControl.SessionUpdate             += new SessionUpdateHandler(Session_Update);
            Network.RudpControl.SessionData[ServiceID, 0] += new SessionDataHandler(Session_Data);
            Network.RudpControl.KeepActive += new KeepActiveHandler(Session_KeepActive);

            Core.SecondTimerEvent += Core_SecondTimer;
            Core.KeepDataCore     += new KeepDataHandler(Core_KeepData);

            Core.Locations.KnowOnline     += new KnowOnlineHandler(Location_KnowOnline);
            Core.Locations.LocationUpdate += new LocationUpdateHandler(Location_Update);

            if (Trust != null)
            {
                Trust.LinkUpdate += new LinkUpdateHandler(Link_Update);
                Link_Update(Trust.LocalTrust);
            }

            TempLocation = new TempCache(Network, ServiceID, DataTypeLocation);
        }