Example #1
0
        public void PrepareRefresh(SyncTask type, SyncList sl, string[] paramList)
        {
            webClient          = new WebClient();
            webClient.Encoding = Encoding.UTF8;
            string      username = paramList[0];
            string      xmlStr   = webClient.DownloadString("http://myanimelist.net/malappinfo.php?u=" + username + "&status=all&type=anime");
            XmlDocument xmlDoc   = new XmlDocument();

            xmlDoc.LoadXml(xmlStr);
            this.animeNodes = xmlDoc.GetElementsByTagName("anime");

            switch (type)
            {
            case SyncTask.ALL: totalProg = animeNodes.Count; break;

            case SyncTask.NEW: totalProg = animeNodes.Count; break;

            case SyncTask.ONE: totalProg = 1; break;

            case SyncTask.UPDATE: totalProg = animeNodes.Count; break;
            }

            i    = 0;
            prog = 1;
        }
Example #2
0
        private void SyncBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            object[] arguments = (object[])e.Argument;

            SyncTask syncTask = (SyncTask)arguments[0];
            bool     shouldImportListItems = (bool)arguments[1];
            bool     shouldExportListItems = (bool)arguments[2];
            bool     shouldImportDocuments = (bool)arguments[3];
            bool     shouldExportDocuments = (bool)arguments[4];
            bool     shouldSkipUpdates     = (bool)arguments[5];
            int      includeVersionsLimit  = (int)arguments[6];

            string[] excludeFields = (string[])arguments[7];

            try
            {
                SyncTasksManager.GetInstance().ExportSyncTaskItems(syncTask, shouldExportListItems, shouldExportDocuments, shouldImportListItems, SyncBackgroundWorker, null, includeVersionsLimit);

                if (shouldImportListItems == true)
                {
                    SyncTasksManager.GetInstance().ProcessSyncTaskExportFiles(syncTask, SyncBackgroundWorker);
                    SyncTasksManager.GetInstance().ImportSyncTaskItems(syncTask, shouldSkipUpdates, excludeFields, SyncBackgroundWorker);
                }

                string folderPath = ConfigurationManager.GetInstance().GetSyncTaskFolder(syncTask);
                System.Diagnostics.Process.Start("explorer.exe", folderPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured:" + ex.Message + Environment.NewLine + "StackTrace:" + ex.StackTrace);
                Logger.Error(ex, "ProcessSyncTaskExport");
            }
        }
        public void pauseAndResumeFromTaskTreeTest()
        {
            SyncTriggerSystem system = createSystem();
            SyncTask          task   = system.doTask("Use",
                                                     useAction1,//在AskTask暂停了
                                                     useAction2);

            void useAction1(CardEngine g1)
            {
                g1.trigger.doTask("Ask",
                                  askAction1,
                                  askAction2);
                void askAction1(CardEngine g2)
                {
                    g2.trigger.currentTask.parent.context["i"] = 1;
                }

                void askAction2(CardEngine g2)
                {
                    g2.trigger.pauseTask(g2.trigger.currentTask);
                }
            }

            void useAction2(CardEngine g1)
            {
                g1.trigger.currentTask.context["i"] = 2;
            }

            Assert.AreEqual(1, task.context["i"]);
            Assert.AreEqual(1, system.getPausedTasks().Count());
            system.resumeTask(system.getPausedTasks().First());
            Assert.AreEqual(2, task.context["i"]);
            Assert.AreEqual(0, system.getPausedTasks().Count());
        }
