コード例 #1
0
ファイル: PublishRequest.cs プロジェクト: Plankankul/Zenity
        /// <summary>
        /// Loads the collection of PublishRequests from database.
        /// </summary>
        /// <param name="isQueuedRequest">if set to <c>true</c> [get queued request].</param>
        /// <returns>The collection of PublishRequests from database</returns>
        public static IEnumerable <PublishRequest> LoadFromDatabase(bool isQueuedRequest)
        {
            List <PublishRequest> requestCollection = new List <PublishRequest>();

            try
            {
                using (var databaseContext = new ZentityAdministrationDataContext(Utilities.ZentityConnectionString))
                {
                    databaseContext.ObjectTrackingEnabled = false;
                    var requestsFromDB = databaseContext.PublishRequestRecoveries.Where(request => request.IsQueuedRequest == isQueuedRequest).OrderBy(request => request.QueueOrder);
                    foreach (PublishRequestRecovery requestFromDB in requestsFromDB)
                    {
                        PublishRequest requestDeserialized = requestFromDB.DeserializeFromXElement();
                        if (requestDeserialized != null)
                        {
                            requestCollection.Add(requestDeserialized);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.TraceMessage(TraceEventType.Error, ex.ToString(), ex.Message);
            }
            return(requestCollection);
        }
コード例 #2
0
ファイル: PublishRequest.cs プロジェクト: Plankankul/Zenity
        /// <summary>
        /// Deletes the PublishRequest from database.
        /// </summary>
        /// <param name="isQueuedRequest">if set to <c>true</c> if it is a queued request.</param>
        /// <param name="deleteAllRows">if set to <c>true</c> deletes all rows.</param>
        /// <returns>True if successful otherwise false.</returns>
        internal bool DeleteFromDatabase(bool isQueuedRequest, bool deleteAllRows)
        {
            try
            {
                if (!deleteAllRows)
                {
                    return(DeleteFromDatabase());
                }

                using (var databaseContext = new ZentityAdministrationDataContext(Utilities.ZentityConnectionString))
                {
                    IEnumerable <PublishRequestRecovery> existingRequestsInDB =
                        databaseContext.PublishRequestRecoveries.Where(request => request.IsQueuedRequest == isQueuedRequest &&
                                                                       request.DataModelNamespace == this.DataModelNamespace &&
                                                                       request.ResourceTypeName == this.ResourceTypeName).ToList();
                    if (existingRequestsInDB.Count() > 0)
                    {
                        databaseContext.PublishRequestRecoveries.DeleteAllOnSubmit(existingRequestsInDB);
                        databaseContext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Globals.TraceMessage(TraceEventType.Error, ex.ToString(), ex.Message);
            }

            return(false);
        }
コード例 #3
0
ファイル: PublishRequest.cs プロジェクト: Plankankul/Zenity
        /// <summary>
        /// Saves the collection of PublishRequests into the database for recovery.
        /// </summary>
        /// <param name="requestCollection">The request collection.</param>
        /// <param name="isQueuedRequest">if set to <c>true</c> [is queued request].</param>
        /// <returns>True if successful otherwise false.</returns>
        public static bool SaveToDatabase(IEnumerable <PublishRequest> requestCollection, bool isQueuedRequest)
        {
            if (requestCollection.Count() > 0)
            {
                return(false);
            }

            try
            {
                using (var databaseContext = new ZentityAdministrationDataContext(Utilities.ZentityConnectionString))
                {
                    List <PublishRequestRecovery> requestCollectionDB = new List <PublishRequestRecovery>();
                    int loopIndexNew = 0;
                    int loopIndexOld = 0;

                    foreach (var sourceRequest in requestCollection)
                    {
                        var existingRequestDB = databaseContext.PublishRequestRecoveries.Where(request => request.InstanceId == sourceRequest.InstanceId).FirstOrDefault();
                        if (existingRequestDB == default(PublishRequestRecovery))
                        {
                            PublishRequestRecovery newRequestDB = new PublishRequestRecovery
                            {
                                InstanceId         = sourceRequest.InstanceId,
                                DataModelNamespace = sourceRequest.DataModelNamespace,
                                ResourceTypeName   = sourceRequest.ResourceTypeName,
                                IsQueuedRequest    = isQueuedRequest,
                                QueueOrder         = isQueuedRequest ? loopIndexNew++ : 0,
                                ObjectData         = sourceRequest.SerializeToXElement()
                            };
                            requestCollectionDB.Add(newRequestDB);
                        }
                        else
                        {
                            existingRequestDB.IsQueuedRequest = isQueuedRequest;
                            existingRequestDB.QueueOrder      = loopIndexOld++;
                            existingRequestDB.ObjectData      = sourceRequest.SerializeToXElement();
                            databaseContext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                        }
                    }

                    if (requestCollectionDB.Count > 0)
                    {
                        databaseContext.PublishRequestRecoveries.InsertAllOnSubmit(requestCollectionDB);
                    }

                    databaseContext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Globals.TraceMessage(TraceEventType.Error, ex.ToString(), ex.Message);
            }

            return(false);
        }
コード例 #4
0
ファイル: PublishRequest.cs プロジェクト: Plankankul/Zenity
        /// <summary>
        /// Saves the PublishRequest into database for recovery.
        /// </summary>
        /// <param name="isQueuedRequest">if set to <c>true</c> [is queued request].</param>
        /// <returns>True if successful otherwise false.</returns>
        internal bool SaveToDatabase(bool isQueuedRequest)
        {
            try
            {
                using (var databaseContext = new ZentityAdministrationDataContext(Utilities.ZentityConnectionString))
                {
                    var existingRequestDB = databaseContext.PublishRequestRecoveries.Where(request => request.InstanceId == this.InstanceId).FirstOrDefault();
                    if (existingRequestDB == default(PublishRequestRecovery))
                    {
                        // If this is a queued request then fetch the highest QueueOrder number.
                        int currentQueueOrder = 0;
                        if (isQueuedRequest)
                        {
                            var queueOrderList = databaseContext.PublishRequestRecoveries.Where(request => request.IsQueuedRequest).Select(request => request.QueueOrder);
                            if (queueOrderList.Count() > 0)
                            {
                                currentQueueOrder = queueOrderList.Max();
                            }
                        }

                        // Create the new PublishRequestRecovery object and add to the database
                        PublishRequestRecovery newPublishRequestDB = new PublishRequestRecovery
                        {
                            InstanceId         = this.InstanceId,
                            DataModelNamespace = this.DataModelNamespace,
                            ResourceTypeName   = this.ResourceTypeName,
                            IsQueuedRequest    = isQueuedRequest,
                            QueueOrder         = currentQueueOrder + 1,
                            ObjectData         = this.SerializeToXElement()
                        };

                        databaseContext.PublishRequestRecoveries.InsertOnSubmit(newPublishRequestDB);
                    }
                    else
                    {
                        if (existingRequestDB.IsQueuedRequest && isQueuedRequest == false)
                        {
                            existingRequestDB.QueueOrder = 0;
                        }
                        existingRequestDB.DataModelNamespace = this.DataModelNamespace;
                        existingRequestDB.ResourceTypeName   = this.ResourceTypeName;
                        existingRequestDB.IsQueuedRequest    = isQueuedRequest;
                        existingRequestDB.ObjectData         = this.SerializeToXElement();
                    }

                    databaseContext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                }
            }
            catch (Exception ex)
            {
                Globals.TraceMessage(TraceEventType.Error, ex.ToString(), ex.Message);
            }

            return(false);
        }
コード例 #5
0
ファイル: PublishRequest.cs プロジェクト: Plankankul/Zenity
        /// <summary>
        /// Deletes the PublishRequest from database.
        /// </summary>
        /// <returns>True if successful otherwise false.</returns>
        internal bool DeleteFromDatabase()
        {
            try
            {
                using (var databaseContext = new ZentityAdministrationDataContext(Utilities.ZentityConnectionString))
                {
                    var existingRequestDB = databaseContext.PublishRequestRecoveries.Where(request => request.InstanceId == this.InstanceId).FirstOrDefault();
                    if (existingRequestDB != default(PublishRequestRecovery))
                    {
                        databaseContext.PublishRequestRecoveries.DeleteOnSubmit(existingRequestDB);
                    }
                    databaseContext.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Globals.TraceMessage(TraceEventType.Error, ex.ToString(), ex.Message);
            }

            return(false);
        }