//private: ListViewItem CreateItem(IUpdateAction action) { switch (action.Code) { case ActionCode_t.ResetTable: return(new ListViewItem(m_actionsName[ActionCode_t.ResetTable])); case ActionCode_t.DeleteRow: { var delRow = action as DeleteRow; return(new ListViewItem(new[] { m_actionsName[ActionCode_t.DeleteRow], delRow.RowID.ToString() })); } case ActionCode_t.ReplaceRow: { var repRow = action as ReplaceRow; return(new ListViewItem(new[] { m_actionsName[ActionCode_t.ReplaceRow], repRow.RowID.ToString() })); } case ActionCode_t.AddRow: { var addRow = action as AddRow; return(new ListViewItem(new[] { m_actionsName[ActionCode_t.AddRow], addRow.Datum.ID.ToString() })); } default: Assert(false); break; } return(null); }
/// <summary> /// Updates the state of the game with the current action. /// </summary> /// <param name="action">The action to be played by the current player</param> /// <exception cref="ArgumentException"> /// If the move is invalid. The action's validity should be verified upstream. /// </exception> public void Update(IUpdateAction action) { lock (_syncLock) { if (action.IsValidOn(State)) { Memento = Memento.Update(action); _breadCrumbs.Clear(); } else { throw new ArgumentException("Invalid move: " + action); } } }
public static void Using <TEvent, TKey, TProjection, TContext>( this IUpdateAction <TEvent, TKey, TProjection, TContext> action, Func <TProjection, TEvent, Task> projector) { if (action == null) { throw new ArgumentNullException(nameof(action)); } if (projector == null) { throw new ArgumentNullException(nameof(projector)); } action.Using((projection, anEvent, context) => projector(projection, anEvent)); }
/// Updates the creation statistics of moves private static IUpdateAction UpdateStatisticsAndPass(this IUpdateAction action) { switch (action) { case MoveBallAction moveBallAction: MoveBalls++; break; case MovePieceAction movePieceAction: MovePieces++; break; case PassAction passAction: Passes++; break; } return(action); }
public static void Using <TEvent, TKey, TProjection, TContext>( this IUpdateAction <TEvent, TKey, TProjection, TContext> action, Action <TProjection, TEvent> projector) { if (action == null) { throw new ArgumentNullException(nameof(action)); } if (projector == null) { throw new ArgumentNullException(nameof(projector)); } action.Using((projection, anEvent, context) => { projector(projection, anEvent); return(TaskConstants.FalseTask); }); }
//private; static void ApplyAction(IUpdateAction action, DBKeyIndexer ndxer) { switch (action.Code) { case ActionCode_t.DeleteRow: var delAct = action as DeleteRow; ndxer.Source.Delete(ndxer.IndexOf(delAct.RowID)); break; case ActionCode_t.ReplaceRow: var replaceAct = action as ReplaceRow; ndxer.Source.Replace(ndxer.IndexOf(replaceAct.RowID), replaceAct.Datum); break; case ActionCode_t.AddRow: var addAct = action as AddRow; ndxer.Source.Insert(addAct.Datum); break; default: Assert(false); break; } }
/// <summary> /// Gets a new memento based on this one. /// </summary> /// <param name="action">The transition from this memento to the result</param> /// <returns>A new memento with this as its parent</returns> public MementoNode Update(IUpdateAction action) { return(new MementoNode(this, action)); }
public MementoNode(GameMemento previous, IUpdateAction action) : base(previous) { Action = action; }
public ActionInfo(IUpdateAction action, int szDatum) { Action = action; DatumSize = szDatum; }
public void Add(IUpdateAction item) => Items.Add(item);
private static void Main() { //Debugger.Launch(); try { // Get the update process name, to be used to create a named pipe and to wait on the application // to quit string[] args = Environment.GetCommandLineArgs(); string syncProcessName = args[1]; if (string.IsNullOrEmpty(syncProcessName)) { Application.Exit(); } // Connect to the named pipe and retrieve the updates list var PIPE_NAME = string.Format("\\\\.\\pipe\\{0}", syncProcessName); var o = GetUpdates(PIPE_NAME); // Make sure we start updating only once the application has completely terminated bool createdNew; using (var mutex = new Mutex(false, syncProcessName, out createdNew)) { try { if (!createdNew) { mutex.WaitOne(); } } catch (AbandonedMutexException) { // An abandoned mutex is exactly what we are expecting... } } string appPath, appDir, tempFolder, backupFolder; bool relaunchApp = true, updateSuccessful = true; { Dictionary <string, object> dict = null; if (o is Dictionary <string, object> ) { dict = o as Dictionary <string, object>; } if (dict == null || dict.Count == 0) { Application.Exit(); return; } // Get some required environment variables appPath = dict["ENV:AppPath"].ToString(); appDir = dict["ENV:WorkingDirectory"] as string ?? Path.GetDirectoryName(appPath); tempFolder = dict["ENV:TempFolder"].ToString(); backupFolder = dict["ENV:BackupFolder"].ToString(); relaunchApp = dict["ENV:RelaunchApplication"] as bool? ?? true; // Perform the actual off-line update process var en = dict.GetEnumerator(); while (en.MoveNext()) { if (en.Current.Key.StartsWith("ENV:")) { continue; } else { IUpdateAction a = null; if (en.Current.Value is string) { a = new FileCopyAction(en.Current.Value.ToString(), Path.Combine(appDir, en.Current.Key)); } else if (en.Current.Value is byte[]) { a = new FileDumpAction(Path.Combine(appDir, en.Current.Key), (byte[])en.Current.Value); } if (a != null) { try { if (!a.Do()) { updateSuccessful = false; break; } } catch (Exception e) { MessageBox.Show("Update failed: " + e.Message); updateSuccessful = false; break; } } } } } if (updateSuccessful) { if (Directory.Exists(backupFolder)) { Directory.Delete(backupFolder, true); } } else { MessageBox.Show("Update Failed."); } // Start the application only if requested to do so if (relaunchApp) { try { Process.Start(new ProcessStartInfo { UseShellExecute = true, WorkingDirectory = appDir, FileName = appPath, }); } catch (Win32Exception e) { MessageBox.Show(e.ToString()); } } //MessageBox.Show(string.Format("Re-launched process {0} with working dir {1}", appPath, appDir)); // Delete the updater EXE and the temp folder) try { var Info = new ProcessStartInfo(); //Application.ExecutablePath Info.Arguments = string.Format(@"/C ping 1.1.1.1 -n 1 -w 3000 > Nul & echo Y|del ""{0}\*.*"" & rmdir ""{0}""" , tempFolder); Info.WindowStyle = ProcessWindowStyle.Hidden; Info.CreateNoWindow = true; Info.FileName = "cmd.exe"; Process.Start(Info); } catch { /* ignore exceptions thrown while trying to clean up */ } Application.Exit(); } catch { //supressing catch because if at any point we get an error the update has failed } finally { Application.Exit(); } }