Example #4
0
        private void clearTimedOutRequests(object state)
        {
            lock (this.waitingTasks)
            {
                while (this.timeoutTasks.Count > 0)
                {
                    SyncTask sTask = this.timeoutTasks.Max;
                    Thread.BeginCriticalRegion();
                    if (sTask.TimeoutMomentUtc <= DateTime.UtcNow)
                    {
                        this.timeoutTasks.Remove(sTask);
                        this.waitingTasks.RemoveO1(sTask);
                        this.syncTaskLookup.Remove(sTask.ReceiptTask);

                        sTask.TrySignalSource(SyncTask.SourceStates.False);
                        sTask.Dispose();
                    }
                    else
                    {
                        int delay = Math.Max(0, (int)Math.Ceiling((sTask.TimeoutMomentUtc - DateTime.UtcNow).TotalMilliseconds));
                        this.timer.Change(delay, Timeout.Infinite);
                        break;
                    }
                    Thread.EndCriticalRegion();
                }
            }
        }
Example #5
0
        public SyncTask response(int playerId, EventContext responseContext)
        {
            SyncTask resTask = _pausedTaskList.FirstOrDefault();

            foreach (SyncTask task in _pausedTaskList)
            {
                EventContext currContext = task.context;
                if (currContext.getVar <bool>("isAny") && currContext.getVar <int[]>("playersId").Contains(playerId) ||
                    currContext.getVar <int[]>("playersId").FirstOrDefault() == playerId)
                {
                    foreach (var item in responseContext)
                    {
                        task.context[item.Key] = item.Value;
                    }
                    currentTask = resTask;
                    if (!currContext.getVar <SyncFunc <bool> >("isValidResponse").evaluate(game))
                    {
                        currentTask = null;
                        pauseTask(resTask);
                    }
                    else
                    {
                        currentTask = null;
                        resTask     = resumeTask(resTask);
                    }
                    return(resTask);
                }
            }
            return(resTask);
        }
 protected void ExecuteSync(SyncTask <Task> task)
 {
     Task.Run(async() =>
     {
         await task();
     }).Wait();
 }
Example #7
0
        public SyncTask doTask(EventContext eventContext, ActionCollection actions)
        {
            SyncTask task = new SyncTask(++_lastTaskId, actions)
            {
                _context = eventContext
            };

            if (currentTask != null && currentTask != task)
            {
                currentTask.addChild(task);
            }
            currentTask = task;
            todoTask(task);
            if (task.state == SyncTaskState.finished)
            {
                currentTask = task.parent;
            }
            else if (task.state == SyncTaskState.paused)
            {
                currentTask = null;
            }
            else
            {
                throw new TaskStillRunningException(task);
            }
            return(task);
        }
Example #8
0
 public void BeginSceneActivation(CompleteHandler callback, object param = null)
 {
     if (this._asyncOperation != null)
     {
         SyncTask.Create(this.HandleSceneActivation(callback, param));
     }
 }
Example #9
0
 protected void LoadAsset(bool useWWW, bool fromCache, bool sync)
 {
     SyncTask.Create(
         this.LoadAssetInternal(
             this._isManifest ? this.assetBundleName : AssetsManager.RemapVariantName(this.assetBundleName),
             this.assetName, useWWW, fromCache, sync));
 }
Example #10
0
 private void DeleteTasks()
 {
     ResultClear();
     if (Tasks_ListView.SelectedItems.Count > 0)
     {
         int errors = 0;
         foreach (var selectedItem in Tasks_ListView.SelectedItems)
         {
             SyncTask item = (SyncTask)selectedItem;
             if (!Settings.SyncTasks.Remove(item))
             {
                 errors++;
             }
         }
         bool result = errors > 0 ? false : true;
         if (result)
         {
             Settings.SaveSyncTasks();
         }
         else
         {
             Settings.LoadSyncTasks(); //При неудачном удалении загружаем последнюю версию файла
         }
         Tasks_ListView.Items.Refresh();
         ResultShow(result);
     }
 }
        public void reponseTest()
        {
            SyncTriggerSystem system = createSystem();
            SyncTask          task   = system.request(1, new EventContext("discover")
            {
                { "cards", new int[] { 1, 2, 3 } }
            }, 3, ALambda.doNothing, new FLambda <bool>(game =>
            {
                EventContext context = game.trigger.currentTask.context;
                int[] cards          = context.getVar <int[]>("cards");
                int card             = context.getVar <int>("card");
                return(cards.Contains(card));
            }));

            task = system.response(1, new EventContext("discover")
            {
                { "card", 4 }
            });
            Assert.AreEqual(SyncTaskState.paused, task.state);
            task = system.response(2, new EventContext("discover")
            {
                { "card", 3 }
            });
            Assert.AreEqual(SyncTaskState.paused, task.state);
            task = system.response(1, new EventContext("discover")
            {
                { "card", 3 }
            });
            Assert.AreEqual(SyncTaskState.finished, task.state);
        }
