public void NotifyWorkflowActivationComplete(Guid instanceId, WaitCallback callback, object state, bool fireImmediatelyIfDontExist)
        {
            bool           instanceFound;
            InstanceRecord instanceRecord;

            lock (this.lockObject)
            {
                instanceFound = instanceRecordMap.TryGetValue(instanceId, out instanceRecord);
                if (instanceFound)
                {
                    instanceRecord.Callback      = callback;
                    instanceRecord.CallbackState = state;
                }
                else if (!fireImmediatelyIfDontExist)
                {
                    instanceRecord               = new InstanceRecord();
                    instanceRecord.Callback      = callback;
                    instanceRecord.CallbackState = state;
                    instanceRecordMap.Add(instanceId, instanceRecord);
                }
            }

            if (!instanceFound && fireImmediatelyIfDontExist)
            {
                //Instance is not in-memory; Notify immediately.
                callback(state);
            }
        }
Esempio n. 2
0
        private void SetApplicablePlugins(InstanceRecord record)
        {
            var lst = new List <IPlugin>();

            Action <IEnumerable <IPlugin> > find = source =>
            {
                lst.AddRange(source.Where(p => p.IsApplicable(record)));
            };

            find(m_plugins.CustomInstanceCreators);
            if (lst.Count > 1)
            {
                throw new InvalidOperationException($"Not more than one plugin from CustomInstanceCreators could be applicable to the resource. For {record.InterfaceType.Name} are applicable: {string.Join(", ", lst.Select(pl => pl.GetType().Name))}");
            }

            if (lst.Count == 0)
            {
                find(m_plugins.DefaultInstanceCreators);
            }

            if (lst.Count == 0)
            {
                throw new InvalidOperationException($"No instance creator found for {record.InterfaceType.Name}");
            }

            find(m_plugins.AfterNewInstanceCreated);
            find(m_plugins.LifecyclePlugins);

            record.ApplicablePlugins = lst;
        }
Esempio n. 3
0
#pragma warning restore 8618
        public ReplayMetadata(InstanceRecord rec, bool debug = false)
        {
            Record        = rec;
            Debug         = debug;
            DialogueSpeed = SaveData.s.DialogueWaitMultiplier;
            SmoothInput   = SaveData.s.AllowInputLinearization;
            Locale        = SaveData.s.Locale;
        }
