/// <summary>
        /// 创建或者更新字典类型
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <DataResult <long> > CreateOrUpdateDictionaryTypeAsync(CreateOrUpdateDictionaryTypeDto dto)
        {
            if (dto is null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            if (!dto.Id.HasValue)
            {
                dto.Id = GuidEx.NewGuid();
                DictionaryType entity = mapper.Map <DictionaryType>(dto);
                await applicationDbContext.DictionaryTypes.AddAsync(entity).ConfigureAwait(false);
            }
            else
            {
                var model = await applicationDbContext.DictionaryTypes.FirstOrDefaultAsync(e => e.Id == dto.Id).ConfigureAwait(false);

                model = mapper.Map(dto, model);
            }

            try
            {
                await applicationDbContext.SaveChangesAsync().ConfigureAwait(false);

                return(OkDataResult(dto.Id.Value));
            }
            catch (DbUpdateException ex)
            {
                return(FailedDataResult <long>(ex));
            }
        }
Exemplo n.º 2
0
        public void ConstructorTestTextRandom()
        {
            var g = new GuidEx("ThisIsARandomText");

            Assert.IsInstanceOfType(g, typeof(GuidEx));
            Assert.AreEqual(g.ToString(), "46526dd3-d88b-5da5-73ba-82023776e697");
        }
Exemplo n.º 3
0
        private void AddUwpModeItem()
        {
            XmlDocument doc = AppDic.ReadXml(AppConfig.WebUwpModeItemsDic,
                                             AppConfig.UserUwpModeItemsDic, Properties.Resources.UwpModeItemsDic);
            List <Guid> guids = new List <Guid>();

            foreach (XmlElement sceneXE in doc.DocumentElement.ChildNodes)
            {
                if (sceneXE.Name == Scene.ToString())
                {
                    foreach (XmlElement itemXE in sceneXE.ChildNodes)
                    {
                        if (GuidEx.TryParse(itemXE.GetAttribute("Guid"), out Guid guid))
                        {
                            if (guids.Contains(guid))
                            {
                                continue;
                            }
                            string uwpName = GuidInfo.GetUwpName(guid);
                            if (!string.IsNullOrEmpty(uwpName))
                            {
                                this.AddItem(new UwpModeItem(uwpName, guid));
                                guids.Add(guid);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void GetHashCodeTest()
        {
            var g  = new Guid("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");
            var gx = new GuidEx(g);

            Assert.AreEqual(g.GetHashCode(), gx.GetHashCode());
        }
Exemplo n.º 5
0
        public void CompareToTestThree()
        {
            var g  = new GuidEx("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");
            var gx = new GuidEx("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");

            Assert.IsTrue(gx.CompareTo(g) == 0);
        }
Exemplo n.º 6
0
        public void ToByteArray()
        {
            var g  = new Guid("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");
            var gx = new GuidEx(g);

            Assert.AreEqual(g.ToByteArray()[4], gx.ToByteArray()[4]);
        }
Exemplo n.º 7
0
        public void EqualsTestTwo()
        {
            var g  = new Guid("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");
            var gx = new GuidEx(g);

            Assert.IsTrue(gx.Equals(g));
        }
Exemplo n.º 8
0
        public void ToStringFormat()
        {
            var g  = new Guid("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");
            var gx = new GuidEx(g);

            Assert.AreEqual(g.ToString("X"), gx.ToString("X"));
        }
Exemplo n.º 9
0
        public void ToStringFormatIFormatProvider()
        {
            var g  = new Guid("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");
            var gx = new GuidEx(g);

            Assert.AreEqual(g.ToString("X", CultureInfo.GetCultureInfo("en-US")), gx.ToString("X", CultureInfo.GetCultureInfo("en-US")));
        }
Exemplo n.º 10
0
        public void NewGuidTestText2ParamsTextGuid()
        {
            var g = GuidEx.NewGuid("ThisIsARandomText", Guid.Parse("ed1dff6c-9c86-41be-9a3c-692526f7ecb7"));

            Assert.IsInstanceOfType(g, typeof(GuidEx));
            Assert.AreEqual(g.ToString(), "80e79921-b800-52a1-666a-5b924957d5fd");
        }
Exemplo n.º 11
0
        public void NewGuidTestText2ParamsTextGuidRandom()
        {
            var g = GuidEx.NewGuid("ThisIsARandomText", GuidEx.NewGuid("AnotherRandomText", GuidEx.NameSpaceKeyName));

            Assert.IsInstanceOfType(g, typeof(GuidEx));
            Assert.AreEqual(g.ToString(), "ee436a5b-7af8-56d0-67a6-77b9e411fab7");
        }
Exemplo n.º 12
0
 public XmlEncObject()
 {
     //defaults
     TargetElement = "Body";
     Id            = "EncryptedContent-" + GuidEx.NewGuid().ToString("D");
     Type          = PlainTextType.Content;
 }
Exemplo n.º 13
0
        public void CompareToTestFour()
        {
            var g  = "A random string again.";
            var gx = new GuidEx("a7f9be96-3cb8-4c00-828a-ac0505e72eb2");

            gx.CompareTo(g);
        }
Exemplo n.º 14
0
        public void ConstructorTestText2ParamsUnknownGuid()
        {
            var g = new GuidEx("ThisIsARandomText", GuidEx.NameSpaceUnknown);

            Assert.IsInstanceOfType(g, typeof(GuidEx));
            Assert.AreEqual(g.ToString(), "46526dd3-d88b-5da5-73ba-82023776e697");
        }
Exemplo n.º 15
0
        /// <summary>
        /// 创建或更新角色
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>成功返回角色id</returns>
        public async Task <DataResult <string> > CreateOrUpdateRoleAsync(ApplicationRole role)
        {
            if (role is null)
            {
                throw new ArgumentNullException(nameof(role));
            }

            IdentityResult result;

            if (string.IsNullOrEmpty(role.Id))
            {
                role.Id = GuidEx.NewGuid().ToString();
                //角色Id是空则创建
                result = await roleManager.CreateAsync(role).ConfigureAwait(false);
            }
            else
            {
                //更新
                result = await roleManager.UpdateAsync(role).ConfigureAwait(false);
            }
            if (result.Succeeded)
            {
                return(OkDataResult(role.Id));
            }

            return(FailedDataResult <string>(result.Errors.FirstOrDefault().Description));
        }
Exemplo n.º 16
0
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <Result <long> > AddArticalAsync(AddArticalDto dto)
        {
            Result <long> respone = new Result <long>();

            do
            {
                var existClassification = await db.ArticalClassifications.AnyAsync(e => e.Id == dto.ClassificationId);

                if (!existClassification)
                {
                    respone.ErrorMessage = "分类不存在";
                    break;
                }

                var id = GuidEx.NewGuid();

                await db.Articals.AddAsync(new Article {
                    Id = id,
                    ClassificationId = dto.ClassificationId,
                    Content          = dto.Content,
                    PublishTime      = DateTime.Now,
                    Title            = dto.Title,
                    UserId           = dto.UserId,
                    VisitCount       = 0
                });

                await db.SaveChangesAsync();

                respone.Data = id;

                respone.Succeeded = true;
            } while (false);
            return(respone);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 添加文章分类
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <Result> AddArticalClassificationAsync(AddArticalClassificationDto dto)
        {
            Result respone = new Result();

            do
            {
                //using(var step= MiniProfiler.Current.Step("添加文章分类"))
                {
                    var exist = await db.ArticalClassifications.AnyAsync(e => e.Name == dto.Name);

                    if (exist)
                    {
                        respone.ErrorMessage = "已经存在相同名称分类";
                        break;
                    }

                    await db.ArticalClassifications.AddAsync(new ArticleClassification {
                        Id   = GuidEx.NewGuid(),
                        Name = dto.Name,
                    });

                    await db.SaveChangesAsync();

                    //移除cache
                    await cacheService.RemoveAsync(CacheStringArticlesTypes);

                    respone.Succeeded = true;
                }
            } while (false);
            return(respone);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 添加文章评论
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <Result> AddArticalCommentAsync(AddArticalCommentDto dto)
        {
            Result respone = new Result();

            do
            {
                var existArtical = await db.Articals.AnyAsync(e => e.Id == dto.ArticalId);

                if (!existArtical)
                {
                    respone.ErrorMessage = "文章不存在";
                    break;
                }


                await db.ArticalComments.AddAsync(new ArticleComment {
                    ArticalId      = dto.ArticalId,
                    CommentContent = dto.CommentContent,
                    CommenterId    = dto.CommenterId,
                    CommentTime    = DateTime.Now,
                    Id             = GuidEx.NewGuid()
                });

                await db.SaveChangesAsync();

                respone.Succeeded = true;
            } while (false);
            return(respone);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Executes Kusto query to obtain service data that includes manual review data.
        /// </summary>
        /// <param name="criteria">Service ID, service name or blank string to return the complete list of services.</param>
        /// <returns>
        /// A list of <see cref="SloRecord"/> objects with a potential <see cref="SloValidationException"/> list that is
        /// returned as a tuple.
        /// </returns>
        public Task <Tuple <List <SloRecord>, List <SloValidationException> > > ExecuteQueryAsync(string criteria)
        {
            string kustoQuery;

            if (string.IsNullOrWhiteSpace(criteria))
            {
                kustoQuery = "GetSloJsonActionItemReport() ";
            }
            else if (GuidEx.IsGuid(criteria))
            {
                kustoQuery = $"GetSloJsonActionItemReport() | where ServiceId == '{criteria.Trim()}' ";
            }
            else if (!GuidEx.IsGuid(criteria))
            {
                kustoQuery = $"GetSloJsonActionItemReport() | where ServiceName contains '{criteria.Trim()}' ";
            }
            else
            {
                kustoQuery = criteria;
            }

            return(Task.Run(() => {
                return queryManager_.ExecuteQuery(kustoQuery);
            }));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 创建或者更新权限
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <DataResult <string> > CreateOrUpdatePermissonAsync(Permisson permisson)
        {
            if (permisson is null)
            {
                throw new ArgumentNullException(nameof(permisson));
            }

            if (!string.IsNullOrEmpty(permisson.Id))
            {
                applicationDbContext.Permissons.Update(permisson);
            }
            else
            {
                permisson.Id = GuidEx.NewGuid().ToString();
                await applicationDbContext.Permissons.AddAsync(permisson).ConfigureAwait(false);
            }

            try
            {
                await applicationDbContext.SaveChangesAsync().ConfigureAwait(false);

                return(OkDataResult(permisson.Id));
            }
            catch (DbUpdateException ex)
            {
                return(FailedDataResult <string>(ex));
            }
        }
Exemplo n.º 21
0
        public static Dictionary <string, Guid> GetPathAndGuids(string shellExPath)
        {
            Dictionary <string, Guid> dic = new Dictionary <string, Guid>();

            foreach (string cmhPart in CmhParts)
            {
                using (RegistryKey cmKey = RegistryEx.GetRegistryKey($@"{shellExPath}\{cmhPart}"))
                {
                    if (cmKey == null)
                    {
                        continue;
                    }
                    foreach (string keyName in cmKey.GetSubKeyNames())
                    {
                        using (RegistryKey key = cmKey.OpenSubKey(keyName))
                        {
                            if (!GuidEx.TryParse(key.GetValue("")?.ToString(), out Guid guid))
                            {
                                GuidEx.TryParse(keyName, out guid);
                            }
                            if (!guid.Equals(Guid.Empty))
                            {
                                dic.Add(key.Name, guid);
                            }
                        }
                    }
                }
            }
            return(dic);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 创建或者更新用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <DataResult <string> > CreateOrUpdateUserAsync(ApplicationUser user)
        {
            var v = await applicationUserValidator.ValidateAsync(user).ConfigureAwait(false);

            if (!v.IsValid)
            {
                return(FailedDataResult <string>(v.Errors.FirstOrDefault().ErrorMessage));
            }


            //Id为空则创建
            IdentityResult result;

            if (string.IsNullOrEmpty(user.Id))
            {
                user.Id = GuidEx.NewGuid().ToString();
                result  = await userManager.CreateAsync(user, user.Password).ConfigureAwait(false);
            }
            else
            {
                result = await userManager.UpdateAsync(user).ConfigureAwait(false);
            }

            if (result.Succeeded)
            {
                return(OkDataResult(user.Id));
            }

            return(FailedDataResult <string>(result.Errors.FirstOrDefault().Description));
        }
Exemplo n.º 23
0
 /// <summary>
 /// Constructor for notification arguments.
 /// </summary>
 /// <param name="g">Device class GUID</param>
 /// <param name="att">Device attached, true or false</param>
 /// <param name="nam">Device name</param>
 public DeviceNotificationArgs(GuidEx g,
                               bool att, string nam)
 {
     DeviceInterfaceGUID = g;
     DeviceAttached      = att;
     DeviceName          = nam;
 }
Exemplo n.º 24
0
        public void ConstructorTestText2Params()
        {
            var g = new GuidEx("ThisIsARandomText", "AnotherRandomText");

            Assert.IsInstanceOfType(g, typeof(GuidEx));
            Assert.AreEqual(g.ToString(), "ee436a5b-7af8-56d0-67a6-77b9e411fab7");
        }
Exemplo n.º 25
0
        /// <summary>
        /// 创建或更新角色
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>成功返回角色id</returns>
        public async Task <DataResult <string> > CreateOrUpdateRoleAsync(ApplicationRole role)
        {
            FluentValidation.Results.ValidationResult v = await applicationRoleValidator.ValidateAsync(role).ConfigureAwait(false);

            if (!v.IsValid)
            {
                return(FailedDataResult <string>(v));
            }

            IdentityResult result;

            if (string.IsNullOrEmpty(role.Id))
            {
                role.Id = GuidEx.NewGuid().ToString();
                //角色Id是空则创建
                result = await roleManager.CreateAsync(role).ConfigureAwait(false);
            }
            else
            {
                //更新
                result = await roleManager.UpdateAsync(role).ConfigureAwait(false);
            }
            if (result.Succeeded)
            {
                return(OkDataResult(role.Id));
            }

            return(FailedDataResult <string>(result.Errors.FirstOrDefault().Description));
        }
 private void LoadShellExItems(XmlElement shellExXE, GroupPathItem groupItem)
 {
     foreach (XmlElement itemXE in shellExXE.SelectNodes("Item"))
     {
         if (!JudgeOSVersion(itemXE))
         {
             continue;
         }
         if (!GuidEx.TryParse(itemXE.GetAttribute("Guid"), out Guid guid))
         {
             continue;
         }
         EnhanceShellExItem item = new EnhanceShellExItem
         {
             FoldGroupItem  = groupItem,
             ShellExPath    = $@"{groupItem.TargetPath}\ShellEx",
             Image          = ResourceIcon.GetIcon(itemXE.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.DllDefaultIcon,
             Text           = ResourceString.GetDirectString(itemXE.GetAttribute("Text")),
             DefaultKeyName = itemXE.GetAttribute("KeyName"),
             Guid           = guid
         };
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = GuidInfo.GetText(guid);
         }
         if (item.DefaultKeyName.IsNullOrWhiteSpace())
         {
             item.DefaultKeyName = guid.ToString("B");
         }
         item.ChkVisible.Checked = item.ItemVisible;
         MyToolTip.SetToolTip(item.ChkVisible, itemXE.GetAttribute("Tip"));
         this.AddItem(item);
     }
 }
Exemplo n.º 27
0
        public void ConstructorTestTextGuid()
        {
            var guid = new Guid("{274ebe15-447b-4863-bf89-eb75c3653694}");
            var g    = new GuidEx(guid.ToString());

            Assert.IsInstanceOfType(g, typeof(GuidEx));
            Assert.AreEqual(g.ToString(), guid.ToString());
        }
Exemplo n.º 28
0
 public MessageIdHeader(string id)
 {
     if (id == null || id == String.Empty)
     {
         id = "uuid:" + GuidEx.NewGuid().ToString("D");
     }
     //id = "uuid:" + System.Guid.NewGuid().ToString("D");
     this.text = id;
 }
 private void LoadShellExItems(XmlNode shellExXN, FoldGroupItem groupItem)
 {
     foreach (XmlNode itemXN in shellExXN.SelectNodes("Item"))
     {
         if (!XmlDicHelper.FileExists(itemXN))
         {
             continue;
         }
         if (!XmlDicHelper.JudgeCulture(itemXN))
         {
             continue;
         }
         if (!XmlDicHelper.JudgeOSVersion(itemXN))
         {
             continue;
         }
         if (!GuidEx.TryParse(itemXN.SelectSingleNode("Guid")?.InnerText, out Guid guid))
         {
             continue;
         }
         EnhanceShellExItem item = new EnhanceShellExItem
         {
             FoldGroupItem  = groupItem,
             ShellExPath    = $@"{groupItem.GroupPath}\ShellEx",
             Image          = ResourceIcon.GetIcon(itemXN.SelectSingleNode("Icon")?.InnerText)?.ToBitmap() ?? AppImage.SystemFile,
             DefaultKeyName = itemXN.SelectSingleNode("KeyName")?.InnerText,
             Guid           = guid
         };
         foreach (XmlNode textXE in itemXN.SelectNodes("Text"))
         {
             if (XmlDicHelper.JudgeCulture(textXE))
             {
                 item.Text = ResourceString.GetDirectString(textXE.InnerText);
             }
         }
         if (item.Text.IsNullOrWhiteSpace())
         {
             item.Text = GuidInfo.GetText(guid);
         }
         if (item.DefaultKeyName.IsNullOrWhiteSpace())
         {
             item.DefaultKeyName = guid.ToString("B");
         }
         string tip = "";
         foreach (XmlElement tipXE in itemXN.SelectNodes("Tip"))
         {
             if (XmlDicHelper.JudgeCulture(tipXE))
             {
                 tip = tipXE.GetAttribute("Text");
             }
         }
         ToolTipBox.SetToolTip(item.ChkVisible, tip);
         this.AddItem(item);
     }
 }
Exemplo n.º 30
0
        private string MakeUniqueFileName(IFormFile file)
        {
            long id = GuidEx.NewGuid();

            ///获取扩展名
            var    provider = new FileExtensionContentTypeProvider();
            var    extName  = provider.Mappings.FirstOrDefault(e => e.Value == file.ContentType).Key;
            string filename = $"{id}_{System.IO.Path.GetFileName(file.FileName)}";

            return(filename);
        }
Exemplo n.º 31
0
		/// <summary>
		/// Constructor for notification arguments.
		/// </summary>
		/// <param name="g">Device class GUID</param>
		/// <param name="att">Device attached, true or false</param>
		/// <param name="nam">Device name</param>
		public DeviceNotificationArgs( GuidEx g, 
			bool att, string nam )
		{
			DeviceInterfaceGUID = g;
			DeviceAttached = att;
			DeviceName = nam;			
		}
Exemplo n.º 32
0
		/// <summary>
		/// Constructor for DeviceStatusMonitor.  Specifies
		/// the class of notifications desired and whether
		/// notifications should be fired for already-attached
		/// devices.
		/// </summary>
		/// <param name="devclass">
		/// GUID of device class to monitor (or empty to 
		/// monitor *all* device notifications).
		/// </param>
		/// <param name="notifyAlreadyConnectedDevices">
		/// Set to true to receive notifiations for devices
		/// which were attached before we started monitoring;
		/// set to false to see new events only.
		/// </param>
		public DeviceStatusMonitor( GuidEx devclass,
			bool notifyAlreadyConnectedDevices )
		{
			devClass = devclass;
			fAll = notifyAlreadyConnectedDevices;
		}