Example #12
0
        private void ChangeTask()
        {
            if (Tasks_ListView.SelectedItems.Count != 1)
            {
                return;
            }

            SyncTask syncTask = Tasks_ListView.SelectedItem as SyncTask;

            if (syncTask == null)
            {
                return;
            }

            CreateTaskDialog dialog = new CreateTaskDialog(core, syncTask)
            {
                Title = "Изменение задачи"
            };

            if (dialog.ShowDialog() == true)
            {
                int i = Tasks_ListView.SelectedIndex;
                Settings.SyncTasks.RemoveAt(i);
                Settings.SyncTasks.Insert(i, dialog.SyncTask);
                Settings.SaveSyncTasks();
                Tasks_ListView.Items.Refresh();
            }
        }
Example #13
0
 public void Initialize(SyncTask syncTask)
 {
     SyncTask     = syncTask;
     IsInEditMode = true;
     //SourceDataFoldersSelector.Initialize();
     //DestinationDataFoldersSelector.Initialize();
     //ApplicationContext.Current.SPCamlStudio.ServerObjectExplorer.
 }
Example #14
0
        public virtual void Load(AssetsCompleteHandler completeHandler, ProgressHandler progressHandler,
                                 ErrorHandler errorHandler, bool useWWW = false, bool fromCache = true, bool sync = false)
        {
            this.completeHandler = completeHandler;
            this.progressHandler = progressHandler;
            this.errorHandler    = errorHandler;

            AssetsProxy assetsProxy = AssetsManager.GetAssetBundle(this.assetBundleName);

            if (assetsProxy != null)
            {
                this.completeHandler?.Invoke(this, assetsProxy);
                return;
            }

            if (Application.isEditor)
            {
                fromCache = false;
            }

            this._canceled = false;

            if (!this._isManifest)
            {
                string[] dependencies = GAssetBundleManifest.GetAllDependencies(this.assetBundleName);
                if (dependencies != null &&
                    dependencies.Length > 0)
                {
                    int           count = dependencies.Length;
                    List <string> dependenciesNotLoaded = new List <string>();
                    for (int i = 0; i < count; i++)
                    {
                        dependencies[i] = AssetsManager.RemapVariantName(dependencies[i]);
                        AssetsProxy dAssetsProxy = AssetsManager.GetAssetBundle(dependencies[i]);
                        if (dAssetsProxy == null)
                        {
                            dependenciesNotLoaded.Add(dependencies[i]);
                        }
                    }
                    if (dependenciesNotLoaded.Count == 0)
                    {
                        this.LoadAsset(useWWW, fromCache, sync);
                    }
                    else
                    {
                        SyncTask.Create(this.LoadDependenciesInternal(dependenciesNotLoaded, useWWW, fromCache, sync));
                    }
                }
                else
                {
                    this.LoadAsset(useWWW, fromCache, sync);
                }
            }
            else
            {
                this.LoadAsset(useWWW, fromCache, sync);
            }
        }
        public void pauseResumeFromOtherTaskTreeTest()
        {
            SyncTriggerSystem system  = createSystem();
            SyncTask          taskUse = system.doTask("Use",
                                                      useAction1,
                                                      useAction2);

            void useAction1(CardEngine g1)
            {
                g1.trigger.doTask("Ask",
                                  askAction1,
                                  askAction2);
                void askAction1(CardEngine g2)
                {
                    g2.trigger.currentTask.parent.context["i"] = 1;
                }

                void askAction2(CardEngine g2)
                {
                    g2.trigger.pauseTask(g2.trigger.currentTask);
                }
            }

            void useAction2(CardEngine g1)
            {
                int i = g1.trigger.currentTask.context.getVar <int>(nameof(i));

                g1.trigger.currentTask.context.setVar(nameof(i), i * 2);
            }

            Assert.AreEqual(1, taskUse.context["i"]);
            Assert.AreEqual(1, system.getPausedTasks().Count());
            SyncTask taskSkill = system.doTask("Skill",
                                               skillAction1,
                                               skillAction2,
                                               skillAction3);

            void skillAction1(CardEngine g1)
            {
                g1.trigger.getPausedTasks()[0].parent.context["i"] = 2;
            }

            void skillAction2(CardEngine g1)
            {
                g1.trigger.resumeTask(g1.trigger.getPausedTasks()[0]);
            }

            void skillAction3(CardEngine g1)
            {
                g1.trigger.currentTask.context["j"] = 3;
            }

            Assert.AreEqual(4, taskUse.context["i"]);
            Assert.AreEqual(0, system.getPausedTasks().Count());
            Assert.AreEqual(3, taskSkill.context["j"]);
        }
