Example #1
0
        private static void AddManualWorkbookByUrl(string in_manualUrl, Google2uData in_instance)
        {
            WorkbookBase info;
            if (string.IsNullOrEmpty(in_manualUrl))
            {
                Debug.LogError(LocalizationInfo.Localize(Localization.rowIds.ID_ERROR_EMPTY_URL));
                return;
            }

            var refreshManualWorkbookCache = false;
            try
            {
                var key =
                    in_manualUrl.Substring(in_manualUrl.IndexOf("key=", StringComparison.InvariantCultureIgnoreCase) + 4);
                key = key.Split('&')[0];

                var singleQuery = new WorksheetQuery(key, "public", "values");

                if (in_instance.ManualService == null && !SetupManualService(in_instance))
                    return;

                var feed = in_instance.ManualService.Query(singleQuery);

                var finalUrl = in_manualUrl.Split('&')[0];

                if (feed != null)
                {
                    info =
                        in_instance.ManualWorkbooks.Find(in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) ??
                        in_instance.AccountWorkbooks.Find(in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl))
                            as WorkbookBase;
                    if (info == null)
                    {
                        var newWorkbook = new Google2uManualWorkbook(feed, finalUrl, feed.Title.Text,
                            in_instance.ManualService);
                        in_instance.ManualWorkbooks.Add(newWorkbook);

                        refreshManualWorkbookCache = true;
                    }
                }
            }
            catch
            {
                try
                {
                    var key =
                        in_manualUrl.Substring(
                            in_manualUrl.IndexOf("spreadsheets/d/", StringComparison.InvariantCultureIgnoreCase) + 15);
                    key = key.Split('/')[0];

                    if (in_instance.ManualService == null && !SetupManualService(in_instance))
                        return;

                    var singleQuery = new WorksheetQuery(key, "public", "values");
                    var feed = in_instance.ManualService.Query(singleQuery);
                    var urlParts = in_manualUrl.Split('/');

                    var finalUrl = "";
                    var urlBuild = 0;
                    string urlPart;
                    do
                    {
                        urlPart = urlParts[urlBuild];
                        finalUrl += urlPart + '/';
                        urlBuild++;
                    } while (urlPart != key);
                    if (feed != null)
                    {
                        info =
                            in_instance.ManualWorkbooks.Find(
                                in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) ??
                            in_instance.AccountWorkbooks.Find(
                                in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) as WorkbookBase;
                        if (info == null)
                        {
                            var newWorkbook = new Google2uManualWorkbook(feed, finalUrl, feed.Title.Text,
                                in_instance.ManualService);
                            in_instance.ManualWorkbooks.Add(newWorkbook);

                            refreshManualWorkbookCache = true;
                        }
                    }
                }
                catch
                {
                    Debug.LogError(LocalizationInfo.Localize(Localization.rowIds.ID_ERROR_INVALID_URL));
                }
            }

            if (refreshManualWorkbookCache)
            {
                in_instance.ManualWorkbookCache = string.Empty;
                foreach (var Google2uSpreadsheet in in_instance.ManualWorkbooks)
                {
                    in_instance.ManualWorkbookCache += Google2uSpreadsheet.WorkbookUrl + "|";
                }
            }
        }
Example #2
0
        private static void AddManualWorkbookByUrl(string in_manualUrl, Google2uData in_instance)
        {
            WorkbookBase info;

            if (string.IsNullOrEmpty(in_manualUrl))
            {
                Debug.LogError(LocalizationInfo.Localize(Localization.rowIds.ID_ERROR_EMPTY_URL));
                return;
            }

            var refreshManualWorkbookCache = false;

            try
            {
                var key =
                    in_manualUrl.Substring(in_manualUrl.IndexOf("key=", StringComparison.InvariantCultureIgnoreCase) + 4);
                key = key.Split('&')[0];

                var singleQuery = new WorksheetQuery(key, "public", "values");

                if (in_instance.ManualService == null && !SetupManualService(in_instance))
                {
                    return;
                }

                var feed = in_instance.ManualService.Query(singleQuery);

                var finalUrl = in_manualUrl.Split('&')[0];

                if (feed != null)
                {
                    info =
                        in_instance.ManualWorkbooks.Find(in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) ??
                        in_instance.AccountWorkbooks.Find(in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl))
                        as WorkbookBase;
                    if (info == null)
                    {
                        var newWorkbook = new Google2uManualWorkbook(feed, finalUrl, feed.Title.Text,
                                                                     in_instance.ManualService);
                        in_instance.ManualWorkbooks.Add(newWorkbook);

                        refreshManualWorkbookCache = true;
                    }
                }
            }
            catch
            {
                try
                {
                    var key =
                        in_manualUrl.Substring(
                            in_manualUrl.IndexOf("spreadsheets/d/", StringComparison.InvariantCultureIgnoreCase) + 15);
                    key = key.Split('/')[0];

                    if (in_instance.ManualService == null && !SetupManualService(in_instance))
                    {
                        return;
                    }

                    var singleQuery = new WorksheetQuery(key, "public", "values");
                    var feed        = in_instance.ManualService.Query(singleQuery);
                    var urlParts    = in_manualUrl.Split('/');

                    var    finalUrl = "";
                    var    urlBuild = 0;
                    string urlPart;
                    do
                    {
                        urlPart   = urlParts[urlBuild];
                        finalUrl += urlPart + '/';
                        urlBuild++;
                    } while (urlPart != key);
                    if (feed != null)
                    {
                        info =
                            in_instance.ManualWorkbooks.Find(
                                in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) ??
                            in_instance.AccountWorkbooks.Find(
                                in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) as WorkbookBase;
                        if (info == null)
                        {
                            var newWorkbook = new Google2uManualWorkbook(feed, finalUrl, feed.Title.Text,
                                                                         in_instance.ManualService);
                            in_instance.ManualWorkbooks.Add(newWorkbook);

                            refreshManualWorkbookCache = true;
                        }
                    }
                }
                catch
                {
                    Debug.LogError(LocalizationInfo.Localize(Localization.rowIds.ID_ERROR_INVALID_URL));
                }
            }

            if (refreshManualWorkbookCache)
            {
                in_instance.ManualWorkbookCache = string.Empty;
                foreach (var Google2uSpreadsheet in in_instance.ManualWorkbooks)
                {
                    in_instance.ManualWorkbookCache += Google2uSpreadsheet.WorkbookUrl + "|";
                }
            }
        }