コード例 #1
0
 public void SaveVerifyToken(ComponentToken token)
 {
     using (ApplicationDbContext _context = new ApplicationDbContext())
     {
         var tokenInDb = _context.ComponentTokens.OrderByDescending(c => c.Id).First();
         tokenInDb.ComponentVerifyTicket         = token.ComponentVerifyTicket;
         tokenInDb.ComponentVerifyTicketCreateOn = token.ComponentVerifyTicketCreateOn;
         _context.SaveChanges();
     }
 }
コード例 #2
0
 public void SavePreAuthCode(ComponentToken token)
 {
     using (ApplicationDbContext _context = new ApplicationDbContext())
     {
         var tokenInDb = _context.ComponentTokens.OrderByDescending(c => c.Id).First();
         tokenInDb.PreAuthCode          = token.PreAuthCode;
         tokenInDb.PreAuthCodeCreateOn  = token.PreAuthCodeCreateOn;
         tokenInDb.PreAuthCodeExpiresIn = token.PreAuthCodeExpiresIn;
         _context.SaveChanges();
     }
 }
コード例 #3
0
 public void SaveAccessToken(ComponentToken token)
 {
     using (ApplicationDbContext _context = new ApplicationDbContext())
     {
         var tokenInDb = _context.ComponentTokens.OrderByDescending(c => c.Id).First();
         tokenInDb.ComponentAccessToken          = token.ComponentAccessToken;
         tokenInDb.ComponentAccessTokenCreateOn  = token.ComponentAccessTokenCreateOn;
         tokenInDb.ComponentAccessTokenExpiresIn = token.ComponentAccessTokenExpiresIn;
         _context.SaveChanges();
     }
 }
コード例 #4
0
 /// <summary>
 /// 将获取到的组件信息存入数据库中
 /// </summary>
 /// <param name="componentInfos"></param>
 private void SaveData(List <ComponentInfo> componentInfos)
 {
     if (base.user.IsLandHome)
     {
         //陆地端将数据写入缓存中
         List <ComponentToken> tokens = new List <ComponentToken>();
         foreach (var item in componentInfos)
         {
             ComponentToken token = new ComponentToken()
             {
                 Id = item.componentid,
                 //CommId = item.commid,
                 Name = item.cname,
                 Type = (ComponentType)item.type
             };
             tokens.Add(token);
         }
         string com = JsonConvert.SerializeObject(tokens);
         HttpContext.Session.SetString("comtoken", com);
     }
 }
コード例 #5
0
        public ActionResult <Component> PostComponentToken(string tenantName, string productName, string componentName, [FromBody] ComponentToken componentToken)
        {
            var isFromCli = HttpContext.Request.Headers["x-called-by"].ToString();

            if (isFromCli != "")
            {
                _logger.LogInformation($"{isFromCli} POST '{HttpContext.Request.Path}' is called");
            }
            else
            {
                _logger.LogInformation($"POST '{HttpContext.Request.Path}' is called");
            }

            var token = _componentService.AddComponentToken(tenantName, productName, componentName, componentToken);

            if (token == null)
            {
                return(BadRequest("Something went wrong, try to create Token one more time"));
            }

            return(Ok($"Token '{token}' has been created for component '{componentName}'"));
        }
コード例 #6
0
        public string AddComponentToken(string tenantName, string productName, string componentName, ComponentToken componentToken, bool shoudGenerateToken = true)
        {
            List <TenantConfiguration> tenants = TenantIOReader.ReadTenantsFromConfigFile();
            var tenant = tenants.Find(x => x.Name == tenantName);

            if (tenant == null)
            {
                return(null);
            }

            var product = tenant.Products.Find(x => x.Name == productName);

            if (product == null)
            {
                return(null);
            }

            var component = product.Components.Find(x => x.Name == componentName);

            if (component == null)
            {
                return(null);
            }

            if (shoudGenerateToken == true)
            {
                string apiKey = KeyGenerators.GenerateApiKey();
                componentToken.Token = apiKey;
            }

            component.Settings.Tokens.Add(componentToken);

            // store token in memory!
            _tenantRepository.AddComponentToken(tenantName, productName, componentName, componentToken);

            // Write into file
            if (TenantIOWriter.WriteTenantsConfiguration(tenants) == true)
            {
                if (shoudGenerateToken == true)
                {
                    // Send to the Cluster
                    _storageHubService.SendCreateComponentTokenStorage(new Model.Storages.Requests.Components.CreateComponentTokenDetails()
                    {
                        Tenant    = tenantName,
                        Product   = productName,
                        Component = componentName,
                        Token     = componentToken,

                        StoragesAlreadySent = new List <string>()
                    });
                }
                return(componentToken.Token);
            }

            return(null);
        }
コード例 #7
0
 public ComponentTokenCreatedDetails()
 {
     Token = new ComponentToken();
     StoragesAlreadySent = new List <string>();
 }
コード例 #8
0
ファイル: IcsImporter.cs プロジェクト: huamanhtuyen/VNACCS
        /// <summary>
        /// Skips the given component block (until it reaches
        /// the corresponding ctkn:END value)
        /// </summary>
        /// <param name="ctkn"></param>
        private void SkipComponent(ComponentToken ctkn)
        {
            int level = 1;

            CalendarEntry entry = GetNextEntry();

            while (entry != null)
            {
                PropertyToken tkn = (PropertyToken) GetToken(_properties, entry.Id);

                switch (tkn)
                {
                    case PropertyToken.Begin:
                        level++;
                        break;

                    case PropertyToken.End:
                        level--;

                        if (level == 0)
                        {
                            if ((ComponentToken) GetToken(_components, entry.Value) != ctkn)
                            {
                                ReportError(entry, "Expected \"END:" +
                                                    Enum.GetName(typeof(ComponentToken), ctkn).ToUpper() + "\"");
                            }
                            return;
                        }
                        break;
                }

                entry = GetNextEntry();
            }

            ReportError(entry, "Expected \"END:" +
                                Enum.GetName(typeof(ComponentToken), ctkn).ToUpper() + "\"");
        }