Example #16
0
        public bool Remove(SyncTask item)
        {
            if (item == null)
            {
                return(false);
            }
            SyncTask syncItem;

            return(m_SyncItems.TryRemove(item.ItemName, out syncItem));
        }
Example #17
0
        public async Task <SyncTask> AddTaskAsync(SyncTask syncTask)
        {
            SyncTask newSyncTask = new SyncTask();

            newSyncTask.Id          = Guid.NewGuid().ToString();
            newSyncTask.Description = syncTask.Description;
            newSyncTask.DueDateTime = syncTask.DueDateTime;
            newSyncTask.Title       = syncTask.Title;
            Tasks.Add(newSyncTask);
            return(newSyncTask);
        }
Example #18
0
        public CreateTaskDialog(SyncCore syncCore, SyncTask syncTask) : this(syncCore)
        {
            localPaths.AddRange(syncTask.LocalPaths);
            selectedUri = syncTask.ServerDirectoryUri;
            backupCount = syncTask.BackupCount;
            syncTimer   = syncTask.SyncTimer;

            LocalPaths_ListBox.Items.Refresh();
            SelectedDirName_TexBlock.Text = syncTask.ServerDirName;
            backupCount = syncTask.BackupCount;
        }
        public void RemoveUnnecessarySyncItemsTest_CalledWithoutFilter_SyncTaskNotRemoved()
        {
            SyncTask syncTask = new SyncTask("Test");
            CreateDirectorySyncItem syncItem = new CreateDirectorySyncItem(directory_testtest);

            this.target.Add(syncTask, syncItem);

            this.target.RemoveUnnecessarySyncItems();

            Assert.AreEqual(1, target.SyncTaskPreviewBySyncTask.Count, "SyncTaskPreviewBySyncTask should contain one element.");
        }
        public void AddTest_AddOneElement_SyncTaskPreviewBySyncTaskContainsOneNestedSyncItem()
        {
            SyncTask syncTask = new SyncTask("Test");
            CreateDirectorySyncItem syncItem = new CreateDirectorySyncItem("test");

            this.target.Add(syncTask, syncItem);

            Assert.AreEqual(syncItem, target[syncTask].CreateDirectorySyncItems.ElementAt(0), "SyncItem does not match.");
            Assert.AreEqual(1, target[syncTask].CreateDirectorySyncItems.Count(), "CreateDirectorySyncItems should contain 1 element.");
            Assert.AreEqual(1, target.SyncTaskPreviewBySyncTask.Count, "SyncTaskPreviewBySyncTask should contain one element.");
        }
