private void Analyze(IEnumerable <JObject> jObjects)
        {
            JObject masterObject = null;
            var     settings     = new JsonMergeSettings
            {
                MergeNullValueHandling = MergeNullValueHandling.Ignore,
                MergeArrayHandling     = MergeArrayHandling.Union
            };

            foreach (JObject jObject in jObjects)
            {
                if (masterObject == null)
                {
                    masterObject = jObject;
                }
                else
                {
                    masterObject.Merge(jObject, settings);
                }
            }

            Analyze(masterObject);
        }
        public static JObject Unflatten(
            IDictionary <string, object> keyValues)
        {
            JContainer result  = null;
            var        setting = new JsonMergeSettings();

            setting.MergeArrayHandling = MergeArrayHandling.Merge;

            foreach (var pathValue in keyValues)
            {
                if (result == null)
                {
                    result = UnflatenSingle(pathValue);
                }
                else
                {
                    var node = UnflatenSingle(pathValue);
                    result.Merge(node, setting);
                }
            }

            return(result as JObject);
        }
        /// <summary>
        /// Tries to load custom settings and if one is find, tries to merge them to the given default settings.
        /// </summary>
        /// <param name="defaultSettings">The default settings with which to merge the ones.</param>
        /// <returns>The result settings after merge.</returns>
        private static TestEnvironmentSettings TryLoadAndMergeWithCustomSettings(TestEnvironmentSettings defaultSettings)
        {
            string customTestSettingsFileLocation = System.Environment.GetEnvironmentVariable(EnvVariableForCustomSettingLocation, EnvironmentVariableTarget.User) ?? FallBackCustomTestSettingsFileLocation;

            var codeBaseUrl   = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            var codeBasePath  = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);
            var dirPath       = Path.GetDirectoryName(codeBasePath);
            var customFileLoc = Path.Combine(dirPath, customTestSettingsFileLocation);

            var finalSettings = JObject.FromObject(defaultSettings);

            if (File.Exists(customFileLoc))
            {
                //TODO: Print that parsing custom values...
                var mergeSettings = new JsonMergeSettings {
                    MergeArrayHandling = MergeArrayHandling.Union
                };
                var customSettingsJson = JObject.Parse(File.ReadAllText(customFileLoc));
                customSettingsJson.Merge(finalSettings, mergeSettings);
                finalSettings = customSettingsJson;
            }

            return(finalSettings.ToObject <TestEnvironmentSettings>());
        }