Esempio n. 4
0
        public async Task <InstanceRecord> GetInstanceInfoAsync(string machineId, CancellationToken cancellationToken)
        {
            var responseBody = await EnsureAuthenticatedRequestAsync(async (client) =>
            {
                var response = await client.GetAsync($"machines/{machineId}").ConfigureAwait(false);

                if (!response.IsSuccessStatusCode)
                {
                    throw GetException(response);
                }

                return(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
            }, cancellationToken).ConfigureAwait(false);

            InstanceRecord info = StringSerializer.Deserialize <InstanceRecord>(responseBody);

            return(info);
        }
        void OnWorkflowStarted(object sender, WorkflowEventArgs args)
        {
            if (args == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("args");
            }

            InstanceRecord instanceRecord;

            lock (this.lockObject)
            {
                if (!this.instanceRecordMap.TryGetValue(args.WorkflowInstance.InstanceId, out instanceRecord))
                {
                    instanceRecord = new InstanceRecord();
                    this.instanceRecordMap.Add(args.WorkflowInstance.InstanceId, instanceRecord);
                }
                instanceRecord.InstanceLoadedOrStarted = true;
            }
        }
Esempio n. 6
0
        private INamedReference CreateFactoryMethod(IClassBuilder locator, InstanceRecord record, Dictionary <string, INamedReference> allFactoryFields)
        {
            var ctorParamFactoryFields = new Dictionary <string, INamedReference>();

            if (record.ConstructorParameters != null)
            {
                foreach (var ctorParam in record.ConstructorParameters)
                {
                    if (ctorParam.ValueProvider != null)
                    {
                        ctorParamFactoryFields[ctorParam.ParameterName] = allFactoryFields[ctorParam.ValueProvider.Name];
                    }
                }
            }

            INamedReference valueFactoryField = null;

            if (record.Factory != null)
            {
                valueFactoryField = allFactoryFields[record.Factory.Name];
            }


            INamedReference lastFactoryMethod = null;

            foreach (var plugin in record.ApplicablePlugins)
            {
                lastFactoryMethod = plugin.GenerateFactoryMethod(
                    record,
                    ctorParamFactoryFields,
                    valueFactoryField,
                    locator,
                    lastFactoryMethod);
            }

            if (lastFactoryMethod == null)
            {
                throw new InvalidOperationException($"Not any plugin was able to implement factory for {record.InterfaceType}");
            }

            return(lastFactoryMethod);
        }
Esempio n. 7
0
        private ConstructorInfo ChooseConstructor(InstanceRecord record)
        {
            var ctors = record.ImplementingType.GetConstructors();

            if (ctors.Length == 1)
            {
                return(ctors[0]);
            }

            var ptype = record.ConstructorParameters.Select(p => p.ParameterType).ToArray();

            var typedCtor = record.ImplementingType.GetConstructor(ptype);

            if (typedCtor != null)
            {
                return(typedCtor);
            }

            throw new InvalidOperationException($"Cannot choose the constructor of {record.ImplementingType}");
        }
Esempio n. 8
0
        public void LoadArrays(TTFReader r)
        {
            r.SetPosition(this.axesArrayOffset);

            this.axes      = new List <VariationAxisRecord>(); // The variation axis array.
            this.instances = new List <InstanceRecord>();      // The named instance array.

            for (int i = 0; i < this.axisCount; ++i)
            {
                VariationAxisRecord v = new VariationAxisRecord();
                v.Read(r);
                this.axes.Add(v);
            }

            for (int i = 0; i < this.instanceCount; ++i)
            {
                InstanceRecord ir = new InstanceRecord();
                ir.Read(r, this.axisCount);
                this.instances.Add(ir);
            }
        }
Esempio n. 9
0
        private void ResolveConstructor(InstanceRecord record)
        {
            if (record.ImplementingType == null)
            {
                return;
            }

            var ctor = ChooseConstructor(record);

            var paramsToResolve = ctor.GetParameters().ToList();
            var setupsStack     = record.ConstructorParameters?.ToList() ?? new List <CtorParamSetupRecord>(0);

            var alignedParams = new List <CtorParamSetupRecord>();

            while (paramsToResolve.Any())
            {
                var toResolve = paramsToResolve[0];
                paramsToResolve.RemoveAt(0);

                var paramDefinition = (setupsStack.FirstOrDefault(p => p.ParameterName == toResolve.Name)
                                       ?? setupsStack.FirstOrDefault(p => (p.ParameterType == toResolve.ParameterType) && string.IsNullOrWhiteSpace(p.ParameterName))
                                       ?? setupsStack.FirstOrDefault(p => toResolve.ParameterType.IsAssignableFrom(p.ParameterType) && string.IsNullOrWhiteSpace(p.ParameterName)))
                                      ?? new CtorParamSetupRecord();

                paramDefinition.ParameterName = toResolve.Name;
                paramDefinition.ParameterType = toResolve.ParameterType;
                paramDefinition.ValueProvider = paramDefinition.ValueProvider;
                alignedParams.Add(paramDefinition);
                setupsStack.Remove(paramDefinition);
            }

            if (setupsStack.Any())
            {
                var firstFail = setupsStack[0];
                throw new InvalidOperationException($"Cannot resolve constructor parameter. Construcotr owner = {record.ImplementingType}, invalid param = {firstFail.ParameterName} {firstFail.ParameterType}");
            }

            record.ConstructorParameters = alignedParams;
            record.PreferredConstructor  = ctor;
        }
Esempio n. 10
0
 public void RecordGame(InstanceRecord rec)
 {
     FinishedGames[rec.Uuid] = rec;
     SaveData.SaveRecord();
 }
Esempio n. 11
0
 public void Read(InstanceRecord instRec)
 {
     this.Verify(instRec);
 }
Esempio n. 12
0
 public Replay(FrameInput[] frames, InstanceRecord rec, bool debug = false) :
     this(() => frames, new ReplayMetadata(rec, debug))
 {
     metadata.Length = frames.Length;
 }
Esempio n. 13
0
        public static UIScreen HighScoreScreen(UIScreen replayScreen,
                                               SMAnalysis.AnalyzedCampaign[] campaigns, SMAnalysis.AnalyzedDayCampaign?days = null)
        {
            if (campaigns.Length == 0)
            {
                return(new UIScreen(new UINode(scores_nocampaign)));
            }
            var replays  = new Dictionary <string, int>();
            var key      = new InstanceRecord().RequestKey;
            var cmpIndex = 0;

            void AssignCampaign(int cmpInd)
            {
                cmpIndex     = cmpInd;
                key.campaign = key.boss.Item1.campaign = key.challenge.Item1.Item1.Item1.campaign =
                    key.stage.Item1.campaign = campaigns[cmpIndex].Key;
                AssignStage(0);
                if (campaigns[cmpIndex].bosses.Length > 0)
                {
                    AssignBoss(campaigns[cmpIndex].bosses[0].boss.key);
                }
                else
                {
                    throw new Exception("No high score handling for days menu implemented yet"); //AssignBoss(days!.bosses[]);
                }
            }

            void AssignBoss(string boss)
            {
                key.boss.Item1.boss = key.challenge.Item1.Item1.boss = boss;
                AssignBossPhase(0);
            }

            void AssignStage(int stage)
            {
                //Better not to mix with AssignBoss to avoid invalid assignments.
                key.stage.Item1.stage = stage;
                AssignStagePhase(0);
            }

            void AssignBossPhase(int phase)
            {
                key.boss.phase = key.challenge.Item1.phase = phase;
            }

            void AssignStagePhase(int phase)
            {
                key.stage.phase = phase;
            }

            key.stage.phase = 1; //only show full-stage practice
            AssignCampaign(0);
            key.type = 0;
            SaveData.p.ReplayData.ForEachI((i, r) => replays[r.metadata.RecordUuid] = i);
            var scoreNodes = SaveData.r.FinishedGames.Values
                             //If the user doesn't enter a name on the replay screen, the score won't show up, but it will still be recorded internally
                             .Where(g => !string.IsNullOrWhiteSpace(g.CustomNameOrPartial) && g.Score > 0)
                             .OrderByDescending(g => g.Score).Select(g => {
                //Don't need to show the request (eg. Yukari (Ex) p3) because it's shown by the option nodes above this
                var node = new UINode(g.AsDisplay(true, false));
                if (replays.TryGetValue(g.Uuid, out var i))
                {
                    node.SetConfirmOverride(() => (true, replayScreen.top[i]));
                }
                return(node.With(monospaceClass).With(small2Class)
                       .With(CheckmarkClass(replays.ContainsKey(g.Uuid)))
                       .VisibleIf(() => DUHelpers.Tuple4Eq(key, g.RequestKey)));
            });
            var optnodes = new UINode[] {
                new OptionNodeLR <short>(practice_type, i => key.type = i, new (LocalizedString, short)?[] {
Esempio n. 14
0
 public void Read(InstanceRecord instRec)
 {
     Console.WriteLine("Instance " + instRec.SequenceNo + " of " + instRec.Ref.Name);
 }
Esempio n. 15
0
 public void Read(InstanceRecord instRec)
 {
     throw new InvalidOperationException();
 }
Esempio n. 16
0
        //
        protected override void ReadContentFrom(BinaryReader reader)
        {
            //Font variations header:

            //Type      Name            Description
            //uint16    majorVersion    Major version number of the font variations table — set to 1.
            //uint16    minorVersion    Minor version number of the font variations table — set to 0.
            //Offset16  axesArrayOffset Offset in bytes from the beginning of the table to the start of the VariationAxisRecord array.
            //uint16    (reserved)      This field is permanently reserved.Set to 2.
            //uint16    axisCount       The number of variation axes in the font (the number of records in the axes array).
            //uint16    axisSize        The size in bytes of each VariationAxisRecord — set to 20 (0x0014) for this version.
            //uint16    instanceCount   The number of named instances defined in the font (the number of records in the instances array).
            //uint16    instanceSize    The size in bytes of each InstanceRecord — set to either axisCount * sizeof(Fixed) + 4,
            //                          or to axisCount * sizeof(Fixed) + 6.


            long beginAt = reader.BaseStream.Position;
            //header:
            ushort majorVersion    = reader.ReadUInt16();
            ushort minorVersion    = reader.ReadUInt16();
            ushort axesArrayOffset = reader.ReadUInt16();
            ushort reserved        = reader.ReadUInt16();//set to 2
            ushort axisCount       = reader.ReadUInt16();
            ushort axisSize        = reader.ReadUInt16();
            ushort instanceCount   = reader.ReadUInt16();
            ushort instanceSize    = reader.ReadUInt16();


            //The header is followed by axes and instances arrays.
            //The location of the axes array is specified in the axesArrayOffset field;
            //the instances array directly follows the axes array.
            //Type                 Name                         Description
            //VariationAxisRecord  axes[axisCount]              The variation axis array.
            //InstanceRecord       instances[instanceCount]     The named instance array.

            //Note: The axisSize and instanceSize fields indicate
            //the size of the VariationAxisRecord and InstanceRecord structures.

            //In this version of the 'fvar' table, the InstanceRecord structure has an optional field,
            //and so two different size formulations are possible.

            //Future minor-version updates of the 'fvar' table may define compatible extensions to either formats.

            //***Implementations must use the axisSize and instanceSize fields to determine the start of each record.***

            //The set of axes that make up the font’s variation space are defined by an array of variation axis records.
            //The number of records, and the number of axes, is determined by the axisCount field.
            //A functional variable font must have an axisCount value that is greater than zero.

            //If axisCount is zero, then the font is not functional as a variable font, ***
            //and must be treated as a non-variable font; ***
            //any variation-specific tables or data is ignored.

            variableAxisRecords = new VariableAxisRecord[axisCount];

            for (int i = 0; i < axisCount; ++i)
            {
                long pos = reader.BaseStream.Position;
                VariableAxisRecord varAxisRecord = new VariableAxisRecord();
                varAxisRecord.ReadContent(reader);
                variableAxisRecords[i] = varAxisRecord;
                if (reader.BaseStream.Position != pos + axisSize)
                {
                    //***Implementations must use the axisSize and instanceSize fields to determine the start of each record.***
                    reader.BaseStream.Position = pos + axisSize;
                }
            }

            instanceRecords = new InstanceRecord[instanceCount];

            for (int i = 0; i < instanceCount; ++i)
            {
                long pos = reader.BaseStream.Position;

                InstanceRecord instanecRec = new InstanceRecord();
                instanecRec.ReadContent(reader, axisCount, instanceSize);

                if (reader.BaseStream.Position != pos + instanceSize)
                {
                    //***Implementations must use the axisSize and instanceSize fields to determine the start of each record.***
                    reader.BaseStream.Position = pos + instanceSize;
                }
            }
        }
Esempio n. 17
0
 public void Verify(InstanceRecord instRec)
 {
     Verify(RecordType.Instance, instRec.SequenceNo);
     Assert.AreEqual(sRefSeqNos.Dequeue(), instRec.Ref.SequenceNo);
 }