Exemplo n.º 1
0
        private void DownloadUpdate(UpdateXml[] update)
        {
            UpdateArguments[] arguments = new UpdateArguments[update.Length];
            int i = 0;

            foreach (UpdateXml updateXml in update)
            {
                UpdateDownloadForm form   = new UpdateDownloadForm(updateXml.Uri, updateXml.Md5, this.applicationInfo.ApllicationIcon);
                DialogResult       result = form.ShowDialog(this.applicationInfo.Context);

                if (result == DialogResult.OK)
                {
                    string currentPath = this.applicationInfo.ApplicationAssembly.Location;
                    string newPath     = Path.GetDirectoryName(currentPath) + "\\" + updateXml.FileName;

                    arguments[i++] = new UpdateArguments(form.TempFilePath, currentPath, newPath, updateXml.LaunchArgs);
                }
                else if (result == DialogResult.Abort)
                {
                    MessageBox.Show("The update download was cancelled\nThe program hasn't been modified",
                                    "Update download cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("There was a problem downloading update",
                                    "Update download error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            UpdateApplication(arguments);
            Application.Exit();
        }
        protected async Task <IActionResult> UpdateAsync(UpdateArguments <TEntity> arguments)
        {
            var query = this.context.Set <TEntity>()
                        .AsTracking();

            if (this.DefaultPredicate != null)
            {
                query = query.Where(this.DefaultPredicate);
            }

            if (typeof(DAL.IHasSoftDelete).IsAssignableFrom(typeof(TEntity)))
            {
                query = query.Cast <DAL.IHasSoftDelete>().Where(x => !x.IsDeleted).Cast <TEntity>();
            }

            if (arguments.Predicate != null)
            {
                query = query.Where(arguments.Predicate);
            }

            var entity = await query.SingleOrDefaultAsync();

            if (entity == null)
            {
                return(this.NotFound());
            }

            arguments.UpdateAction?.Invoke(entity);

            await this.context.SaveChangesAsync();

            return(await arguments.GetAction(entity.Id));
        }
Exemplo n.º 3
0
        public void UpdateKey_Success()
        {
            //Arrange
            Exception       exception      = null;
            Locker          locker         = null;
            string          lockerFilePath = Path.Combine(TestContext.DeploymentDirectory, "lockerforupdates.bin");
            UpdateArguments arguments      = new UpdateArguments
            {
                LockerPath = lockerFilePath,
                Password   = "******",
                Key        = "somekey",
                Value      = "anothervalue"
            };

            //Act
            try
            {
                Program.UpdateKey(arguments);
                locker = Program.GetLocker(arguments);
            }
            catch (Exception e)
            {
                exception = e;
            }

            //Assert
            Assert.IsNull(exception, $"Was not expecting an exception [{exception}]");

            Assert.IsNotNull(locker, "Was expecting to have a locker");
            Assert.AreEqual(1, locker.Keys.Count, "Was expecting to have 1 key");
            Assert.AreEqual("somekey", locker.Keys.First().Key, "key name mismatch");
            Assert.AreEqual("anothervalue", locker.Keys.First().Value, "value name mismatch");
        }
Exemplo n.º 4
0
        private async Task <object> ParseUpdateArguments(string[] arguments, Message message)
        {
            var args      = new UpdateArguments();
            var optionSet = new OptionSet();

            optionSet.Parse(arguments);

            return(args);
        }
        public GitHubIssueMock()
        {
            issues = new Mock <IIssuesClient>(MockBehavior.Strict);

            issues
            .Setup(issues => issues.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <NewIssue>()))
            .ReturnsAsync((Func <string, string, NewIssue, Issue>)CreateIssue)
            .Callback <string, string, NewIssue>(
                (owner, name, newIssue) =>
            {
                CreateIssueArgs = new CreateArguments(owner, name, newIssue);
            });

            issues
            .Setup(issues => issues.Update(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <IssueUpdate>()))
            .ReturnsAsync((Func <string, string, int, IssueUpdate, Issue>)UpdateIssue)
            .Callback <string, string, int, IssueUpdate>(
                (owner, name, number, issueUpdate) =>
            {
                UpdateIssueArgs = new UpdateArguments(owner, name, number, issueUpdate);
            });

            comment = new Mock <IIssueCommentsClient>(MockBehavior.Strict);

            comment
            .Setup(comment => comment.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>()))
            .ReturnsAsync((Func <string, string, int, string, IssueComment>)CreateComment)
            .Callback <string, string, int, string>(
                (owner, name, number, newComment) =>
            {
                createCommentArgs.Add(new CreateCommentArguments(owner, name, number, newComment));
            });

            comment
            .Setup(comment => comment.Delete(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(CompletedTask)
            .Callback <string, string, int>(
                (owner, name, number) =>
            {
                deleteCommentArgs.Add(new DeleteCommentArguments(owner, name, number));
            });

            comment
            .Setup(comment => comment.GetAllForIssue(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync((Func <string, string, int, IReadOnlyList <IssueComment> >)GetAllCommentsForIssue)
            .Callback <string, string, int>(
                (owner, name, number) =>
            {
                GetAllCommentsForIssueArgs = new GetAllCommentsForIssueArguments(owner, name, number);
            });

            issues.Setup(issues => issues.Comment).Returns(Comment);

            createCommentArgs = new List <CreateCommentArguments>();
            deleteCommentArgs = new List <DeleteCommentArguments>();
            issueComments     = new Dictionary <int, IssueComment[]>();
        }
Exemplo n.º 6
0
        void MergeReminders()
        {
            TicketReminderModel[] reminders = Source.Reminders();
            UpdateArguments       args      = new UpdateArguments("RefID", Destination.TicketID);

            foreach (TicketReminderModel reminderModel in reminders)
            {
                Data_API.Update(Destination, args);
            }
        }
Exemplo n.º 7
0
        void MergeChildren()
        {
            //TODO: Think about when parentid = ticketid
            UpdateArguments args = new UpdateArguments("ParentID", Destination.TicketID);

            TicketModel[] children = Source.ChildTickets();
            foreach (TicketModel child in children)
            {
                Data_API.Update(child, args);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// UPDATE
        /// </summary>
        public static void Update <T>(T proxy)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name)
                    {
                    case "ActionProxy":
                        ActionProxy actionProxy = proxy as ActionProxy;
                        //DataAPI.DataAPI.Update(new ActionNode(connection, actionProxy.ActionID), actionProxy);
                        break;

                    case "AttachmentProxy":
                        AttachmentProxy attachmentProxy = proxy as AttachmentProxy;
                        UpdateArguments args            = new UpdateArguments();
                        args.Append("FileName", attachmentProxy.FileName);
                        args.Append("Path", attachmentProxy.Path);
                        args.Append("FilePathID", attachmentProxy.FilePathID.Value);
                        Data_API.Update(new AttachmentModel(connection, attachmentProxy), args);
                        break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed to read
                //int logid = DataAPI.Data_API.LogException(connection.Authentication, ex, "Ticket Merge Exception:" + ex.Source);
                //return $"Error merging tickets. Exception #{logid}. Please report this to TeamSupport by either emailing [email protected], or clicking Help/Support Hub in the upper right of your account.";
            }
        }
Exemplo n.º 9
0
        void MergeAssets()
        {
            AssetTicketModel[] assetTickets = Source.AssetTickets();
            if (assetTickets.Length == 0)
            {
                return;
            }

            AssetTicketModel[] destinationAssetTickets = Destination.AssetTickets();
            UpdateArguments    args = new UpdateArguments("TicketID", Destination.TicketID);

            foreach (AssetTicketModel assetTicket in assetTickets)
            {
                // WHERE NOT EXISTS (Select AssetTickets WITH (NOLOCK) WHERE AssetId = {asset} AND TicketId ={sourceTicket.TicketID})
                if (!destinationAssetTickets.Where(a => a.Asset.AssetID == assetTicket.Asset.AssetID).Any())
                {
                    Data_API.Update(assetTicket, args);
                }
                else
                {
                    Data_API.Delete(assetTicket);
                }
            }
        }
 public UpdateResult Update(EphorteIdentity identity, UpdateArguments arguments)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
        private async Task UpdateItem(UpdateArguments args, Message message)
        {
            var m = await message.Channel.SendMessage("Updating...");

            using (var db = new Database())
            {
                // Excluding items not in the db
                var updated = 0;

                var runeday = await RSUtil.GetRuneday();

                var total = await db.Database.SqlQuery <int>(
                    "SELECT COUNT(*) " +
                    "FROM items " +
                    "WHERE Id <> 0 " +
                    "AND UpdatedAtRD <> @p0", runeday)
                            .FirstAsync();

                db.Database.Log = Console.WriteLine;

                for (var i = 0;; i++)
                {
                    // Getting item batch
                    var items = await db.Database.SqlQuery <item>(
                        "SELECT * " +
                        "FROM items " +
                        "WHERE Id <> 0 " +
                        "AND UpdatedAtRD <> @p0 " +
                        "LIMIT @p1, 50"
                        , runeday
                        , i * 50)
                                .ToListAsync();

                    if (items.Count <= 0)
                    {
                        break;
                    }

                    var tasks = new Task <item> [items.Count];

                    // Starting tasks
                    items.ForEachWithIndex((index, item)
                                           => tasks[index] = RSUtil.GetItemForId((int)item.Id, item.Name, runeday));

                    // Waiting for tasks to complete
                    await Task.Run(() =>
                    {
                        try { Task.WaitAll(tasks); } catch (Exception) {}
                    });

                    var updateQuery = "UPDATE items SET Price = (CASE";

                    var predicatedTasks = tasks.Where(t => t.Status == TaskStatus.RanToCompletion);
                    predicatedTasks.ForEach(t => updateQuery += $" WHEN Id = {t.Result.Id} THEN {t.Result.Price}");

                    updateQuery += " ELSE Price END), UpdatedAtRD = @p0, UpdatedAt = @p1 WHERE Id In " +
                                   $"({string.Join(",", predicatedTasks.Select(t => t.Result.Id))});";

                    updated += db.Database.ExecuteSqlCommand(updateQuery
                                                             , runeday
                                                             , DateTime.Now);

                    await m.Edit($"Updated **{updated}**/**{total}** items.");
                }

                await message.Channel.SendMessage($"Item updates completed. Updated **{updated}**/**{total}** items.");
            }
        }