Example #4
0
        public static void MergeHsanFiles(string srcPath, string songPackName, string destPath)
        {
            //Load hsan manifest
            var hsanFiles = Directory.EnumerateFiles(srcPath, "*.hsan", SearchOption.AllDirectories).ToArray();

            if (hsanFiles.Length < 1)
            {
                throw new DataException("No songs_*.hsan file found.");
            }

            // merge multiple hsan files into a single hsan file
            if (hsanFiles.Length > 1)
            {
                var mergeSettings = new JsonMergeSettings {
                    MergeArrayHandling = MergeArrayHandling.Union
                };
                JObject hsanObject1 = new JObject();

                foreach (var hsan in hsanFiles)
                {
                    JObject hsanObject2 = JObject.Parse(File.ReadAllText(hsan));
                    hsanObject1.Merge(hsanObject2, mergeSettings);
                }

                var    hsanFileName = String.Format("songs_dlc_{0}.hsan", songPackName.ToLower());
                var    hsanPath     = Path.Combine(destPath, hsanFileName);
                string json         = JsonConvert.SerializeObject(hsanObject1, Formatting.Indented);
                File.WriteAllText(hsanPath, json);

                // delete old hsan files
                foreach (var hsan in hsanFiles)
                {
                    File.Delete(hsan);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Post the custom tracking events to the OMS using Integration Account Tracking API
        /// </summary>
        /// <param name="eventSource">The event source</param>
        /// <param name="correlationId">The correlation client tracking ID</param>
        /// <param name="eventLevel">The event severity level</param>
        /// <param name="eventDateTime">The event date time</param>
        /// <param name="customSourceInformation">The custom event source information</param>
        /// <param name="customEventTrackingProperties">The custom tracking event properties to be posted to OMS</param>
        public void PostCustomTrackingEvents(string eventSource, string correlationId, string eventLevel, string eventDateTime, IDictionary <string, object> customSourceInformation, IDictionary <string, object> customEventTrackingProperties)
        {
            var apiUrl = $"https://management.azure.com/subscriptions/{this.SubscriptionId}/resourceGroups/{this.ResourceGroupName}/providers/Microsoft.Logic/integrationAccounts/{this.IntegrationAccountName}/logTrackingEvents?api-version={this.ApiVersion}";

            // Initialize the default JSON merge settings
            var defaultJsonMergeSettings = new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            };

            // Initialize the JSON payload
            var contentJObject = new JObject
            {
                { IntegrationAccountTrackingApiConstants.SourceType, IntegrationAccountTrackingApiConstants.Custom }
            };

            // Populate the source details
            var sourceJObject = new JObject
            {
                { IntegrationAccountTrackingApiConstants.EventSourceName, eventSource }
            };

            // Add run instance information to it
            var runInstanceJObject = new JProperty(IntegrationAccountTrackingApiConstants.RunInstance, new JObject(new JProperty(IntegrationAccountTrackingApiConstants.OmsCorrelationTrackingId, correlationId)));

            sourceJObject.Add(runInstanceJObject);

            // Add custom source properties to it
            var customSourceJObject = JObject.FromObject(customSourceInformation);

            sourceJObject.Merge(customSourceJObject, defaultJsonMergeSettings);

            // Add the source details to the JSON payload
            contentJObject.Add(new JProperty(IntegrationAccountTrackingApiConstants.Source, sourceJObject));

            // Populate the event details
            var eventJObject = new JObject()
            {
                { IntegrationAccountTrackingApiConstants.EventLevel, eventLevel },
                { IntegrationAccountTrackingApiConstants.EventTime, eventDateTime },
                { IntegrationAccountTrackingApiConstants.RecordType, IntegrationAccountTrackingApiConstants.Custom }
            };

            // Add custom event properties
            var customEventJObject = JObject.FromObject(customEventTrackingProperties);

            eventJObject.Add(new JProperty(IntegrationAccountTrackingApiConstants.Record, customEventJObject));

            // Add the event details to the JSON payload
            contentJObject.Add(
                new JProperty(
                    IntegrationAccountTrackingApiConstants.Events,
                    new JArray()
            {
                eventJObject
            }));

            var jsonPayload = contentJObject.ToString();

            using (var client = new WebClient())
            {
                // Get the bearer token
                var azureAdBearerToken = this.GetAzureActiveDirectoryAuthorizationToken();

                // Configure the headers
                client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                client.Headers.Add("Authorization", "Bearer " + azureAdBearerToken);

                // Upload the JSON payload
                client.UploadString(new Uri(apiUrl), "POST", jsonPayload);
            }
        }
        protected virtual async Task <DownstreamResponse> MapAbpApiDefinitionAggregateContentAsync(List <DownstreamContext> downstreamContexts)
        {
            var               responseKeys   = downstreamContexts.Select(s => s.DownstreamReRoute.Key).Distinct().ToList();
            JObject           responseObject = null;
            JsonMergeSettings mergeSetting   = new JsonMergeSettings();

            mergeSetting.MergeArrayHandling     = MergeArrayHandling.Union;
            mergeSetting.PropertyNameComparison = System.StringComparison.CurrentCultureIgnoreCase;
            for (var k = 0; k < responseKeys.Count; k++)
            {
                var contexts = downstreamContexts.Where(w => w.DownstreamReRoute.Key == responseKeys[k]).ToList();
                if (contexts.Count == 1)
                {
                    if (contexts[0].IsError)
                    {
                        return(contexts[0].DownstreamResponse);
                    }

                    var content       = await contexts[0].DownstreamResponse.Content.ReadAsStringAsync();
                    var contentObject = JsonConvert.DeserializeObject(content);
                    if (responseObject == null)
                    {
                        responseObject = JObject.FromObject(contentObject);
                    }
                    else
                    {
                        responseObject.Merge(contentObject, mergeSetting);
                    }
                }
                else
                {
                    for (var i = 0; i < contexts.Count; i++)
                    {
                        if (contexts[i].IsError)
                        {
                            return(contexts[i].DownstreamResponse);
                        }

                        var content       = await contexts[i].DownstreamResponse.Content.ReadAsStringAsync();
                        var contentObject = JsonConvert.DeserializeObject(content);
                        if (responseObject == null)
                        {
                            responseObject = JObject.FromObject(contentObject);
                        }
                        else
                        {
                            responseObject.Merge(contentObject, mergeSetting);
                        }
                    }
                }
            }

            var stringContent = new StringContent(responseObject.ToString())
            {
                Headers = { ContentType = new MediaTypeHeaderValue("application/json") }
            };

            stringContent.Headers.Add("_abperrorformat", "true");
            return(new DownstreamResponse(stringContent, HttpStatusCode.OK,
                                          new List <KeyValuePair <string, IEnumerable <string> > >(), "OK"));
        }
Example #7
0
        public void MergeRows <T>(DocumentStorage storage, List <T> rows, DocumentMap map, Formatting formatting = Formatting.None)
        {
            try
            {
                using (FileStream fsTemp = new FileStream(storage.Tempory, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write, BufferSize))
                    using (StreamWriter sw = new StreamWriter(fsTemp, Encoding.UTF8, BufferSize))
                        using (JsonTextWriter writer = new JsonTextWriter(sw))
                        {
                            var match = 0;
                            var count = rows.Count;

                            var settings = new JsonMergeSettings();
                            settings.MergeArrayHandling     = MergeArrayHandling.Replace;
                            settings.PropertyNameComparison = StringComparison.OrdinalIgnoreCase;
                            settings.MergeNullValueHandling = MergeNullValueHandling.Merge;

                            writer.Formatting = formatting;
                            writer.WriteStartArray();

                            using (FileStream fsTarget = new FileStream(storage.Target, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize))
                                using (StreamReader sr = new StreamReader(fsTarget, Encoding.UTF8, false, BufferSize))
                                    using (JsonReader reader = new JsonTextReader(sr))
                                    {
                                        while (reader.Read())
                                        {
                                            if (reader.TokenType == JsonToken.StartObject)
                                            {
                                                JObject readRow = JObject.Load(reader);

                                                if (match < count)
                                                {
                                                    var readId = readRow[map.Target].ToString();

                                                    foreach (T row in rows)
                                                    {
                                                        JObject rowObject = JObject.FromObject(row);
                                                        var     id        = rowObject[map.Source].ToString();

                                                        if (readId == id)
                                                        {
                                                            readRow.Merge(rowObject, settings);
                                                            match++;
                                                            break;
                                                        }
                                                    }
                                                }

                                                readRow.WriteTo(writer);
                                            }
                                        }
                                    }

                            writer.WriteEndArray();
                            writer.Flush();
                        }
            }
            catch (Exception ex)
            {
                Logger?.Fatal(ex);

                throw ex;
            }
        }
        /// <summary>
        /// Sends a message to the websocket API with the specified request type and optional parameters
        /// </summary>
        /// <param name="requestType">obs-websocket request type, must be one specified in the protocol specification</param>
        /// <param name="additionalFields">additional JSON fields if required by the request type</param>
        /// <returns>The server's JSON response as a JObject</returns>
        public async Task <JObject> SendRequest(string requestType, JObject additionalFields = null)
        {
            ////WSConnection.OnClose -= (s, e) => Disconnected?.Invoke(this, e);

            ////WSConnection.Close();
            ////while (WSConnection.ReadyState != WebSocketState.Closed) { }

            ////WSConnection.Connect();
            ////while (WSConnection.ReadyState != WebSocketState.Open) { }

            ////WSConnection.OnClose += (s, e) => Disconnected?.Invoke(this, e);

            string messageID;

            // Build the bare-minimum body for a request
            var body = new JObject
            {
                { "request-type", requestType }
            };

            // Add optional fields if provided
            if (additionalFields != null)
            {
                _ = new JsonMergeSettings
                {
                    MergeArrayHandling = MergeArrayHandling.Union
                };

                body.Merge(additionalFields);
            }

            // Prepare the asynchronous response handler
            var tcs = new TaskCompletionSource <JObject>(TaskContinuationOptions.RunContinuationsAsynchronously);

            do
            {
                // Generate a random message id
                messageID = NewMessageID();
                if (responseHandlers.TryAdd(messageID, tcs))
                {
                    body.Add("message-id", messageID);
                    break;
                }
                // Message id already exists, retry with a new one.
            } while (true);
            // Send the message and wait for a response
            // (received and notified by the websocket response handler)

            Console.WriteLine($"connection state is {WSConnection.ReadyState}");

            WSConnection.Send(body.ToString());

            try
            {
                tcs.Task.Wait();

                if (tcs.Task.IsCanceled)
                {
                    throw new ErrorResponseException("Request canceled");
                }

                var result = tcs.Task.Result;

                // Throw an exception if the server returned an error.
                // An error occurs if authentication fails or one if the request body is invalid.
                if ((string)result["status"] == "error")
                {
                    throw new ErrorResponseException((string)result["error"]);
                }

                return(await Task.FromResult(result));
            }
            catch (Exception ex)
            {
                var exp = ex;
                throw;
            }
        }
Example #9
0
        // Load RS1 CDLC into PackageCreator
        public static DLCPackageData RS1LoadFromFolder(string unpackedDir, Platform targetPlatform, bool convert)
        {
            var data = new DLCPackageData();

            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();
            data.Tones        = new List <Tone>();

            data.GameVersion   = (convert ? GameVersion.RS2014 : GameVersion.RS2012);
            data.SignatureType = PackageMagic.CON;
            // set default volumes
            data.Volume        = (float)-5.5; // - 7 default a little too quite
            data.PreviewVolume = data.Volume;

            //Load song manifest
            var songsManifestJson = Directory.GetFiles(unpackedDir, "songs.manifest.json", SearchOption.AllDirectories);

            if (songsManifestJson.Length < 1)
            {
                throw new DataException("No songs.manifest.json file found.");
            }
            if (songsManifestJson.Length > 1)
            {
                throw new DataException("More than one songs.manifest.json file found.");
            }

            List <Attributes> attr = new List <Attributes>();
            var songsManifest      = Manifest.Manifest.LoadFromFile(songsManifestJson[0]).Entries.ToArray();

            for (int smIndex = 0; smIndex < songsManifest.Count(); smIndex++)
            {
                var smData = songsManifest[smIndex].Value.ToArray()[0].Value;
                attr.Add(smData);
            }

            if (attr.FirstOrDefault() == null)
            {
                throw new DataException("songs.manifest.json file did not parse correctly.");
            }

            // Fill SongInfo
            data.SongInfo = new SongInfo();
            data.SongInfo.SongDisplayName     = attr.FirstOrDefault().SongName;
            data.SongInfo.SongDisplayNameSort = attr.FirstOrDefault().SongNameSort;
            data.SongInfo.Album      = attr.FirstOrDefault().AlbumName;
            data.SongInfo.SongYear   = (attr.FirstOrDefault().SongYear == 0 ? 2012 : attr.FirstOrDefault().SongYear);
            data.SongInfo.Artist     = attr.FirstOrDefault().ArtistName;
            data.SongInfo.ArtistSort = attr.FirstOrDefault().ArtistNameSort;
            data.Name = attr.FirstOrDefault().SongKey;

            //Load tone manifest, even poorly formed tone_bass.manifest.json
            var toneManifestJson = Directory.GetFiles(unpackedDir, "*tone*.manifest.json", SearchOption.AllDirectories);

            if (toneManifestJson.Length < 1)
            {
                throw new DataException("No tone.manifest.json file found.");
            }

            // toolkit produces multiple tone.manifest.json files when packing RS1 CDLC files
            // rather than change toolkit behavior just merge manifest files for now
            if (toneManifestJson.Length > 1)
            {
                var mergeSettings = new JsonMergeSettings {
                    MergeArrayHandling = MergeArrayHandling.Union
                };
                JObject toneObject1 = new JObject();

                foreach (var tone in toneManifestJson)
                {
                    JObject toneObject2 = JObject.Parse(File.ReadAllText(tone));
                    //(toneObject1.SelectToken("Entries") as JArray).Merge(toneObject2.SelectToken("Entries"));
                    toneObject1.Merge(toneObject2, mergeSettings);
                }

                toneManifestJson    = new string[1];
                toneManifestJson[0] = Path.Combine(unpackedDir, "merged.tone.manifest");
                string json = JsonConvert.SerializeObject(toneObject1, Formatting.Indented);
                File.WriteAllText(toneManifestJson[0], json);
            }

            List <Tone> tones        = new List <Tone>();
            var         toneManifest = Manifest.Tone.Manifest.LoadFromFile(toneManifestJson[0]);

            for (int tmIndex = 0; tmIndex < toneManifest.Entries.Count(); tmIndex++)
            {
                var tmData = toneManifest.Entries[tmIndex];
                tones.Add(tmData);
            }

            data.Tones = tones;

            // Load xml arrangements
            var xmlFiles = Directory.GetFiles(unpackedDir, "*.xml", SearchOption.AllDirectories);

            if (xmlFiles.Length <= 0)
            {
                throw new DataException("Can not find any XML arrangement files");
            }

            List <Tone2014> tones2014 = new List <Tone2014>();

            foreach (var xmlFile in xmlFiles)
            {
                if (xmlFile.ToLower().Contains("metadata")) // skip DF file
                {
                    continue;
                }

                // some poorly formed RS1 CDLC use just "vocal"
                if (xmlFile.ToLower().Contains("vocal"))
                {
                    var voc = new Arrangement();
                    voc.Name            = ArrangementName.Vocals;
                    voc.ArrangementType = ArrangementType.Vocal;
                    voc.ScrollSpeed     = 20;
                    voc.SongXml         = new SongXML {
                        File = xmlFile
                    };
                    voc.SongFile = new SongFile {
                        File = ""
                    };
                    voc.CustomFont = false;

                    // Add Vocal Arrangement
                    data.Arrangements.Add(voc);
                }
                else
                {
                    Attributes2014 attr2014 = new Attributes2014();
                    Song           rsSong   = new Song();
                    bool           foundToneForArrangement = false;

                    using (var obj1 = new Rs1Converter())
                    {
                        rsSong = obj1.XmlToSong(xmlFile);
                        data.SongInfo.AverageTempo = (int)obj1.AverageBPM(rsSong);
                    }

                    // matchup rsSong, songs.manifest, and tone.manifest files
                    foreach (var arrangement in attr)
                    {
                        // apply best guesstimate matching, RS1 CDLC are very inconsistent
                        // TODO: improve accuracy possibly by matching .xblock data
                        string xmlArr = rsSong.Arrangement.ToLowerInvariant();
                        // var matchLead = Regex.Match(xmlArr.ToLower(), "^lead$", RegexOptions.IgnoreCase);
                        // if(matchLead.Success)

                        if (xmlArr.ToLower().Contains("guitar") && !xmlArr.ToLower().Equals("lead") && !xmlArr.ToLower().Equals("rhythm") && !xmlArr.ToLower().Equals("combo") && !xmlArr.ToLower().Equals("bass"))
                        {
                            if (xmlArr.ToUpper().Equals("PART REAL_GUITAR_22")) //
                            {
                                if (arrangement.ArrangementName.ToLower().Contains("combo"))
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Rhythm";
                                }
                                else
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Lead";
                                }
                            }
                            else
                            {
                                if (arrangement.ArrangementName.ToLower().Contains("combo"))
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Rhythm";
                                }
                                else
                                {
                                    rsSong.Arrangement = arrangement.ArrangementName = "Lead";
                                }
                            }
                        }

                        if (xmlArr.ToLower().Contains("lead") && arrangement.ArrangementName.ToLower().Contains("rhythm"))
                        {
                            rsSong.Arrangement = arrangement.ArrangementName = "Lead";
                        }

                        if (xmlArr.ToLower().Contains("rhythm") && arrangement.ArrangementName.ToLower().Contains("lead"))
                        {
                            rsSong.Arrangement = arrangement.ArrangementName = "Rhythm";
                        }

                        if (xmlArr.ToLower().Contains("lead"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("lead"))
                            {
                                continue;
                            }
                        }
                        if (xmlArr.ToLower().Contains("rhythm"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("rhythm"))
                            {
                                continue;
                            }
                        }
                        if (xmlArr.ToLower().Contains("combo"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("combo"))
                            {
                                continue;
                            }
                        }
                        if (xmlArr.ToLower().Contains("bass"))
                        {
                            if (!arrangement.ArrangementName.ToLower().Contains("bass"))
                            {
                                continue;
                            }
                        }

                        if (rsSong.Part == arrangement.SongPartition || tones.Count == 1) // this is inaccurate for some
                        {
                            foreach (var tone in tones)                                   // tone.manifest
                            {
                                if (String.IsNullOrEmpty(arrangement.EffectChainName))
                                {
                                    arrangement.EffectChainName = "Default";
                                }

                                if (arrangement.EffectChainName.ToLower() == tone.Key.ToLower() || tones.Count == 1) // ok
                                {
                                    if (convert)
                                    {
                                        using (var obj1 = new Rs1Converter())
                                            tones2014.Add(obj1.ToneToTone2014(tone));

                                        // added for consistent naming
                                        tone.Name = tones2014[tones2014.Count - 1].Name;
                                        tone.Key  = tones2014[tones2014.Count - 1].Key;
                                    }

                                    // load attr2014 with RS1 mapped values for use by Arrangement()
                                    attr2014.Tone_Base            = tone.Name;
                                    attr2014.ArrangementName      = arrangement.ArrangementName;
                                    attr2014.CentOffset           = 0;
                                    attr2014.DynamicVisualDensity = new List <float>()
                                    {
                                        2
                                    };
                                    attr2014.SongPartition = arrangement.SongPartition;
                                    attr2014.PersistentID  = IdGenerator.Guid().ToString();
                                    attr2014.MasterID_RDV  = RandomGenerator.NextInt();

                                    attr2014.ArrangementProperties = new SongArrangementProperties2014();

                                    if (arrangement.ArrangementName.ToLower().Contains("lead"))
                                    {
                                        attr2014.ArrangementType = 0;
                                        attr2014.ArrangementProperties.RouteMask = 1;
                                    }
                                    else if (arrangement.ArrangementName.ToLower().Contains("rhythm"))
                                    {
                                        attr2014.ArrangementType = 1;
                                        attr2014.ArrangementProperties.RouteMask = 2;
                                    }
                                    else if (arrangement.ArrangementName.ToLower().Contains("combo"))
                                    {
                                        attr2014.ArrangementType = 2;
                                        attr2014.ArrangementProperties.RouteMask = arrangement.EffectChainName.ToLower().Contains("lead") ? 1 : 2;
                                    }
                                    else if (arrangement.ArrangementName.ToLower().Contains("bass"))
                                    {
                                        attr2014.ArrangementType = 3;
                                        attr2014.ArrangementProperties.RouteMask = 4;
                                    }
                                    else
                                    {
                                        // some RS1 CDLC do not have a valid ArrangementName
                                        if (rsSong.Arrangement.ToLower().Contains("guitar"))
                                        {
                                            attr2014.ArrangementName = "Lead";
                                            attr2014.ArrangementType = 0;
                                            attr2014.ArrangementProperties.RouteMask = 1;
                                        }
                                        else if (rsSong.Arrangement.ToLower().Contains("bass"))
                                        {
                                            attr2014.ArrangementName = "Bass";
                                            attr2014.ArrangementType = 3;
                                            attr2014.ArrangementProperties.RouteMask = 4;
                                        }
                                        else // default to rhythm
                                        {
                                            attr2014.ArrangementName = "Rhythm";
                                            attr2014.ArrangementType = 1;
                                            attr2014.ArrangementProperties.RouteMask = 2;
                                        }
                                    }

                                    if (arrangement.Tuning == "E Standard")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                                        }
                                    }
                                    ;
                                    else if (arrangement.Tuning == "DropD")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = -2, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                                        }
                                    }
                                    ;
                                    else if (arrangement.Tuning == "OpenG")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = -2, String1 = -2, String2 = 0, String3 = 0, String4 = 0, String5 = -2
                                        }
                                    }
                                    ;
                                    else if (arrangement.Tuning == "EFlat")
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = -1, String1 = -1, String2 = -1, String3 = -1, String4 = -1, String5 = -1
                                        }
                                    }
                                    ;
                                    else // default to standard tuning
                                    {
                                        rsSong.Tuning = new TuningStrings {
                                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                                        }
                                    };

                                    foundToneForArrangement = true;
                                    break;
                                }
                            }
                        }

                        if (foundToneForArrangement)
                        {
                            break;
                        }
                    }

                    if (!foundToneForArrangement)
                    {
                        Console.WriteLine(@"Could not determine the arrangement tone pairing");
                    }

                    // write the tones to file
                    using (var obj1 = new Rs1Converter())
                        obj1.SongToXml(rsSong, xmlFile, true);

                    if (convert) // RS1 -> RS2
                    {
                        Song2014 rsSong2014 = new Song2014();

                        using (var obj1 = new Rs1Converter())
                            rsSong2014 = obj1.SongToSong2014(rsSong);

                        using (var obj2 = new Rs2014Converter())
                            obj2.Song2014ToXml(rsSong2014, xmlFile, true);
                    }

                    // Adding Song Arrangement
                    try
                    {
                        data.Arrangements.Add(new Arrangement(attr2014, xmlFile));
                    }
                    catch (Exception ex)
                    {
                        // mainly for the benifit of convert2012 CLI users
                        Console.WriteLine(@"This CDLC could not be auto converted." + Environment.NewLine + "You can still try manually adding the arrangements and assests." + Environment.NewLine + ex.Message);
                    }
                }
            }

            data.TonesRS2014 = tones2014;

            //Get Album Artwork DDS Files
            var artFiles = Directory.GetFiles(unpackedDir, "*.dds", SearchOption.AllDirectories);

            if (artFiles.Length < 1)
            {
                throw new DataException("No Album Artwork file found.");
            }
            if (artFiles.Length > 1)
            {
                throw new DataException("More than one Album Artwork file found.");
            }

            var targetArtFiles = new List <DDSConvertedFile>();

            data.AlbumArtPath = artFiles[0];
            targetArtFiles.Add(new DDSConvertedFile()
            {
                sizeX = 256, sizeY = 256, sourceFile = artFiles[0], destinationFile = artFiles[0].CopyToTempFile(".dds")
            });
            data.ArtFiles = targetArtFiles;

            //Audio files
            var targetAudioFiles = new List <string>();
            var audioFiles       = Directory.GetFiles(unpackedDir, "*.ogg", SearchOption.AllDirectories);

            if (audioFiles.Length < 1)
            {
                throw new DataException("No Audio file found.");
            }
            if (audioFiles.Length > 2)
            {
                throw new DataException("Too many Audio files found.");
            }

            int i;

            for (i = 0; i < audioFiles.Length; i++)
            {
                if (convert && audioFiles[i].Contains("_fixed.ogg")) // use it
                {
                    break;
                }
                if (!convert && !audioFiles[i].Contains("_fixed.ogg"))
                {
                    break;
                }
            }

            var sourcePlatform = unpackedDir.GetPlatform();

            if (targetPlatform.IsConsole != (sourcePlatform = audioFiles[i].GetAudioPlatform()).IsConsole)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(audioFiles[i]), String.Format("{0}_cap.ogg", Path.GetFileNameWithoutExtension(audioFiles[i])));
                OggFile.ConvertAudioPlatform(audioFiles[i], newFile);
                audioFiles[i] = newFile;
            }

            targetAudioFiles.Add(audioFiles[i]);

            if (!targetAudioFiles.Any())
            {
                throw new DataException("Audio file not found.");
            }

            FileInfo a = new FileInfo(audioFiles[i]);

            data.OggPath = a.FullName;

            //AppID
            if (!convert)
            {
                var appidFile = Directory.GetFiles(unpackedDir, "*APP_ID*", SearchOption.AllDirectories);
                if (appidFile.Length > 0)
                {
                    data.AppId = File.ReadAllText(appidFile[0]);
                }
            }
            else
            {
                data.AppId = "248750";
            }

            //Package version
            var versionFile = Directory.GetFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories);

            if (versionFile.Length > 0)
            {
                data.PackageVersion = GeneralExtensions.ReadPackageVersion(versionFile[0]);
            }
            else
            {
                data.PackageVersion = "1";
            }

            if (convert)
            {
                data.Tones = null;
            }

            return(data);
        }