コード例 #9
0
ファイル: IcsImporter.cs プロジェクト: huamanhtuyen/VNACCS
        private void ProcessZonePartEnd(CalendarEntry entry,
            CalendarTimeZone zone, TimeZonePart part, ComponentToken tkn)
        {
            if ((ComponentToken)GetToken(_components, entry.Value) != tkn)
                ReportError(entry, "Expected \"END:" + _components[(int)tkn].Text.ToUpper() + "\"");

            if (zone.Part == null)
                zone.Part = new List<TimeZonePart>();

            zone.Part.Add(part);
        }
コード例 #10
0
ファイル: IcsImporter.cs プロジェクト: huamanhtuyen/VNACCS
        /// <summary>
        /// Processes VTimeZone parts (DayLight, Standard)
        /// </summary>
        /// <param name="zone"></param>
        /// <param name="tkn"></param>
        private void ProcessZonePart(CalendarTimeZone zone, ComponentToken tkn)
        {
            bool isDtStartValue = false;

            TimeZonePart part = new TimeZonePart();

            CalendarEntry entry = GetNextEntry();

            while (entry != null)
            {
                switch ((PropertyToken) GetToken(_properties, entry.Id))
                {
                    case PropertyToken.DtStart:
                        part.StartDate = ProcessDate(entry, ref isDtStartValue);
                        break;

                    case PropertyToken.RDate:
                        part.RecurDate = ProcessRDate(entry, part.RecurDate);
                        break;

                    case PropertyToken.RRule:
                        part.RecurRule = ProcessRRule(entry);
                        break;

                    case PropertyToken.TzOffsetTo:
                        part.OffsetTo = ProcessTzOffset(entry);
                        break;

                    case PropertyToken.End:
                        ProcessZonePartEnd(entry, zone, part, tkn);
                        return;
                }

                entry = GetNextEntry();
            }

            ReportError(entry, "Expected \"END:" + _components[(int)tkn].Text.ToUpper() + "\"");
        }
コード例 #11
0
        /// <summary>
        /// 设备界面显示
        /// </summary>
        /// <param name="isShow"></param>
        /// <param name="id">不为空时是陆地端跳转</param>
        /// <param name="shipName"></param>
        /// <returns></returns>
        public IActionResult Index(bool isShow = false, string id = "", string shipName = "")
        {
            if (!string.IsNullOrEmpty(id))
            {
                string browsertoken = HttpContext.Request.Cookies["token"];
                if (browsertoken != null)
                {
                    string urlstr = HttpContext.Session.GetString(browsertoken);
                    user            = JsonConvert.DeserializeObject <UserToken>(urlstr);
                    user.ShipId     = id;
                    user.IsLandHome = true;
                    user.ShipName   = shipName;
                    string userStr = JsonConvert.SerializeObject(user);
                    //将请求的url注册
                    HttpContext.Session.SetString(browsertoken, userStr);
                    //写入浏览器token
                    HttpContext.Response.Cookies.Append("token", browsertoken);
                }
                //陆地端过来不显示报警信息
                ManagerHelp.IsShowAlarm = false;
                ManagerHelp.isInit      = false;
                ViewBag.LoginName       = base.user.Name;
                ViewBag.ShipName        = base.user.ShipName;
                ViewBag.src             = "/Device/Index";
                ViewBag.layuithis       = "device";

                #region 缓存当前船下的组件信息,提供给设备,算法,船员,船状态操作
                assembly.SendComponentQuery(id);
                bool flag = true;
                new TaskFactory().StartNew(() =>
                {
                    while (ManagerHelp.ComponentReponse == "" && flag)
                    {
                        Thread.Sleep(1000);
                    }
                    if (ManagerHelp.ComponentReponse != "")
                    {
                        ProtoBuffer.Models.ComponentResponse response = JsonConvert.DeserializeObject <ProtoBuffer.Models.ComponentResponse>(ManagerHelp.ComponentReponse);
                        ManagerHelp.ComponentReponse = "";
                        List <ComponentToken> tokens = new List <ComponentToken>();
                        if (response.result == 0 && response.componentinfos != null)
                        {
                            foreach (var item in response.componentinfos)
                            {
                                ComponentToken token = new ComponentToken()
                                {
                                    Id = item.componentid,
                                    //CommId = item.commid,
                                    Name = item.cname,
                                    Type = (ComponentType)item.type
                                };
                                tokens.Add(token);
                            }
                        }
                        string com = JsonConvert.SerializeObject(tokens);
                        HttpContext.Session.SetString("comtoken", com);
                    }
                }).Wait(timeout);
                flag = false;
                #endregion
            }
            ViewBag.IsLandHome   = base.user.IsLandHome;
            ViewBag.IsShowLayout = isShow;
            ViewBag.IsSet        = base.user.EnableConfigure;
            return(View());
        }
コード例 #12
0
        public bool AddComponentToken(string tenant, string product, string component, ComponentToken componentToken)
        {
            var componentDetail = GetComponent(tenant, product, component);

            if (componentDetail == null)
            {
                return(false);
            }

            componentDetail.Settings.Tokens.Add(componentToken);
            return(true);
        }