当前位置: 首页>>代码示例>>C#>>正文


C# SqlDatabase.Add方法代码示例

本文整理汇总了C#中SqlDatabase.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDatabase.Add方法的具体用法?C# SqlDatabase.Add怎么用?C# SqlDatabase.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlDatabase的用法示例。


在下文中一共展示了SqlDatabase.Add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

 private static void Save(Entry[] entries)
 {
     lock (_dbLock)
     {
         using (var db = new SqlDatabase<Entry>(Location, false))
         {
             if (!db.Failed)
             {
                 foreach (var entry in entries)
                 {
                     db.Add(entry);
                 }
             }
         }
     }
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:16,代码来源:BubbleGroupIndex.cs

示例2: Set

 public static void Set(TelegramDc dc)
 {
     lock (_lock)
     {
         using (var db = new SqlDatabase<TelegramDc>(Location))
         {
             foreach (var entry in db.Store.Where(x => x.Dc == dc.Dc))
             {
                 entry.Key = dc.Key;
                 entry.Salt = dc.Salt;
                 db.Update(entry);
                 return;
             }
                 
             db.Add(dc);
         }
     }
 }
开发者ID:akonsand,项目名称:DisaOpenSource,代码行数:18,代码来源:TelegramDcManager.cs

示例3: SetNeedsContactSync

 internal static void SetNeedsContactSync(Service[] services, bool value)
 {
     if (services == null)
         return;
     lock (_lock)
     {
         using (var db = new SqlDatabase<Entry>(Location))
         {
             foreach (var service in services)
             {
                 if (service == null)
                     continue;
                 bool updated = false;
                 foreach (var entry in db.Store.Where(x => x.ServiceName == 
                     service.Information.ServiceName))
                 {
                     Utils.DebugPrint("NeedsContactSync for service " 
                         + service.Information.ServiceName + " is being updated to " + value);
                     entry.NeedsContactSync = value;
                     db.Update(entry);
                     updated = true;
                     break;
                 }
                 if (!updated)
                 {
                     Utils.DebugPrint("NeedsContactSync for service " 
                         + service.Information.ServiceName + " is being set to " + value);
                     db.Add(new Entry
                     {
                         ServiceName = service.Information.ServiceName,
                         NeedsContactSync = value,
                     });
                 }
             }
         }
     }
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:37,代码来源:SettingsChangedManager.cs

示例4: InsertDefaultIfNull

 private static void InsertDefaultIfNull(BubbleGroup group)
 {
     lock (_lock)
     {
         if (group.Settings == null)
         {
             using (var db = new SqlDatabase<BubbleGroupSettings>(GetPath()))
             {
                 var settings = new BubbleGroupSettings
                 {
                     Mute = false,
                     Unread = true,
                     Guid = group.ID,
                     LastUnreadSetTime = 0,
                     ReadTimes = null,
                     ParticipantNicknames = null,
                     NotificationLed = DefaultNotificationLedColor,
                     VibrateOption = null,
                     VibrateOptionCustomPattern = null,
                     Ringtone = null,
                 };
                 db.Add(settings);
                 group.Settings = settings;
             }
         }
     }
 }        
开发者ID:StefanTischler,项目名称:DisaOpenSource,代码行数:27,代码来源:BubbleGroupSettingsManager.cs

示例5: InsertDefaultIfNull

 private static void InsertDefaultIfNull(BubbleGroup group)
 {
     lock (_lock)
     {
         if (group.Settings == null)
         {
             using (var db = new SqlDatabase<BubbleGroupSettings>(GetPath()))
             {
                 var settings = new BubbleGroupSettings
                 {
                     Mute = false,
                     Unread = true,
                     Guid = group.ID,
                     LastUnreadSetTime = 0,
                     ReadTimes = null,
                 };
                 db.Add(settings);
                 group.Settings = settings;
             }
         }
     }
 }
开发者ID:Zaldroc,项目名称:DisaOpenSource,代码行数:22,代码来源:BubbleGroupSettingsManager.cs

示例6: GetThumbnail

        public DisaThumbnail GetThumbnail(string id, bool group, bool small)
        {
            if (id == null)
            {
                return null;
            }
            var key = id + group + small;


            Func<DisaThumbnail, MemoryStream> convertThumbnailToMemoryStream = thumbnail =>
            {
                MemoryStream memoryStream = new MemoryStream();
                Serializer.Serialize<DisaThumbnail>(memoryStream, thumbnail);
                return memoryStream;
            };


            Func<DisaThumbnail, byte[]> serializeDisaThumbnail = thumbnail =>
            {
                using (var memoryStream = convertThumbnailToMemoryStream(thumbnail))
                {
                    return memoryStream.ToArray();
                }
            };

            Func<DisaThumbnail, DisaThumbnail> cache = thumbnail =>
            {
                if (thumbnail == null)
                {
                    return null;
                }
                lock (_cachedThumbnailsLock)
                {
                    using (var database = new SqlDatabase<CachedThumbnail>(GetThumbnailDatabasePath()))
                    {
                        var bytes = serializeDisaThumbnail(thumbnail);
                        if (bytes == null)
                        {
                            return null;
                        }
                        var cachedThumbnail = new CachedThumbnail
                        {
                            Id = key,
                            ThumbnailBytes = bytes
                        };

                        var dbThumbnail = database.Store.Where(x => x.Id == key).FirstOrDefault();
                        if (dbThumbnail != null)
                        {
                            DebugPrint(">>>>>> Saving cached thumbnail after deletion ");
                            database.Store.Delete(x => x.Id == key);
                            database.Add(cachedThumbnail);
                        }
                        else
                        {
                            DebugPrint(">>>>>> Saving cached thumbnail ");
                            database.Add(cachedThumbnail);
                        }
                    }
                }
                return thumbnail;
            };

            lock (_cachedThumbnailsLock)
            {
                using (var database = new SqlDatabase<CachedThumbnail>(GetThumbnailDatabasePath()))
                {
                    Retry:
                    var dbThumbnail = database.Store.Where(x => x.Id == key).FirstOrDefault();
                    if (dbThumbnail != null)
                    {
                        if (dbThumbnail.ThumbnailBytes == null)
                        {
                            return null;
                        }
                        using (var stream = new MemoryStream(dbThumbnail.ThumbnailBytes))
                        {
                            var disaThumbnail = Serializer.Deserialize<DisaThumbnail>(stream);
                            disaThumbnail.Failed = false;
                            if (!File.Exists(disaThumbnail.Location))
                            {
                                DebugPrint("The thumbnail cache was purged! purging the database so that everything is redownloaded");
                                database.DeleteAll();
                                goto Retry;
                            }
                            return disaThumbnail;
                        }
                    }
                }
            }
            if (group)
            {
                var chat = _dialogs.GetChat(uint.Parse(id));
                DebugPrint(">>>> Getting Thumbail for " + TelegramUtils.GetChatTitle(chat));
                if (chat == null)
                {
                    return null;
                }
                var fileLocation = TelegramUtils.GetChatThumbnailLocation(chat, small);
                if (fileLocation == null)
//.........这里部分代码省略.........
开发者ID:harper10,项目名称:DisaOpenSource,代码行数:101,代码来源:Telegram.cs

示例7: Add

 private static Entry Add(VisualBubble bubble)
 {
     lock (_dbLock)
     {
         using (var db = new SqlDatabase<Entry>(Location))
         {
             // don't add a duplicate bubble in the queue
             foreach (var possibleBubble in db.Store)
             {
                 if (possibleBubble.Guid == bubble.ID)
                     return possibleBubble;
             }
             var entry = new Entry()
             {
                 ServiceName = bubble.Service.Information.ServiceName,
                 Guid = bubble.ID,
                 Time = bubble.Time
             };
             db.Add(entry);
             return entry;
         }
     }
 }
开发者ID:Zaldroc,项目名称:DisaOpenSource,代码行数:23,代码来源:BubbleQueueManager.cs

示例8: AddNotQueued

 private static NotQueuedEntry AddNotQueued(VisualBubble bubble, BubbleGroup group)
 {
     lock (_dbLock)
     {
         var bubbleId = bubble.ID;
         using (var db = new SqlDatabase<NotQueuedEntry>(NotQueuedLocation))
         {
             // don't add a duplicate group into the queue
             foreach (var possibleGroup in db.Store.Where(x => x.Guid == bubbleId))
             {
                 return possibleGroup;
             }
             var entry = new NotQueuedEntry
             {
                 ServiceName = group.Service.Information.ServiceName,
                 BubbleGroupGuid = group.ID,
                 Guid = bubble.ID,
                 Time = bubble.Time,
             };
             db.Add(entry);
             return entry;
         }
     }
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:24,代码来源:BubbleQueueManager.cs

示例9: CreateCachedUserAndAdd

 private void CreateCachedUserAndAdd(IUser user, uint userId, SqlDatabase<CachedUser> database)
 {
     using (var memoryStream = ConvertUserToMemoryStream(user))
     {
         var cachedUser = new CachedUser
         {
             Id = userId,
             ProtoBufBytes = memoryStream.ToArray(),
         };
         var dbUser = database.Store.Where(x => x.Id == userId).FirstOrDefault();
         if (dbUser != null)
         {
             database.Store.Delete(x => x.Id == userId);
             database.Add(cachedUser);
         }
         else
         {
             database.Add(cachedUser);
         }
     }
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:21,代码来源:CachedDialogs.cs

示例10: CreateCachedChatAndAdd

        private void CreateCachedChatAndAdd(IChat chat, uint chatId, SqlDatabase<CachedChat> database)
        {
            using (var memoryStream = ConvertChatToMemoryStream(chat))
            {
                CachedChat cachedChat = null;
                if (chat is Chat)
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        isChat = true,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                else
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        isChat = false,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }

                var dbUser = database.Store.Where(x => x.Id == chatId).FirstOrDefault();
                if (dbUser != null)
                {
                    database.Store.Delete(x => x.Id == chatId);
                    database.Add(cachedChat);
                }
                else
                {
                    database.Add(cachedChat);
                }
            }
        }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:36,代码来源:CachedDialogs.cs

示例11: Add

 internal static void Add(BubbleGroup group)
 {
     lock (_dbLock)
     {
         if (group is UnifiedBubbleGroup)
             return;
         Remove(group.ID);
         using (var db = new SqlDatabase<Entry>(Location, false))
         {
             if (!db.Failed)
             {
                 var lastBubble = group.LastBubbleSafe();
                 var serviceName = group.Service.Information.ServiceName;
                 db.Add(new Entry
                 {
                     Guid = group.ID,
                     Service = serviceName,
                     LastBubble = SerializeBubble(lastBubble),
                     LastBubbleGuid = lastBubble.ID
                 });
             }
         }
     }
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:24,代码来源:BubbleGroupIndex.cs

示例12: AddUnified

 internal static void AddUnified(UnifiedBubbleGroup unifiedGroup)
 {
     lock (_dbLock)
     {
         RemoveUnified(unifiedGroup.ID);
         using (var db = new SqlDatabase<Entry>(Location, false))
         {
             if (!db.Failed)
             {
                 db.Add(new Entry
                 {
                     Guid = unifiedGroup.ID,
                     Unified = true,
                     UnifiedBubbleGroupsGuids = unifiedGroup.Groups.Select(x => x.ID).
                         Aggregate((current, next) => current + "," + next),
                     UnifiedPrimaryBubbleGroupGuid = unifiedGroup.PrimaryGroup.ID,
                     UnifiedSendingBubbleGroupGuid = unifiedGroup.SendingGroup.ID,
                 });
             }
         }
     }
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:22,代码来源:BubbleGroupIndex.cs

示例13: CreateCachedChatAndAdd

        private void CreateCachedChatAndAdd(IChat chat, uint chatId, SqlDatabase<CachedChat> database)
        {
            using (var memoryStream = ConvertChatToMemoryStream(chat))
            {
                CachedChat cachedChat = null;
                if (chat is Chat)
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        IsChat = true,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                else 
                {
                    cachedChat = new CachedChat
                    {
                        Id = chatId,
                        IsChat = false,
                        ProtoBufBytes = memoryStream.ToArray(),
                    };
                }
                //Additional check to prevent overwritng a channel without a access hash
                if (chat is Channel)
                {
                    var channel = chat as Channel;
                    if (channel.AccessHash == 0)
                    {
                        return;
                    }
                }

                var dbChat = database.Store.Where(x => x.Id == chatId).FirstOrDefault();
                if (dbChat != null)
                {
                    cachedChat.Pts = dbChat.Pts;
                    database.Store.Delete(x => x.Id == chatId);
                    database.Add(cachedChat);
                }
                else
                {
                    database.Add(cachedChat);
                }
            }

        }
开发者ID:harper10,项目名称:DisaOpenSource,代码行数:47,代码来源:CachedDialogs.cs

示例14: UpdateChatPts

 public void UpdateChatPts(uint channelId, uint pts)
 {
     lock (_chatLock)
     {
         using (var database = new SqlDatabase<CachedChat>(GetDatabasePath(false)))
         {
             var cachedChat = database.Store.Where(x => x.Id == channelId).FirstOrDefault();
             if (cachedChat == null)
             {
                 return;
             }
             cachedChat.Pts = pts;
             database.Store.Delete(x => x.Id == channelId);
             database.Add(cachedChat);
             Utils.DebugPrint("$$$$ saved pts for chat as " + cachedChat.Pts);
         }
     }
 }
开发者ID:harper10,项目名称:DisaOpenSource,代码行数:18,代码来源:CachedDialogs.cs


注:本文中的SqlDatabase.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。