Example #10
0
        private static void ExecuteCommand(CommandLineOptions opts)
        {
            var jsonList = new List <string>();

            if (opts.JsonFiles != null)
            {
                foreach (var file in opts.JsonFiles)
                {
                    var fileContent = File.ReadAllText(file);
                    jsonList.Add(fileContent);
                }
            }

            if (opts.JsonStrings != null)
            {
                foreach (var jstring in opts.JsonStrings)
                {
                    jsonList.Add(jstring);
                }
            }

            var loadSettings = new JsonLoadSettings();

            if (opts.CommentsIgnore)
            {
                loadSettings.CommentHandling = CommentHandling.Ignore;
            }
            else
            {
                loadSettings.CommentHandling = CommentHandling.Load;
            }

            if (opts.LineInfoIgnore)
            {
                loadSettings.LineInfoHandling = LineInfoHandling.Ignore;
            }
            else
            {
                loadSettings.LineInfoHandling = LineInfoHandling.Load;
            }

            var mergeSettings = new JsonMergeSettings();

            if (opts.ArrayConcat)
            {
                mergeSettings.MergeArrayHandling = MergeArrayHandling.Concat;
            }
            else if (opts.ArrayMerge)
            {
                mergeSettings.MergeArrayHandling = MergeArrayHandling.Merge;
            }
            else if (opts.ArrayReplace)
            {
                mergeSettings.MergeArrayHandling = MergeArrayHandling.Replace;
            }
            else if (opts.ArrayUnion)
            {
                mergeSettings.MergeArrayHandling = MergeArrayHandling.Union;
            }

            if (opts.NullIgnore)
            {
                mergeSettings.MergeNullValueHandling = MergeNullValueHandling.Ignore;
            }
            else
            {
                mergeSettings.MergeNullValueHandling = MergeNullValueHandling.Merge;
            }

            Formatting formatting = Formatting.None;

            if (opts.Indent)
            {
                formatting = Formatting.Indented;
            }

            string mergedJson = MergeJson(jsonList, loadSettings, mergeSettings, formatting);

            if (String.IsNullOrEmpty(opts.OutputJsonFile))
            {
                Console.Write(mergedJson);
            }
            else
            {
                File.WriteAllText(opts.OutputJsonFile, mergedJson);
            }
        }
 /// <summary>
 /// Merge the specified content into this <see cref="JToken"/> using <see cref="JsonMergeSettings"/>.
 /// </summary>
 /// <param name="content">The content to be merged.</param>
 /// <param name="settings">The <see cref="JsonMergeSettings"/> used to merge the content.</param>
 public void Merge(object content, JsonMergeSettings settings)
 {
     MergeItem(content, settings);
 }
