void Start()
    {
        string       dataAsJson = File.ReadAllText("Assets/Data/2015US.json");
        AllDocuments info       = JsonUtility.FromJson <AllDocuments>(dataAsJson);

        foreach (Document doc in info.docs)
        {
            Debug.Log(doc.ST);
        }
    }
예제 #2
0
        public ActionResult IndexDocumentActivity(int id)
        {
            var          userlist        = db.Users.ToList();
            AllDocuments allDoc          = new AllDocuments();
            var          documents       = db.Documents.Where(c => c.ActivityId == id).ToList();
            var          currentActivity = db.Activities.Find(id);
            var          TeacherRoleId   = db.Roles.FirstOrDefault(m => m.Name == "Teacher").Id;
            var          StudentRoleId   = db.Roles.FirstOrDefault(m => m.Name == "Student").Id;
            var          ActivityTypeId  = db.ActivityTypes.FirstOrDefault(m => m.Description == "Assignment").Id;
            //if (currentActivity.TypeId == ActivityTypeId)
            //{
            //var d = User.Identity.GetUserId();
            var studentDokumentsForActivity = currentActivity.Documents.Where(w => w.User.Roles.Select(q => q.RoleId).Contains(StudentRoleId)).ToList();
            var TeacherDokumentsForActivity = currentActivity.Documents.Where(w => w.User.Roles.Select(q => q.RoleId).Contains(TeacherRoleId)).ToList();

            allDoc.UL         = userlist;
            allDoc.StudentDoc = studentDokumentsForActivity;
            allDoc.TeacherDoc = TeacherDokumentsForActivity;
            List <AllDocuments> ALLDOCUMENT = new List <AllDocuments>();

            ALLDOCUMENT.Add(allDoc);
            if (Request.IsAjaxRequest())
            {
                return(PartialView(ALLDOCUMENT));
            }

            return(View(ALLDOCUMENT));
            //}
            //else if (User.IsInRole("Teacher") && currentActivity.TypeId == ActivityTypeId)
            //{
            //	var d = User.Identity.GetUserId();
            //	var studentDokumentsForActivity = db.Documents.Where(c => c.ActivityId == id).ToList();
            //	var TeacherDokumentsForActivity = currentActivity.Documents.Where(w => w.User.Roles.Select(q => q.RoleId).Contains(TeacherRoleId)).ToList();


            //	allDoc.StudentDoc = studentDokumentsForActivity;
            //	allDoc.TeacherDoc = TeacherDokumentsForActivity;
            //	return View(allDoc);
            //}

            //else
            //{
            //	allDoc.STUDENTTEACHERDoc = documents;
            //	return View(documents);
            //}
        }
예제 #3
0
        public async Task <List <Tuple <string, double> > > AnalyzeTextAsync(List <string> wordTokensList)
        {
            var analysisInfoList = new List <Tuple <string, double> >();

            await Task.Run(() =>
            {
                var analyzeTaskArray = wordTokensList.Select(async(string wordTokenString) =>
                {
                    var document = new Document()
                    {
                        Language = "en",
                        Id       = "1",
                        Text     = wordTokenString
                    };

                    var allDocs = new AllDocuments()
                    {
                        Documents = new List <Document>()
                        {
                            document
                        }
                    };

                    var bodyString          = JsonConvert.SerializeObject(allDocs);
                    var textAnalyticsProxy  = new CMPTextAnalyticsProxy(KAnalyticsRegionString, KAnalyticsKeyString);
                    var sentimentModelsList = await textAnalyticsProxy.AnalyzeSentimentAsync(bodyString);
                    if ((sentimentModelsList == null) || (sentimentModelsList.Count == 0))
                    {
                        return;
                    }

                    var sentimentModel = sentimentModelsList[0];
                    var score          = Double.Parse(sentimentModel.ScoreString);
                    analysisInfoList.Add(new Tuple <string, double>(wordTokenString, score));
                }).ToArray();

                Task.WaitAll(analyzeTaskArray);
            });

            return(analysisInfoList);
        }