Example #21
0
        protected R ExecuteSync <R>(SyncTask <Task <R> > task)
        {
            R result = default(R);

            Task.Run(async() =>
            {
                result = await task();
            }).Wait();

            return(result);
        }
        public void askAndGetRequestsTest()
        {
            SyncTriggerSystem system = createSystem();
            SyncTask          task   = system.request(1, new EventContext("discover")
            {
                { "cards", new int[] { 1, 2, 3 } }
            }, float.MaxValue, null);

            Assert.AreEqual(SyncTaskState.paused, task.state);
            Assert.AreEqual(task, system.getAllRequestTasks()[0]);
        }
Example #23
0
 public void Add(SyncTask item)
 {
     if (item == null)
     {
         return;
     }
     if (string.IsNullOrEmpty(item.ItemName))
     {
         return;
     }
     m_SyncItems[item.ItemName] = item;
 }
Example #24
0
        private bool exitSlowly(ref Task <bool> receipt)
        {
            lock (this.waitingTasks)
            {
                if (!Object.ReferenceEquals(this.lockHeldBy, receipt))
                {
                    SyncTask sTask;
                    try { } finally
                    {
                        if (this.syncTaskLookup.TryGetValue(receipt, out sTask))
                        {
                            this.waitingTasks.RemoveO1(sTask);
                            this.syncTaskLookup.Remove(sTask.ReceiptTask);
                            this.timeoutTasks?.Remove(sTask);
                            sTask.Dispose();
                            receipt = null;
                        }
                    }
                    return(false);
                }

                try
                {
                    SyncTask sTask = null;
                    while (this.waitingTasks.Count > 0)
                    {
                        using (sTask = this.waitingTasks.Dequeue())
                        {
                            this.syncTaskLookup.Remove(sTask.ReceiptTask);
                            this.timeoutTasks?.Remove(sTask);

                            if (sTask.PrepareDequeue())
                            {
                                this.lockHeldBy = sTask.ReceiptTask;
                                receipt         = null;
                                return(true);
                            }
                        }
                    }

                    try { } finally
                    {
                        this.lockHeldBy = null;
                        receipt         = null;
                    }
                    return(true);
                }
                finally
                {
                    this.queueCount = this.waitingTasks.Count;
                }
            }
        }
        private void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            SLExcelData processedData = SyncTasksManager.GetInstance().GetProcessData(SyncTask.ID, SyncTask.ProcessID, IsCompleted);

            if (processedData == null)
            {
                SyncTask syncTask = SyncTasksManager.GetInstance().SyncTasks.Where(t => t.ProcessID == SyncTask.ProcessID).FirstOrDefault();
                if (syncTask != null)
                {
                    List <ProgressItem> progressItems = new List <ProgressItem>();
                    progressItems.Add(new ProgressItem()
                    {
                        Action  = "Synchronization",
                        Message = SyncTask.DestinationListName,
                        Status  = syncTask.Status,
                        Path    = ""
                    });

                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        TasksDataGrid.ItemsSource = null;
                        TasksDataGrid.ItemsSource = progressItems;
                    }));
                }
            }
            else
            {
                try
                {
                    List <ProgressItem> progressItems = new List <ProgressItem>();
                    foreach (List <string> datarow in processedData.DataRows)
                    {
                        progressItems.Add(new ProgressItem()
                        {
                            Action  = datarow[0],
                            Message = datarow[2],
                            Status  = datarow[1],
                            Path    = datarow[4]
                        });
                    }

                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        TasksDataGrid.ItemsSource = null;
                        TasksDataGrid.ItemsSource = progressItems;
                    }));
                }
                catch (Exception ex)
                {
                }
            }
        }