Example #12
0
        public static Configuration LoadConfiguration(IEnumerable <string> configurationFileOrUrls, string profile, IEnumerable <KeyValuePair <string, string> > arguments)
        {
            JObject configuration = null;

            foreach (var configurationFileOrUrl in configurationFileOrUrls)
            {
                JObject localconfiguration;

                if (!string.IsNullOrWhiteSpace(configurationFileOrUrl))
                {
                    string configurationContent;

                    // Load the job definition from a url or locally
                    try
                    {
                        if (configurationFileOrUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                        {
                            configurationContent = _httpClient.GetStringAsync(configurationFileOrUrl).GetAwaiter().GetResult();
                        }
                        else
                        {
                            configurationContent = File.ReadAllText(configurationFileOrUrl);
                        }
                    }
                    catch
                    {
                        throw new Exception($"Configuration '{configurationFileOrUrl}' could not be loaded.");
                    }

                    localconfiguration = JObject.Parse(configurationContent);
                }
                else
                {
                    throw new Exception($"Invalid file path or url: '{configurationFileOrUrl}'");
                }

                if (configuration != null)
                {
                    var mergeOptions = new JsonMergeSettings {
                        MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge
                    };

                    configuration.Merge(localconfiguration);
                }
                else
                {
                    configuration = localconfiguration;
                }
            }

            var configurationInstance = configuration.ToObject <Configuration>();

            // Roundtrip the JObject such that it contains all the exta properties of the Configuration class that are not in the configuration file
            configuration = JObject.FromObject(configurationInstance);

            // Apply profile properties if a profile name is provided
            if (!String.IsNullOrWhiteSpace(profile))
            {
                if (!configurationInstance.Profiles.ContainsKey(profile))
                {
                    throw new Exception($"The profile `{profile}` was not found");
                }

                PatchObject(configuration, JObject.FromObject(configurationInstance.Profiles[profile]));
            }

            // Apply custom arguments
            foreach (var argument in Arguments)
            {
                JToken node = configuration;

                var segments = argument.Key.Split('.');

                foreach (var segment in segments)
                {
                    node = ((JObject)node).GetValue(segment, StringComparison.OrdinalIgnoreCase);
                }

                if (node is JArray jArray)
                {
                    jArray.Add(argument.Value);
                }
                else if (node is JValue jValue)
                {
                    // The value is automatically converted to the destination type
                    jValue.Value = argument.Value;
                }
            }

            var result = configuration.ToObject <Configuration>();

            // TODO: Post process the services to re-order them based on weight
            // result.Dependencies = result.Dependencies.OrderBy(x => x, x.Contains(":") ? int.Parse(x.Split(':', 2)[1]) : 100);

            // Override default values in ServerJob
            foreach (var dependency in result.Dependencies)
            {
                var service = result.Services[dependency];
                service.NoArguments = true;
            }

            return(result);
        }
Example #13
0
        /// <summary>
        /// Applies all command line argument to alter the configuration files and build a final Configuration instance.
        /// 1- Merges the configuration files in the same order as requested
        /// 2- For each scenario's job, clone it in the Configuration's jobs list
        /// 3- Path the new job with the scenario's properties
        /// </summary>
        public static Configuration BuildConfiguration(IEnumerable <string> configurationFileOrUrls, string scenarioName, IEnumerable <KeyValuePair <string, string> > arguments)
        {
            JObject configuration = null;

            foreach (var configurationFileOrUrl in configurationFileOrUrls)
            {
                JObject localconfiguration;

                if (!string.IsNullOrWhiteSpace(configurationFileOrUrl))
                {
                    string configurationContent;

                    // Load the job definition from a url or locally
                    try
                    {
                        if (configurationFileOrUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                        {
                            configurationContent = _httpClient.GetStringAsync(configurationFileOrUrl).GetAwaiter().GetResult();
                        }
                        else
                        {
                            configurationContent = File.ReadAllText(configurationFileOrUrl);
                        }
                    }
                    catch
                    {
                        throw new Exception($"Configuration '{configurationFileOrUrl}' could not be loaded.");
                    }

                    localconfiguration = null;

                    switch (Path.GetExtension(configurationFileOrUrl))
                    {
                    case ".json":
                        localconfiguration = JObject.Parse(configurationContent);
                        break;

                    case ".yml":
                    case ".yaml":

                        var deserializer = new DeserializerBuilder().Build();
                        var yamlObject   = deserializer.Deserialize(new StringReader(configurationContent));

                        var serializer = new SerializerBuilder()
                                         .JsonCompatible()
                                         .Build();

                        var json = serializer.Serialize(yamlObject);
                        localconfiguration = JObject.Parse(json);
                        break;
                    }
                }
                else
                {
                    throw new Exception($"Invalid file path or url: '{configurationFileOrUrl}'");
                }

                if (configuration != null)
                {
                    var mergeOptions = new JsonMergeSettings {
                        MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge
                    };

                    configuration.Merge(localconfiguration);
                }
                else
                {
                    configuration = localconfiguration;
                }
            }

            // Roundtrip the JObject such that it contains all the exta properties of the Configuration class that are not in the configuration file
            var configurationInstance = configuration.ToObject <Configuration>();

            // After that point we only modify the concrete instance of Configuration
            if (!configurationInstance.Scenarios.ContainsKey(scenarioName))
            {
                throw new Exception($"The scenario `{scenarioName}` was not found");
            }

            var scenario = configurationInstance.Scenarios[scenarioName];

            // Clone each service from the selected scenario inside the Jobs property of the Configuration
            foreach (var service in scenario)
            {
                var jobName     = service.Value.Job;
                var serviceName = service.Key;

                if (!configurationInstance.Jobs.ContainsKey(jobName))
                {
                    throw new Exception($"The job named `{jobName}` was not found for `{serviceName}`");
                }

                var jobObject        = JObject.FromObject(configurationInstance.Jobs[jobName]);
                var dependencyObject = (JObject)configuration["scenarios"][scenarioName][serviceName];

                PatchObject(jobObject, dependencyObject);

                configurationInstance.Jobs[serviceName] = jobObject.ToObject <ServerJob>();
            }

            // After that point we only modify the JObject representation of Configuration

            configuration = JObject.FromObject(configurationInstance);

            // Apply custom arguments
            foreach (var argument in arguments)
            {
                JToken node = configuration["Jobs"];

                var segments = argument.Key.Split('.');

                foreach (var segment in segments)
                {
                    node = ((JObject)node).GetValue(segment, StringComparison.OrdinalIgnoreCase);

                    if (node == null)
                    {
                        throw new Exception($"Could not find part of the configuration path: '{argument}'");
                    }
                }

                if (node is JArray jArray)
                {
                    jArray.Add(argument.Value);
                }
                else if (node is JValue jValue)
                {
                    // The value is automatically converted to the destination type
                    jValue.Value = argument.Value;
                }
                else if (node is JObject jObject)
                {
                    // String to Object mapping -> try to parse as KEY=VALUE
                    var argumentSegments = argument.Value.ToString().Split('=', 2);

                    if (argumentSegments.Length != 2)
                    {
                        throw new Exception($"Argument value '{argument.Value}' could not assigned to `{segments.Last()}`.");
                    }

                    jObject.Add(argumentSegments[0], argumentSegments[1]);
                }
            }

            var result = configuration.ToObject <Configuration>();

            // Override default values in ServerJob for backward compatibility as the server would automatically add custom arguments to the applications.
            foreach (var job in result.Jobs.Values)
            {
                job.NoArguments = true;
                job.Scenario    = scenarioName;
            }

            return(result);
        }
        /// <summary>
        /// Merges properties to the contents of a content item.
        /// </summary>
        /// <typeparam name="properties">The object to merge.</typeparam>
        /// <returns>The current <see cref="ContentItem"/> instance.</returns>
        public static ContentItem Merge(this ContentItem contentItem, object properties, JsonMergeSettings jsonMergeSettings = null)
        {
            var props = JObject.FromObject(properties);

            var originalDocumentId = contentItem.Id;

            contentItem.Data.Merge(props, jsonMergeSettings);
            contentItem.Elements.Clear();

            // Return to original value or it will be interpreated as a different object by YesSql.
            contentItem.Id = originalDocumentId;

            // After merging content here we need to remove all the well known properties from the Data jObject
            // or these properties will take precedence over the properties on the C# object when and if they are mutated.
            if (props.ContainsKey(nameof(contentItem.DisplayText)))
            {
                contentItem.DisplayText = props[nameof(contentItem.DisplayText)].ToString();
                contentItem.Data.Remove(nameof(contentItem.DisplayText));
            }

            if (props.ContainsKey(nameof(contentItem.Owner)))
            {
                contentItem.Owner  = props[nameof(contentItem.Owner)].ToString();
                contentItem.Author = props[nameof(contentItem.Owner)].ToString();
                contentItem.Data.Remove(nameof(contentItem.Owner));
            }

            if (props.ContainsKey(nameof(contentItem.Author)))
            {
                contentItem.Author = props[nameof(contentItem.Author)].ToString();
                contentItem.Data.Remove(nameof(contentItem.Author));
            }

            // Do not set these properties on the content item as they are the responsibility of the content manager.
            if (props.ContainsKey(nameof(contentItem.Published)))
            {
                contentItem.Data.Remove(nameof(contentItem.Published));
            }

            if (props.ContainsKey(nameof(contentItem.Latest)))
            {
                contentItem.Data.Remove(nameof(contentItem.Latest));
            }

            if (props.ContainsKey(nameof(contentItem.CreatedUtc)))
            {
                contentItem.Data.Remove(nameof(contentItem.CreatedUtc));
            }

            if (props.ContainsKey(nameof(contentItem.ModifiedUtc)))
            {
                contentItem.Data.Remove(nameof(contentItem.ModifiedUtc));
            }

            if (props.ContainsKey(nameof(contentItem.PublishedUtc)))
            {
                contentItem.Data.Remove(nameof(contentItem.PublishedUtc));
            }

            if (props.ContainsKey(nameof(contentItem.ContentItemId)))
            {
                contentItem.Data.Remove(nameof(contentItem.ContentItemId));
            }

            if (props.ContainsKey(nameof(contentItem.ContentItemVersionId)))
            {
                contentItem.Data.Remove(nameof(contentItem.ContentItemVersionId));
            }

            if (props.ContainsKey(nameof(contentItem.ContentType)))
            {
                contentItem.Data.Remove(nameof(contentItem.ContentType));
            }

            return(contentItem);
        }
Example #15
0
        /// <summary>Merges the new data into the Accout</summary>
        /// <param name="jobj">The new JObject to merge.</param>
        /// <param name="account">The account.</param>
        public static void MergeNewData(this HzAccount account, JObject jobj)
        {
            account.ServerTimeOffset = jobj["data"]["server_time"].Value <long>() - DateTimeOffset.Now.ToUnixTimeSeconds();
            var updateQuest = jobj.SelectToken("data.quest");

            if (updateQuest != null)
            {
                var questToUpdate = account.JsonData["data"]?["quests"]?.OfType <JContainer>().FirstOrDefault(quest => quest["id"]?.Value <int>() == updateQuest["id"]?.Value <int>());
                if (questToUpdate != null)
                {
                    questToUpdate.Merge(updateQuest);
                }
            }

            if (jobj.SelectToken("data.quests")?.HasValues ?? false)
            {
                var quests = account.JsonData.Descendants().OfType <JProperty>().FirstOrDefault(prop => prop.Name == "quests");
                if (quests != null)
                {
                    quests.Remove();
                }
            }
            if (jobj.SelectToken("data.opponents")?.HasValues ?? false)
            {
                var opponents = account.JsonData.Descendants().OfType <JProperty>().FirstOrDefault(prop => prop.Name == "opponents");
                if (opponents != null)
                {
                    opponents.Remove();
                }
            }
            var updateRoom = jobj.SelectToken("data.hideout_room");

            if (updateRoom != null)
            {
                var roomToUpdate = account.JsonData["data"]?["hideout_rooms"]?.OfType <JContainer>().FirstOrDefault(room => room["id"]?.Value <int>() == updateRoom["id"]?.Value <int>());
                if (roomToUpdate != null)
                {
                    roomToUpdate.Merge(updateRoom);
                }
                else
                {
                    var data = account.JsonData["data"];
                    if (data != null)
                    {
                        var rooms = data["hideout_rooms"] as JContainer;
                        if (rooms == null)
                        {
                            (data as JObject).Add(new JProperty("hideout_rooms"));
                        }
                    }
                    var container = account.JsonData["data"]?["hideout_rooms"] as JContainer;
                    container.Add(updateRoom);
                    //account.JsonData["data"]?["hideout_rooms"]?.OfType<JContainer>().a
                }
            }
            if (jobj.SelectToken("data.hideout_rooms")?.HasValues ?? false)
            {
                var rooms = jobj.SelectToken("data.hideout_rooms").OfType <JContainer>().ToList();
                foreach (var item in rooms)
                {
                    var roomToUpdate = account.JsonData["data"]?["hideout_rooms"]?.OfType <JContainer>().FirstOrDefault(room => room["id"]?.Value <int>() == item["id"]?.Value <int>());
                    if (roomToUpdate != null)
                    {
                        roomToUpdate.Merge(item);
                        item.Remove();
                    }
                }


                //var hideoutRooms = jobj.Descendants().OfType<JProperty>().FirstOrDefault(prop => prop.Name == "hideout_rooms");
                //if (hideoutRooms != null)
                //{
                //    hideoutRooms.Remove();
                //}
            }
            var settings = new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            };

            account.JsonData.Merge(jobj, settings);
            account.MainData = account.JsonData.ToObject <JsonRoot>();
        }
Example #16
0
        /// <summary>
        /// Post the custom tracking events to the OMS using Integration Account Tracking API
        /// </summary>
        /// <param name="eventSource">The event source</param>
        /// <param name="correlationId">The correlation client tracking ID</param>
        /// <param name="eventLevel">The event severity level</param>
        /// <param name="eventDateTime">The event date time</param>
        /// <param name="customSourceInformation">The custom event source information</param>
        /// <param name="customEventTrackingProperties">The custom tracking event properties to be posted to OMS</param>
        public void PostCustomTrackingEvents(
            string eventSource,
            string correlationId,
            string eventLevel,
            string eventDateTime,
            IDictionary <string, object> customSourceInformation,
            IDictionary <string, object> customEventTrackingProperties)
        {
            var apiUrl = this.CallBackUrl;

            // Initialize the default JSON merge settings
            var defaultJsonMergeSettings = new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            };

            // Initialize the JSON payload
            var contentJObject = new JObject
            {
                { IntegrationAccountTrackingApiConstants.SourceType, IntegrationAccountTrackingApiConstants.Custom }
            };

            // Populate the source details
            var sourceJObject = new JObject
            {
                { IntegrationAccountTrackingApiConstants.EventSourceName, eventSource }
            };

            // Add run instance information to it
            var runInstanceJObject = new JProperty(IntegrationAccountTrackingApiConstants.RunInstance, new JObject(new JProperty(IntegrationAccountTrackingApiConstants.OmsCorrelationTrackingId, correlationId)));

            sourceJObject.Add(runInstanceJObject);

            // Add custom source properties to it
            var customSourceJObject = JObject.FromObject(customSourceInformation);

            sourceJObject.Merge(customSourceJObject, defaultJsonMergeSettings);

            // Add the source details to the JSON payload
            contentJObject.Add(new JProperty(IntegrationAccountTrackingApiConstants.Source, sourceJObject));

            // Populate the event details
            var eventJObject = new JObject()
            {
                { IntegrationAccountTrackingApiConstants.EventLevel, eventLevel },
                { IntegrationAccountTrackingApiConstants.EventTime, eventDateTime },
                { IntegrationAccountTrackingApiConstants.RecordType, IntegrationAccountTrackingApiConstants.Custom }
            };

            // Add custom event properties
            var customEventJObject = JObject.FromObject(customEventTrackingProperties);

            eventJObject.Add(new JProperty(IntegrationAccountTrackingApiConstants.Record, customEventJObject));

            // Add the event details to the JSON payload
            contentJObject.Add(
                new JProperty(
                    IntegrationAccountTrackingApiConstants.Events,
                    new JArray()
            {
                eventJObject
            }));

            var jsonPayload = contentJObject.ToString();

            using (var client = new WebClient())
            {
                // Configure the headers
                client.Headers.Add(HttpRequestHeader.ContentType, "application/json");

                // Upload the JSON payload
                client.UploadString(new Uri(apiUrl), "POST", jsonPayload);
            }
        }