예제 #4
0
        public ActionResult StudentAssignmentSolutions(int id)
        {
            var          userlist                    = db.Users.ToList();
            AllDocuments allDoc                      = new AllDocuments();
            var          documents                   = db.Documents.Where(c => c.ActivityId == id).ToList();
            var          currentActivity             = db.Activities.Find(id);
            var          StudentRoleId               = db.Roles.FirstOrDefault(m => m.Name == "Student").Id;
            var          ActivityTypeId              = db.ActivityTypes.FirstOrDefault(m => m.Description == "Assignment").Id;
            var          studentDokumentsForActivity = currentActivity.Documents.Where(w => w.User.Roles.Select(q => q.RoleId).Contains(StudentRoleId)).ToList();

            allDoc.UL         = userlist;
            allDoc.StudentDoc = studentDokumentsForActivity;
            List <AllDocuments> ALLDOCUMENT = new List <AllDocuments>();

            ALLDOCUMENT.Add(allDoc);
            if (Request.IsAjaxRequest())
            {
                return(PartialView(ALLDOCUMENT));
            }
            return(View(ALLDOCUMENT));
        }
예제 #5
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Fetches/updates all DocumentEntries in a Dictionary and wraps them in a Noc class.
        /// </summary>
        /// <returns>Dictionary of ResourceId's and Noc objects.</returns>
        public static void UpdateAllEntries()
        {
            if (AllDocuments == null)
            {
                AllDocuments = new Dictionary <string, Document>();
            }

            if (AllFolders == null)
            {
                AllFolders = new Dictionary <string, Document>();
            }

            // let's first make sure the user is authenticated
            if (_settings == null)
            {
                throw new Exception("User hasn't been authenticated - internet down?");
            }

            try
            {
                var request = new DocumentsRequest(_settings)
                {
                    Service = { ProtocolMajor = 3 }
                    //BaseUri = DocumentsListQuery.documentsAclUri
                };
                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.Proxy = GetProxy();

                // we'll fetch all entries
                AllEntriesFeed = request.GetEverything();

                // if we've already retrieved items, let's clear the dictionaries before updating them
                if (AllDocuments.Count > 0)
                {
                    AllDocuments.Clear();
                }
                if (AllFolders.Count > 0)
                {
                    AllFolders.Clear();
                }

                foreach (var entry in AllEntriesFeed.Entries)
                {
                    // let's only add documents and folders
                    if (entry.Type == Document.DocumentType.Document)
                    {
                        AllDocuments.Add(entry.ResourceId, entry);
                    }
                    else if (entry.Type == Document.DocumentType.Folder)
                    {
                        AllFolders.Add(entry.ResourceId, entry);
                    }
                }
            }
            catch (GDataNotModifiedException)
            {
                // since doclist updates timestamps on feeds based on access,
                // etags are useless here and we shouldn't get here
                return;
            }
            catch (GDataRequestException exRequest)
            {
                var error = GetErrorMessage(exRequest);
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't fetch all entries - internet down?");
                }

                Trace.WriteLine(string.Format("\n{0} - NocsService: couldn't fetch all entries: {1}\n", DateTime.Now, error));
                throw new GDataRequestException(Tools.TrimErrorMessage(error));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                Trace.WriteLine(string.Format("\n{0} - NocsService: couldn't fetch all entries: {1}\n", DateTime.Now, error));
                throw new Exception(error);
            }
        }