Example #26
0
        private bool GetIsNeedUpdate(SyncTask task)
        {
            if (!task.SyncTimer.IsEnabled)
            {
                return(false);
            }

            switch (task.SyncTimer.Type)
            {
            case SyncTimerType.Once:
                if (task.SyncTimer.StartDate < DateTime.Now)
                {
                    task.SyncTimer.IsEnabled = false;
                    return(true);
                }
                else
                {
                    return(false);
                }

            case SyncTimerType.EveryDay:
                if (task.LastSyncDate == null)
                {
                    return(true);
                }
                if (task.LastSyncDate.Value.Date.Add(TimeSpan.FromDays(1)) < DateTime.Now)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case SyncTimerType.Custom:
                if (task.LastSyncDate == null)
                {
                    return(true);
                }
                if (task.LastSyncDate.Value.Add(task.SyncTimer.Period) < DateTime.Now)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                return(false);
            }
        }
        public void AddTest_AddTwoElement2_SyncTaskPreviewBySyncTaskContainsTwoNestedSyncItem()
        {
            SyncTask syncTask = new SyncTask("Test");
            CreateDirectorySyncItem syncItem1 = new CreateDirectorySyncItem("test1");
            CreateDirectorySyncItem syncItem2 = new CreateDirectorySyncItem("test2");

            this.target.Add(syncTask, syncItem1);
            this.target.Add(syncTask, syncItem2);

            Assert.AreEqual(2, target[syncTask].CreateDirectorySyncItems.Count(), "CreateDirectorySyncItems should contain 2 elements.");
            Assert.AreEqual(1, target.SyncTaskPreviewBySyncTask.Count, "SyncTaskPreviewBySyncTask should contain one element.");
            Assert.AreEqual(2, target.CountOfActiveCreateDirectories, "CountOfActiveCreateDirectories should contain 2 elements.");
        }
Example #28
0
 private static void Enque(SyncTask task)
 {
     lock (lockObject)
     {
         var runner = new QueryRunner()
         {
             Task = task
         };
         //runner.RetryCount = request.RetryCount;
         //runner.OnStateChange += QueryStateChanged;
         QueuedRequests.Add(runner);
     }
 }
Example #29
0
        private void DeleteTaskButton_Click(object sender, RoutedEventArgs e)
        {
            List <SyncTask> synctasks = new List <SyncTask>();

            foreach (object synchTask in TasksDataGrid.SelectedItems)
            {
                SyncTask _synchTask = (SyncTask)synchTask;
                SyncTasksManager.GetInstance().SyncTasks.Remove(_synchTask);
            }

            SyncTasksManager.GetInstance().SaveSyncTasks();
            RefreshButton_Click(null, null);
        }
Example #30
0
 public void stopTask(SyncTask task)
 {
     if (task == null)
     {
         throw new ArgumentNullException();
     }
     _pausedTaskList.Remove(task);
     for (; task != null; task = task.parent)
     {
         task.state = SyncTaskState.finished;
     }
     currentTask = null;
 }
Example #31
0
        public ThreadWorker()
        {
#endif // XBOX
            mTaskQueue = new Queue<ITask>();

            mThreadWaitHandle = new AutoResetEvent(false);
            mSyncWaitHandle = new AutoResetEvent(false);
            mSyncTask = new SyncTask(mSyncWaitHandle);

            // Start the worker thread
            mThread = new Thread(Work);
            mThread.Start();
            mTaskCount = 0;
        }
		private void ExecuteTest(string treeName)
		{
			SyncTask task = new SyncTask();
			DirectoryInfo toDirectory = new DirectoryInfo(_todirectory);
			DirectoryInfo sourceDirectory = new DirectoryInfo(_sourcedirectory);
			XmlDocument doc = new XmlDocument();
			int expected;

			LoadTree(treeName);
			expected = GetDescendantCount(sourceDirectory);
			doc.LoadXml(Properties.Resources.build);
			task.Project = new Project(doc, Level.Info, 0);
			task.ToDirectory = toDirectory;
			task.SourceDirectory = sourceDirectory;
			task.Execute();

			Assert.AreEqual(expected, GetDescendantCount(sourceDirectory));
			Assert.AreEqual(expected, GetDescendantCount(toDirectory));
		}