Example #17
0
        public JToken Do(ParseContext context, JToken jOptions, JObject obj, string keyWord)
        {
            var options = Common.ParseOptions <MergeOptions>(jOptions, context.Serializer);

            JObject resultObj = obj;

            foreach (var option in options)
            {
                var jsonMergeSettings = new JsonMergeSettings
                {
                    MergeNullValueHandling = option.NullValueHandling,
                    MergeArrayHandling     = MergeArrayHandling.Replace,
                    PropertyNameComparison =
                        option.IgnoreCase
                            ? StringComparison.OrdinalIgnoreCase
                            : StringComparison.Ordinal
                };

                var mergePath = option.DataSource;

                context = context.Clone();

                context.DisableProcessors = option.DisableProcessors ?? false;

                if (context.Parameters == null)
                {
                    context.Parameters = option.Parameters;
                }
                else if (option.Parameters != null)
                {
                    foreach (KeyValuePair <string, object> optionParameter in option.Parameters)
                    {
                        context.Parameters[optionParameter.Key] = optionParameter.Value;
                    }
                }


                var otherToken = context.Manager.LoadSettings(mergePath, context, LoadMode.Json);

                var otherObj = otherToken as JObject;

                if (otherObj == null)
                {
                    throw new SettingsException($"Merge path {mergePath} must be JObject");
                }


                if (option.Priority == MergePriority.This)
                {
                    otherObj.Merge(resultObj, jsonMergeSettings);
                    resultObj = otherObj;
                }
                else if (option.Priority == MergePriority.Other)
                {
                    resultObj.Merge(otherObj, jsonMergeSettings);
                }
                else
                {
                    throw new NotImplementedException(option.Priority.ToString());
                }
            }

            return(resultObj);
        }
        internal static void MergeEnumerableContent(JContainer target, IEnumerable content, JsonMergeSettings settings)
        {
            switch (settings.MergeArrayHandling)
            {
            case MergeArrayHandling.Concat:
                foreach (JToken item in content)
                {
                    target.Add(item);
                }
                break;

            case MergeArrayHandling.Union:
#if !NET20
                HashSet <JToken> items = new HashSet <JToken>(target, EqualityComparer);

                foreach (JToken item in content)
                {
                    if (items.Add(item))
                    {
                        target.Add(item);
                    }
                }
#else
                Dictionary <JToken, bool> items = new Dictionary <JToken, bool>(EqualityComparer);
                foreach (JToken t in target)
                {
                    items[t] = true;
                }

                foreach (JToken item in content)
                {
                    if (!items.ContainsKey(item))
                    {
                        items[item] = true;
                        target.Add(item);
                    }
                }
#endif
                break;

            case MergeArrayHandling.Replace:
                target.ClearItems();
                foreach (JToken item in content)
                {
                    target.Add(item);
                }
                break;

            case MergeArrayHandling.Merge:
                int i = 0;
                foreach (object targetItem in content)
                {
                    if (i < target.Count)
                    {
                        JToken sourceItem = target[i];

                        JContainer existingContainer = sourceItem as JContainer;
                        if (existingContainer != null)
                        {
                            existingContainer.Merge(targetItem, settings);
                        }
                        else
                        {
                            if (targetItem != null)
                            {
                                JToken contentValue = CreateFromContent(targetItem);
                                if (contentValue.Type != JTokenType.Null)
                                {
                                    target[i] = contentValue;
                                }
                            }
                        }
                    }
                    else
                    {
                        target.Add(targetItem);
                    }

                    i++;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(settings), "Unexpected merge array handling when merging JSON.");
            }
        }
 internal abstract void MergeItem(object content, JsonMergeSettings settings);