예제 #6
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Deletes an entry with a given id.
        /// </summary>
        /// <param name="entryId">ResourceId of the entry to be deleted.</param>
        /// <param name="entryType">Type of the entry (Document or Folder).</param>
        public static void DeleteEntry(string entryId, Document.DocumentType entryType)
        {
            Working = true;

            // we will only rename documents and folders
            if (entryType != Document.DocumentType.Document && entryType != Document.DocumentType.Folder)
            {
                throw new ArgumentException(string.Format("Invalid entryType ({0})", entryType));
            }

            var doc           = entryType == Document.DocumentType.Document ? AllDocuments[entryId] : AllFolders[entryId];
            var entryToDelete = doc.DocumentEntry;

            try
            {
                _documentService.ProtocolMajor = 3;
                entryToDelete.Delete();
            }
            catch (GDataRequestException exRequest)
            {
                var response = exRequest.Response as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.PreconditionFailed &&
                    exRequest.ResponseString.ToLowerInvariant().Contains("etagsmismatch"))
                {
                    // ETags don't match -> this document has been updated outside this instance of Nocs
                    // or it was just saved -> let's update it and try renaming again
                    Debug.WriteLine(string.Format("ETags don't match, couldn't find {0} - updating it and trying delete again..", doc.ETag));
                    doc = GetUpdatedDocument(doc);
                    DeleteEntry(doc.ResourceId, doc.Type);
                }
                else
                {
                    var error = GetErrorMessage(exRequest);
                    if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                    {
                        throw new GDataRequestException("Couldn't delete entry, connection timed out");
                    }

                    var knownIssues = ConsecutiveKnownIssuesOccurred(DeleteEntryLock, "DeleteEntry", doc, error, ref _deleteEntryAttempts, 1);
                    if (knownIssues == KnownIssuesResult.Retry)
                    {
                        doc = GetUpdatedDocument(doc);
                        DeleteEntry(doc.ResourceId, doc.Type);
                        doc.Summary          = null;
                        _deleteEntryAttempts = 0;
                        return;
                    }
                    else if (knownIssues == KnownIssuesResult.LimitReached)
                    {
                        return;
                    }

                    Trace.WriteLine(string.Format("Couldn't delete {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                    throw new GDataRequestException(string.Format("Couldn't delete {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                }
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                throw new Exception(string.Format("Couldn't delete entry: {0} - {1}", doc.DocumentEntry.Title.Text, error));
            }
            finally
            {
                Working = false;
            }

            // let's update the appropriate dictionary
            if (entryType == Document.DocumentType.Document)
            {
                AllDocuments.Remove(entryId);
            }
            else
            {
                AllFolders.Remove(entryId);
            }
        }
예제 #7
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Creates a new document in Google Docs.
        /// </summary>
        /// <param name="folderId">An entry id for any given folder in which the new document is to be saved.</param>
        /// <param name="title">Title for the new document.</param>
        /// <param name="content">HTML content for the new document.</param>
        /// <param name="createDefaultDirectory">
        /// true = create a default directory ('Nocs')
        /// fales = don't create a default directory
        /// </param>
        /// <returns>A newly created Document.</returns>
        public static Document CreateNewDocument(string folderId, string title, string content, bool createDefaultDirectory)
        {
            DocumentEntry newEntry;
            Document      newDocument;

            content = Tools.FormatEditorContentToHtml(title, content);

            try
            {
                var request    = new DocumentsRequest(_settings);
                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.Proxy = GetProxy();

                // we'll first create a default 'Nocs'-folder if one isn't already created
                if (createDefaultDirectory)
                {
                    var defaultFolder = new Document
                    {
                        Type  = Document.DocumentType.Folder,
                        Title = "Nocs"
                    };
                    defaultFolder = request.CreateDocument(defaultFolder);

                    // if we created our default directory, let's add it to our folder dictionary
                    if (defaultFolder != null)
                    {
                        AllFolders.Add(defaultFolder.ResourceId, defaultFolder);
                        folderId = defaultFolder.ResourceId;
                    }
                }

                SetupService(null, null, 3, null, null);
                var textStream = new MemoryStream(Encoding.UTF8.GetBytes(content));

                // we might be creating this document inside a particular folder
                var postUri = !string.IsNullOrEmpty(folderId) ?
                              new Uri(string.Format(DocumentsListQuery.foldersUriTemplate, folderId))
                              : new Uri(DocumentsListQuery.documentsBaseUri);

                newEntry = _documentService.Insert(postUri, textStream, DocumentContentType, title) as DocumentEntry;
            }
            catch (GDataRequestException exRequest)
            {
                var error = !string.IsNullOrEmpty(exRequest.ResponseString) ? exRequest.ResponseString : exRequest.Message;
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't create document - internet down?");
                }


                // we'll also check for InvalidEntryException: Could not convert document
                // - assuming it's a known problem in GData API related to sharing, we will just ignore it
                if (error.ToLowerInvariant().Contains("could not convert document"))
                {
                    Debug.WriteLine(string.Format("Couldn't convert document while creating a document: {0}", title));
                    return(null);
                }

                Trace.WriteLine(string.Format("{0} - Couldn't create a new document: {1} - {2}", DateTime.Now, title, error));
                throw new GDataRequestException(string.Format("Couldn't create a new document: {0} - {1}", title, Tools.TrimErrorMessage(error)));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                Trace.WriteLine(DateTime.Now + " - NocsService - couldn't create a new document: " + error);
                throw new Exception(string.Format("Couldn't create document: {0} - {1}", title, error));
            }

            // let's create a new Document
            if (newEntry != null)
            {
                newEntry.IsDraft = false;

                newDocument = new Document
                {
                    AtomEntry = newEntry,
                    Title     = title,
                    Content   = Tools.ParseContent(content)
                };

                // let's add the new document to our document dictionary and return it
                AllDocuments.Add(newDocument.ResourceId, newDocument);
                return(newDocument);
            }

            // we should never get here
            throw new Exception((string.Format("Couldn't create document: {0} - internet down?", title)));
        }