Example #20
0
        // Load RS1 CDLC into PackageCreator
        public static DLCPackageData RS1LoadFromFolder(string unpackedDir, Platform targetPlatform, bool convert)
        {
            var data = new DLCPackageData();

            data.Arrangements = new List <Arrangement>();
            data.TonesRS2014  = new List <Tone2014>();
            data.Tones        = new List <Tone>();

            data.GameVersion   = (convert ? GameVersion.RS2014 : GameVersion.RS2012);
            data.SignatureType = PackageMagic.CON;
            // set default volumes
            data.Volume        = -6.5F; // default maybe too quite
            data.PreviewVolume = data.Volume;

            //Load song manifest
            var songsManifestJson = Directory.GetFiles(unpackedDir, "songs.manifest.json", SearchOption.AllDirectories);

            if (songsManifestJson.Length < 1)
            {
                throw new DataException("No songs.manifest.json file found.");
            }
            if (songsManifestJson.Length > 1)
            {
                throw new DataException("More than one songs.manifest.json file found.");
            }

            var attr          = new List <Attributes>();
            var songsManifest = Manifest.Manifest.LoadFromFile(songsManifestJson[0]).Entries.ToArray();

            for (int smIndex = 0; smIndex < songsManifest.Count(); smIndex++)
            {
                var smData = songsManifest[smIndex].Value.ToArray()[0].Value;
                attr.Add(smData);
            }

            if (attr.FirstOrDefault() == null)
            {
                throw new DataException("songs.manifest.json file did not parse correctly.");
            }

            // Fill SongInfo
            data.SongInfo = new SongInfo();
            data.SongInfo.SongDisplayName     = attr.FirstOrDefault().SongName;
            data.SongInfo.SongDisplayNameSort = attr.FirstOrDefault().SongNameSort;
            data.SongInfo.Album      = attr.FirstOrDefault().AlbumName;
            data.SongInfo.SongYear   = (attr.FirstOrDefault().SongYear == 0 ? 2012 : attr.FirstOrDefault().SongYear);
            data.SongInfo.Artist     = attr.FirstOrDefault().ArtistName;
            data.SongInfo.ArtistSort = attr.FirstOrDefault().ArtistNameSort;
            data.Name = attr.FirstOrDefault().SongKey;

            //Load tone manifest, even poorly formed tone_bass.manifest.json
            var toneManifestJson = Directory.GetFiles(unpackedDir, "*tone*.manifest.json", SearchOption.AllDirectories);

            if (toneManifestJson.Length < 1)
            {
                throw new DataException("No tone.manifest.json file found.");
            }

            // toolkit produces multiple tone.manifest.json files when packing RS1 CDLC files
            // rather than change toolkit behavior just merge manifest files for now
            if (toneManifestJson.Length > 1)
            {
                var mergeSettings = new JsonMergeSettings {
                    MergeArrayHandling = MergeArrayHandling.Union
                };
                JObject toneObject1 = new JObject();

                foreach (var tone in toneManifestJson)
                {
                    JObject toneObject2 = JObject.Parse(File.ReadAllText(tone));
                    //(toneObject1.SelectToken("Entries") as JArray).Merge(toneObject2.SelectToken("Entries"));
                    toneObject1.Merge(toneObject2, mergeSettings);
                }

                toneManifestJson    = new string[1];
                toneManifestJson[0] = Path.Combine(unpackedDir, "merged.tone.manifest.json");
                string json = JsonConvert.SerializeObject(toneObject1, Formatting.Indented);
                File.WriteAllText(toneManifestJson[0], json);
            }

            var tones2014    = new List <Tone2014>();
            var tones        = new List <Tone>();
            var toneManifest = Manifest.Tone.Manifest.LoadFromFile(toneManifestJson[0]);

            for (int tmIndex = 0; tmIndex < toneManifest.Entries.Count(); tmIndex++)
            {
                var tmData = toneManifest.Entries[tmIndex];
                tones.Add(tmData);
            }

            data.Tones = tones;

            // Load AggregateGraph.nt
            var songDir = Path.Combine(unpackedDir, data.Name);

            if (targetPlatform.platform == GamePlatform.XBox360)
            {
                songDir = Path.Combine(unpackedDir, "Root", data.Name);
            }

            var aggFile      = Directory.GetFiles(songDir, "*.nt", SearchOption.TopDirectoryOnly)[0];
            var aggGraphData = AggregateGraph.AggregateGraph.ReadFromFile(aggFile);

            // Load Exports\Songs\*.xblock
            var xblockDir  = Path.Combine(songDir, "Exports\\Songs");
            var xblockFile = Directory.GetFiles(xblockDir, "*.xblock", SearchOption.TopDirectoryOnly)[0];
            // xblockFile = "D:\\Temp\\Mapping\\songs.xblock";
            var songsXblock = XblockX.LoadFromFile(xblockFile);

            // create project map for cross referencing arrangements with tones
            var projectMap = AggregateGraph.AggregateGraph.ProjectMap(aggGraphData, songsXblock, toneManifest);

            // Load xml arrangements
            var xmlFiles = Directory.GetFiles(unpackedDir, "*.xml", SearchOption.AllDirectories);

            if (xmlFiles.Length <= 0)
            {
                throw new DataException("Can not find any XML arrangement files");
            }

            foreach (var xmlFile in xmlFiles)
            {
                if (xmlFile.ToLower().Contains("metadata"))
                {
                    continue;
                }

                // some poorly formed RS1 CDLC use just "vocal"
                if (xmlFile.ToLower().Contains("vocal"))
                {
                    // Add Vocal Arrangement
                    data.Arrangements.Add(new Arrangement
                    {
                        Name            = ArrangementName.Vocals,
                        ArrangementType = ArrangementType.Vocal,
                        ScrollSpeed     = 20,
                        SongXml         = new SongXML {
                            File = xmlFile
                        },
                        SongFile = new SongFile {
                            File = ""
                        },
                        CustomFont = false
                    });
                }
                else
                {
                    var attr2014   = new Attributes2014();
                    var rsSong     = new Song();
                    var rsSong2014 = new Song2014();

                    // optimized tone matching effort using project mapping algo
                    var result = projectMap.First(m => String.Equals(Path.GetFileName(m.SongXmlPath), Path.GetFileName(xmlFile), StringComparison.CurrentCultureIgnoreCase));
                    if (result.Tones.Count != 1)
                    {
                        throw new DataException("Invalid RS1 CDLC Tones Data");
                    }

                    var arrangement = attr.First(s => s.SongXml.ToLower().Contains(result.LLID));//FIXME: Sequence contains no matching element issue
                    var tone        = tones.First(t => t.Key == result.Tones[0]);

                    using (var obj1 = new Rs1Converter())
                    {
                        rsSong = obj1.XmlToSong(xmlFile);
                        data.SongInfo.AverageTempo = (int)obj1.AverageBPM(rsSong);
                    }

                    if (arrangement.Tuning == "E Standard")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        }
                    }
                    ;
                    else if (arrangement.Tuning == "DropD")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = -2, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        }
                    }
                    ;
                    else if (arrangement.Tuning == "OpenG")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = -2, String1 = -2, String2 = 0, String3 = 0, String4 = 0, String5 = -2
                        }
                    }
                    ;
                    else if (arrangement.Tuning == "EFlat")
                    {
                        rsSong.Tuning = new TuningStrings {
                            String0 = -1, String1 = -1, String2 = -1, String3 = -1, String4 = -1, String5 = -1
                        }
                    }
                    ;
                    else // default to standard tuning
                    {
                        arrangement.Tuning = "E Standard";
                        rsSong.Tuning      = new TuningStrings {
                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        };
                    }

                    // save/write the changes to xml file
                    using (var obj1 = new Rs1Converter())
                        obj1.SongToXml(rsSong, xmlFile, true);

                    if (convert)
                    {
                        using (var obj1 = new Rs1Converter())
                            tones2014.Add(obj1.ToneToTone2014(tone, rsSong));
                    }

                    // load attr2014 with RS1 mapped values for use by Arrangement()
                    attr2014.Tone_Base            = tone.Name;
                    attr2014.ArrangementName      = arrangement.ArrangementName;
                    attr2014.CentOffset           = 0;
                    attr2014.DynamicVisualDensity = new List <float>()
                    {
                        2
                    };
                    attr2014.SongPartition         = arrangement.SongPartition;
                    attr2014.PersistentID          = IdGenerator.Guid().ToString();
                    attr2014.MasterID_RDV          = RandomGenerator.NextInt();
                    attr2014.ArrangementProperties = new SongArrangementProperties2014();

                    // processing order is important - CAREFUL
                    // RouteMask  None = 0, Lead = 1, Rhythm = 2, Any = 3, Bass = 4
                    // XML file names are usually meaningless to arrangement determination

                    if (arrangement.ArrangementName.ToLower().Contains("lead") ||
                        rsSong.Arrangement.ToLower().Contains("lead"))
                    {
                        attr2014.ArrangementName = "Lead";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Lead;
                        attr2014.ArrangementProperties.PathLead   = 1;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass   = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("rhythm") ||
                             rsSong.Arrangement.ToLower().Contains("rhythm"))
                    // || rsSong.Arrangement.ToLower().Contains("guitar"))
                    {
                        attr2014.ArrangementName = "Rhythm";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Rhythm;
                        attr2014.ArrangementProperties.PathLead   = 0;
                        attr2014.ArrangementProperties.PathRhythm = 1;
                        attr2014.ArrangementProperties.PathBass   = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("combo") ||
                             rsSong.Arrangement.ToLower().Contains("combo"))
                    {
                        attr2014.ArrangementName = "Combo";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = arrangement.EffectChainName.ToLower().Contains("lead") ? (int)RouteMask.Lead : (int)RouteMask.Rhythm;
                        attr2014.ArrangementProperties.PathLead   = arrangement.EffectChainName.ToLower().Contains("lead") ? 1 : 0;
                        attr2014.ArrangementProperties.PathRhythm = arrangement.EffectChainName.ToLower().Contains("lead") ? 0 : 1;
                        attr2014.ArrangementProperties.PathBass   = 0;
                    }
                    else if (arrangement.ArrangementName.ToLower().Contains("bass") ||
                             rsSong.Arrangement.ToLower().Contains("bass"))
                    {
                        attr2014.ArrangementName = "Bass";
                        attr2014.ArrangementType = (int)ArrangementType.Bass;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Bass;
                        attr2014.ArrangementProperties.PathLead   = 0;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass   = 1;
                    }
                    else
                    {
                        // default to Lead arrangement
                        attr2014.ArrangementName = "Lead";
                        attr2014.ArrangementType = (int)ArrangementType.Guitar;
                        attr2014.ArrangementProperties.RouteMask  = (int)RouteMask.Lead;
                        attr2014.ArrangementProperties.PathLead   = 1;
                        attr2014.ArrangementProperties.PathRhythm = 0;
                        attr2014.ArrangementProperties.PathBass   = 0;

                        Console.WriteLine("RS1->RS2 CDLC Conversion defaulted to 'Lead' arrangement");
                    }

                    if (convert) // RS1 -> RS2 magic
                    {
                        using (var obj1 = new Rs1Converter())
                            rsSong2014 = obj1.SongToSong2014(rsSong);

                        // update ArrangementProperties
                        rsSong2014.ArrangementProperties.RouteMask      = attr2014.ArrangementProperties.RouteMask;
                        rsSong2014.ArrangementProperties.PathLead       = attr2014.ArrangementProperties.PathLead;
                        rsSong2014.ArrangementProperties.PathRhythm     = attr2014.ArrangementProperties.PathRhythm;
                        rsSong2014.ArrangementProperties.PathBass       = attr2014.ArrangementProperties.PathBass;
                        rsSong2014.ArrangementProperties.StandardTuning = (arrangement.Tuning == "E Standard" ? 1 : 0);

                        // <note time="58.366" linkNext="0" accent="0" bend="0" fret="7" hammerOn="0" harmonic="0" hopo="0" ignore="0" leftHand="-1" mute="0" palmMute="0" pluck="-1" pullOff="0" slap="-1" slideTo="-1" string="3" sustain="0.108" tremolo="0" harmonicPinch="0" pickDirection="0" rightHand="-1" slideUnpitchTo="-1" tap="0" vibrato="0" />
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Bend != 0)))
                        {
                            rsSong2014.ArrangementProperties.Bends = 1;
                        }
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Hopo != 0)))
                        {
                            rsSong2014.ArrangementProperties.Hopo = 1;
                        }
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.SlideTo != -1)))
                        {
                            rsSong2014.ArrangementProperties.Slides = 1;
                        }
                        if (rsSong2014.Levels.Any(sl => sl.Notes.Any(sln => sln.Sustain > 0)))
                        {
                            rsSong2014.ArrangementProperties.Sustain = 1;
                        }

                        // fixing times that are off
                        var lastEbeatsTime           = rsSong2014.Ebeats[rsSong2014.Ebeats.Length - 1].Time;
                        var lastPhraseIterationsTime = rsSong2014.PhraseIterations[rsSong2014.PhraseIterations.Length - 1].Time;

                        // tested ... not source of in game hangs
                        // confirm last PhraseIterations time is less than last Ebeats time
                        if (lastPhraseIterationsTime > lastEbeatsTime)
                        {
                            rsSong2014.PhraseIterations[rsSong2014.PhraseIterations.Length - 1].Time = lastEbeatsTime;
                            rsSong2014.Sections[rsSong2014.Sections.Length - 1].StartTime            = lastEbeatsTime;
                        }

                        // tested ... not source of in game hangs
                        // confirm SongLength at least equals last Ebeats time
                        if (rsSong2014.SongLength < lastEbeatsTime)
                        {
                            rsSong2014.SongLength = lastEbeatsTime;
                        }

                        using (var obj2 = new Rs2014Converter())
                            obj2.Song2014ToXml(rsSong2014, xmlFile, true);
                    }

                    // Adding Song Arrangement
                    try
                    {
                        data.Arrangements.Add(new Arrangement(attr2014, xmlFile));
                    }
                    catch (Exception ex)
                    {
                        // mainly for the benefit of convert2012 CLI users
                        Console.WriteLine(@"This CDLC could not be auto converted." + Environment.NewLine + "You can still try manually adding the arrangements and assets." + Environment.NewLine + ex.Message);
                    }
                }
            }
            if (convert)
            {
                // get rid of duplicate tone names
                tones2014 = tones2014.Where(p => p.Name != null)
                            .GroupBy(p => p.Name).Select(g => g.First()).ToList();
                data.TonesRS2014 = tones2014;
            }

            //Get Album Artwork DDS Files
            var artFiles = Directory.GetFiles(unpackedDir, "*.dds", SearchOption.AllDirectories);

            if (artFiles.Length < 1)
            {
                throw new DataException("No Album Artwork file found.");
            }
            if (artFiles.Length > 1)
            {
                throw new DataException("More than one Album Artwork file found.");
            }

            var targetArtFiles = new List <DDSConvertedFile>();

            data.AlbumArtPath = artFiles[0];
            targetArtFiles.Add(new DDSConvertedFile()
            {
                sizeX = 256, sizeY = 256, sourceFile = artFiles[0], destinationFile = artFiles[0].CopyToTempFile(".dds")
            });
            data.ArtFiles = targetArtFiles;

            //Audio files
            var targetAudioFiles = new List <string>();
            var audioFiles       = Directory.GetFiles(unpackedDir, "*.ogg", SearchOption.AllDirectories);

            if (audioFiles.Length < 1)
            {
                throw new DataException("No Audio file found.");
            }
            if (audioFiles.Length > 2)
            {
                throw new DataException("Too many Audio files found.");
            }

            int i;

            for (i = 0; i < audioFiles.Length; i++)
            {
                if (convert && audioFiles[i].Contains("_fixed.ogg")) // use it
                {
                    break;
                }
                if (!convert && !audioFiles[i].Contains("_fixed.ogg"))
                {
                    break;
                }
            }
            // FIXME: platform specific decode is broken
            var sourcePlatform = unpackedDir.GetPlatform();

            if (targetPlatform.IsConsole != (sourcePlatform = audioFiles[i].GetAudioPlatform()).IsConsole)
            {
                var newFile = Path.Combine(Path.GetDirectoryName(audioFiles[i]), String.Format("{0}_cap.ogg", Path.GetFileNameWithoutExtension(audioFiles[i])));
                OggFile.ConvertAudioPlatform(audioFiles[i], newFile);
                audioFiles[i] = newFile;
            }

            targetAudioFiles.Add(audioFiles[i]);

            if (!targetAudioFiles.Any())
            {
                throw new DataException("Audio file not found.");
            }

            var a = new FileInfo(audioFiles[i]);

            data.OggPath = a.FullName;

            //AppID
            if (!sourcePlatform.IsConsole)
            {
                if (!convert)
                {
                    var appidFile = Directory.GetFiles(unpackedDir, "*APP_ID*", SearchOption.AllDirectories);
                    if (appidFile.Length > 0)
                    {
                        data.AppId = File.ReadAllText(appidFile[0]);
                    }
                }
                else
                {
                    data.AppId = "248750";
                }
            }

            try
            {
                // Package Info
                var versionFile = Directory.EnumerateFiles(unpackedDir, "toolkit.version", SearchOption.AllDirectories).FirstOrDefault();
                if (versionFile != null)
                {
                    var tkInfo = GeneralExtensions.ReadToolkitInfo(versionFile);
                    data.PackageVersion = tkInfo.PackageVersion;
                    data.PackageComment = tkInfo.PackageComment;
                }
                else
                {
                    data.PackageVersion = "1";
                    data.PackageComment = "";
                }
            }
            catch { }

            if (convert)
            {
                data.Tones = null;
            }

            return(data);
        }
Example #21
0
        //[Route("GetUserModulesWithNotifications")]
        public HttpResponseMessage GetUserModules()
        {
            try
            {
                /*groupby da Select ი იმიტომაა რომ ხანდახან module ები დუბლირებულად მოდის(ერთი და იგივე რამოდენიმეჯერ)*/
                var modulesList = AuthUser.Modules.GroupBy(x => x.ID).Select(g => g.First()).ToList();

                /**
                 * get module Notifications
                 */
                var moduleIds = modulesList.Select(i => i.ID).ToList();

                var externalModuleIDs = modulesList.Where(i => i.ExternalService == 1).Select(i => i.ID).ToList();

                /*notification type 2 == OnMain notifications*/ // .Where(i=>i.Pinned)

                var moduleIdsAsString = moduleIds.FirstOrDefault().ToString();

                for (int i = 1; i < moduleIds.Count; i++)
                {
                    moduleIdsAsString = $"{moduleIdsAsString},{moduleIds[i].ToString()}";
                }


                var externalModuleIdsAsStr = string.Empty;
                for (int i = 1; i < externalModuleIDs.Count; i++)
                {
                    externalModuleIdsAsStr = $"{externalModuleIdsAsStr},{externalModuleIDs[i].ToString()}";
                }

                var notifications =
                    DataProviderManager <PKG_MENU> .Provider.GetNotificationsJson(moduleIdsAsString, 3, AuthUser.UnID,
                                                                                  AuthUser.SubUserID);

                // var externalGroupIcons = DataProviderManager<PKG_MENU>.Provider.GetModuleGroupIcons($",{externalModuleIdsAsStr},");

                //   var externalGroupIconsProp = new JProperty("ExternalGroupIcons", JArray.FromObject(externalGroupIcons.Select(i=> new { Image = i.Item2, ModuleID = i.Item1 })));


                /* mandatory ნოტიფიკაციაში js ფუნქციაში (" da ") ან აურია JSON ი და ქვევით escape ს ვუკეთებ " - ას */

                notifications = notifications.Replace("(\"", "(\\\"");
                notifications = notifications.Replace("\")", "\\\")");
                // old =  (" new = (\"
                var notifProp   = new JProperty("ModuleNotifications", JArray.Parse(notifications));
                var modulesProp = new JProperty("UserModules", JArray.Parse(JsonConvert.SerializeObject(modulesList)));


                var moduleJson = new JObject(modulesProp);
                var notifJson  = new JObject(notifProp);
                // var externalGroupIconsJson = new JObject(externalGroupIconsProp);
                var mergeSettings = new JsonMergeSettings
                {
                    MergeArrayHandling     = MergeArrayHandling.Union,
                    MergeNullValueHandling = MergeNullValueHandling.Merge
                };

                moduleJson.Merge(notifJson, mergeSettings);
                //  moduleJson.Merge(externalGroupIconsJson, mergeSettings);
                return(Success(moduleJson));
            }
            catch (Exception ex)
            {
                CommonFunctions.CatchExceptions(ex, "", false, AuthUser.Username);
            }
            return(Success());
        }
        /// <summary>
        /// Merges properties to the contents of a content item.
        /// </summary>
        /// <typeparam name="properties">The object to merge.</typeparam>
        /// <returns>The modified <see cref="ContentItem"/> instance.</returns>
        public static ContentItem Merge(this ContentItem contentItem, object properties, JsonMergeSettings jsonMergeSettings = null)
        {
            var props   = JObject.FromObject(properties);
            var content = (JObject)contentItem.Content;

            content.Merge(props, jsonMergeSettings);
            contentItem.Elements.Clear();

            if (props.ContainsKey(nameof(contentItem.DisplayText)))
            {
                contentItem.DisplayText = props[nameof(contentItem.DisplayText)].ToString();
            }

            if (props.ContainsKey(nameof(contentItem.Owner)))
            {
                contentItem.Owner  = props[nameof(contentItem.Owner)].ToString();
                contentItem.Author = props[nameof(contentItem.Owner)].ToString();
            }

            if (props.ContainsKey(nameof(contentItem.Author)))
            {
                contentItem.Author = props[nameof(contentItem.Author)].ToString();
            }

            return(contentItem);
        }
Example #23
0
        public void MergeSettingsComparisonDefault()
        {
            JsonMergeSettings settings = new JsonMergeSettings();

            Assert.AreEqual(StringComparison.Ordinal, settings.PropertyNameComparison);
        }
Example #24
0
        // TODO we don't have a merge for elements.
        public static ContentItem FromDto <TDto>(this ContentItem contentItem, TDto dto, JsonMergeSettings jsonMergeSettings = null)
            where TDto : ContentItemDto
        {
            if (dto == null)
            {
                throw new ArgumentNullException();
            }

            var jObject = JObject.FromObject(dto);

            if (jsonMergeSettings == null)
            {
                return(contentItem.Merge(jObject, ReplaceJsonMergeSettings));
            }
            else
            {
                return(contentItem.Merge(jObject, jsonMergeSettings));
            }
        }
Example #25
0
        public string explore_getResult(string expID, bool messagebox = true)
        {
            JsonText Res = CreateJsonText(StdGetRequest($"explore/getResult/{expID}/"));

            if (Res["updateTaskVo"] != null)
            {
                foreach (var taskUpdate in Res["updateTaskVo"])
                {
                    var taskCondition = from task in gameinfo["taskVo"]
                                        where (string)task["taskCid"] == (string)taskUpdate["taskCid"]
                                        select task;
                    taskCondition.First()["condition"] = taskUpdate["condition"];
                }
            }
            //loveChange
            //$intimacyOther ????
            //rewardItems
            var mergeSettings = new JsonMergeSettings
            {
                MergeArrayHandling = MergeArrayHandling.Union
            };

            ((JObject)gameinfo["userVo"]).Merge(Res["userLevelVo"], mergeSettings);
            //((JObject)gameinfo["detailInfo"]).Merge(Res["userLevelVo"], mergeSettings);
            JToken packageVo;

            if (Res.obj.TryGetValue("packageVo", out packageVo))
            {
                foreach (var itemnew in packageVo)
                {
                    var iteminfo = from itemold in gameinfo["packageVo"]
                                   where (string)itemold["itemCid"] == (string)itemnew["itemCid"]
                                   select itemold;
                    if (iteminfo.Any())
                    {
                        iteminfo.First()["num"] = itemnew["num"];
                    }
                    else
                    {
                        ((JArray)gameinfo["packageVo"]).Add(itemnew);
                    }
                }
            }
            ((JObject)gameinfo["userVo"]).Merge(Res["userResVo"], mergeSettings);
            //newAward
            gameinfo["pveExploreVo"] = Res["pveExploreVo"];
            gameinfo["detailInfo"]   = Res["detailInfo"];
            //shipVO
            gameinfo["fleetVo"] = Res["fleetVo"];
            ///////////////////////////////////////////////////////////////////
            string expTitle = (from expinfo in init_txt["pveExplore"]
                               where (string)expinfo["id"] == expID
                               select(string) expinfo["title"]).First();

            string resStr = string.Format(getLangStr("ExpeditionCompleted")
                                          .Replace("%d", "{0}").Replace("%s", "{1}"),
                                          Res["shipVO"]["id"], expTitle);

            if ((string)Res["bigSuccess"] == "1")
            {
                resStr += Environment.NewLine + "大成功!";
            }

            resStr += Environment.NewLine + "获得:" + Environment.NewLine;
            foreach (var award in (JObject)Res["newAward"])
            {
                resStr += "\t" + getCidText(int.Parse(award.Key)) + "x" + (string)award.Value + Environment.NewLine;
            }

            resStr += "舰队成员:" + Environment.NewLine;
            int shipIndex = 0;

            //int intimacyOtherIndex = 0;
            foreach (var shipID in (JArray)Res["shipVO"]["ships"])
            {
                int shipCid = (from ship in gameinfo["userShipVO"] where ship["id"].ToString() == (string)shipID select(int) ship["shipCid"]).First();
                resStr += "\t" + getCidText(shipCid) + "\t";
                if (Res["loveChange"].HasValues &&
                    Res["loveChange"][shipIndex].ToString().ToLower() != "false")
                {
                    resStr += "好感度:+" + Res["loveChange"][shipIndex] + Environment.NewLine;
                    var shipinfo = from ship in gameinfo["userShipVO"]
                                   where ship["id"].ToString() == (string)shipID
                                   select ship;
                    shipinfo.First()["love"] =
                        (int)shipinfo.First()["love"] +
                        (int)Res["loveChange"][shipIndex];
                }
                else
                {
                    resStr += Environment.NewLine;
                }
                shipIndex++;
            }
            if (messagebox)
            {
                ;//MessageBox.Show(resStr, getLangStr("HasFinishedPVEExplore"));
            }
            return(resStr);
        }
Example #26
0
 /// <summary>
 /// Merges properties to the contents of a content item.
 /// </summary>
 /// <param name="properties">The object to merge.</param>
 /// <param name="content"> </param>
 /// <param name="jsonMergeSettings"> </param>
 /// <returns>The modified <see cref="ContentItem"/> instance.</returns>
 public static IContent Merge(this IContent content, object properties, JsonMergeSettings jsonMergeSettings = null) =>
 content.ContentItem.Merge(properties, jsonMergeSettings);